How to build a Robot on an Arduino that can be controlled remotely online:
by J.B. Wylzan/* ===============================================================
Project Homotronics: Robot controlled by Ethernet
Author: J. B. Wylzan with some help from the Arduino community
Website: http://www.ihackrobot.blogspot.com
Abstract: Control a robot via the ethernet.
================================================================== */
#include <SPI.h>
#include <Ethernet.h>
const int MLWF = 4;
const int MLBB = 7;
const int MRYF = 6;
const int MRRB = 5;
byte mac[] = { your mac address };
byte ip[] = { your ip address };
byte gateway[] = { 192, 168, x, x };
byte subnet[] = { 255, 255, x, x };
EthernetServer server(80); //or 8081
String gString;
void setup() {
Serial.begin(9600);
pinMode(MLWF, OUTPUT);
pinMode(MLBB, OUTPUT);
pinMode(MRYF, OUTPUT);
pinMode(MRRB, OUTPUT);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.print("my server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
EthernetClient client = server.available();
if (client == true) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (gString.length() < 100) {
gString = gString + c;
}
if (c == '\n') {
Serial.println(gString);
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>iHackLab</TITLE>");
client.println("</HEAD>");
client.println("<BODY bgcolor='#ff4d4d'>");
client.println("<center>");
client.println("<H1>iHackLab Homotronics Website</H1>");
client.println("<hr />");
client.println("<br />");
client.println("<H2>Robotics with Arduino Ethernet Shield</H2>");
client.println("<br />");
client.println("<a href=\"/fwd\"\">Move Forward</a>");
client.println("<br />");
client.println("<br />");
client.println("<a href=\"/rvs\"\">Move Backward</a><br />");
client.println("<br />");
client.println("<br />");
client.println("<a href=\"/rht\"\">Turn Right</a>");
client.println("<br />");
client.println("<br />");
client.println("<a href=\"/lft\"\">Turn Left</a><br />");
client.println("<br />");
client.println("<br />");
client.println("<br />");
client.println("<a href=\"/stp\"\">Stop</a><br />");
client.println("<br />");
client.println("<br />");
client.println("<br />");
client.println("<hr />");
client.println("<www.thearduinosketch.blogspot.com>");
client.println("<hr />");
client.println("<br />");
client.println("</center>");
client.println("</BODY>");
client.println("</HTML>");
delay(1); //page loading delay
client.stop();
Serial.println("client disconnected");
if (gString.indexOf("fwd") >0){
Serial.println("Forward");
digitalWrite(MLBB, 0);
digitalWrite(MLWF, 255);
digitalWrite(MRRB, LOW);
digitalWrite(MRYF, HIGH);
}
if (gString.indexOf("rvs") >0){
Serial.println("Reverse");
digitalWrite(MLBB, 255);
digitalWrite(MLWF, 0);
digitalWrite(MRRB, HIGH);
digitalWrite(MRYF, LOW);
}
if (gString.indexOf("lft") >0){
Serial.println("Left");
digitalWrite(MLBB, 0);
digitalWrite(MLWF, 255);
digitalWrite(MRRB, LOW);
digitalWrite(MRYF, LOW);
}
if (gString.indexOf("rht") >0){
Serial.println("Right");
digitalWrite(MLBB, 0);
digitalWrite(MLWF, 0);
digitalWrite(MRRB, LOW);
digitalWrite(MRYF, HIGH);
}
if (gString.indexOf("stp") >0){
Serial.println("Stop");
digitalWrite(MLBB, 0);
digitalWrite(MLWF, 0);
digitalWrite(MRRB, LOW);
digitalWrite(MRYF, LOW);
}
gString="";
}
}
}
}
/* ================================================================== */
Circuit: (optional)
* Ethernet shield prepares to be attached to pins 10, 11, 12, 13
* Analog inputs attached to pins A0 through A5
* On-board SS micro-SD card slot must be on pin 4
* On-board SS micro-SD card slot must be on pin 4
- PWR: indicates that the board and shield are powered
- LINK: indicates the presence of a network link and flashes when the shield transmits or receives data
- FULLD: indicates that the network connection is full duplex
- 100M: indicates the presence of a 100 Mb/s network connection (as opposed to 10 Mb/s)
- RX: flashes when the shield receives data
- TX: flashes when the shield sends data
- COLL: flashes when network collisions are detected.
Disclaimer: We shall not be liable for any loss or damage of whatever nature - direct, indirect, consequential, or otherwise - which may arise as a result of your use of any information on this website. However, if you are interested in using any of the projects for personal or educational purposes, please inform the author by email.
Public Domain Notice: Copyright (c) 2000. All rights reserved. This article is part of a book entitled iHackRobot. Copies are welcome to be shared or distributed publicly as long proper citations are observed. Please cite as follows: Biotronics: The Silver Species, Joey Lawsin, 1988, USA.
==================================================================
Patent Pending. 2000 © ®
A L.A.W.S.I.N. Educational Production
No comments:
Post a Comment