Here is an example of a Wi-Fi-based Robotic Rescue and Recon Vehicle. The user can see the front of the vehicle via the network camera connected to the Wi-Fi router on the vehicle, and control the movement of the vehicle from a computer/smartphone application software. The control signals are sent through the Wi-Fi medium which is received by the onboard Wi-Fi router and, communicated to the microcontroller via the Ethernet shield. The microcontroller interprets the control signal and gives the respective signals to the motors to make the vehicle move. The range of controlling the vehicle wirelessly is limited by the range of Wi-Fi signals. However, just by using a 3G-to-Wi-Fi router the effective range of control will be increased throughout the globe where GSM coverage is available.
// Tested on Arduino 1.0.3
int LeftMotorPlus = 2;
int LeftMotorMinus = 4;
int LeftMotorEnable = 3;
int RightMotorPlus = 7;
int RightMotorMinus = 8;
int RightMotorEnable = 5;
//Analog pins
int VehicleBat_analogInput = 4;
int CameraBat_analogInput = 3;
float VehicleBat_vout = 0.0;
float VehicleBat_vin = 0.0;
float CameraBat_vout = 0.0;
float CameraBat_vin = 0.0;
float R1 = 20000.0; // !! resistance of R1 !!
float R2 = 10000.0; // !! resistance of R2 !!
// variable to store the value
int VehicleBat_analogInput_value = 0;
int CameraBat_analogInput_value = 0;
#include // needed for Arduino versions later than 0018
#include
#include // UDP library from: This email address is being protected from spambots. You need JavaScript enabled to view it. 12/30/2008
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE };
byte ip[] = { 192, 168, 1, 177 };
const unsigned int localPort = 8890; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char replyBuffer[] = "ok"; // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup()
{
Serial.begin(9600);
pinMode(VehicleBat_analogInput, INPUT);
pinMode(CameraBat_analogInput, INPUT);
// start the Ethernet and UDP:
Ethernet.begin(mac, ip);
Udp.begin(localPort);
pinMode(LeftMotorPlus, OUTPUT);
pinMode(LeftMotorMinus, OUTPUT);
pinMode(LeftMotorEnable, OUTPUT);
pinMode(RightMotorEnable, OUTPUT);
pinMode(RightMotorMinus , OUTPUT);
pinMode(RightMotorPlus , OUTPUT);
Serial.begin(9600);
}
void move_backward() {
Serial.println("Moving Backword");
digitalWrite(LeftMotorPlus, HIGH);
digitalWrite(LeftMotorMinus, LOW);
digitalWrite(LeftMotorEnable, HIGH);
digitalWrite(RightMotorPlus, LOW);
digitalWrite(RightMotorMinus, HIGH);
digitalWrite(RightMotorEnable, HIGH);
}
void move_forward() {
Serial.println("Moving Forward");
digitalWrite(LeftMotorPlus, LOW);
digitalWrite(LeftMotorMinus, HIGH);
digitalWrite(LeftMotorEnable, HIGH);
digitalWrite(RightMotorPlus, HIGH);
digitalWrite(RightMotorMinus, LOW);
digitalWrite(RightMotorEnable, HIGH);
}
void turn_left() {
Serial.println("Turning Left");
digitalWrite(LeftMotorPlus, HIGH);
digitalWrite(LeftMotorMinus, LOW);
digitalWrite(LeftMotorEnable, HIGH);
digitalWrite(RightMotorPlus, HIGH);
digitalWrite(RightMotorMinus, LOW);
digitalWrite(RightMotorEnable, HIGH);
}
void turn_right() {
Serial.println("Turning Right");
digitalWrite(LeftMotorPlus, LOW);
digitalWrite(LeftMotorMinus, HIGH);
digitalWrite(LeftMotorEnable, HIGH);
digitalWrite(RightMotorPlus, LOW);
digitalWrite(RightMotorMinus, HIGH);
digitalWrite(RightMotorEnable, HIGH);
}
void stop_right_there() {
Serial.println("Stopped");
digitalWrite(LeftMotorPlus, LOW);
digitalWrite(LeftMotorMinus, LOW);
digitalWrite(LeftMotorEnable, LOW);
digitalWrite(RightMotorPlus, LOW);
digitalWrite(RightMotorMinus, LOW);
digitalWrite(RightMotorEnable, LOW);
}
void loop()
{
//delay(10);
// if there's data available, read a packet
int readPacketSize = Udp.parsePacket(); // note that this includes the UDP header
if (readPacketSize <= 0)
return;
readPacketSize = readPacketSize - 8; // subtract the 8 byte header
Serial.print("Received packet of size ");
Serial.println(readPacketSize);
memset(packetBuffer, 0, sizeof(packetBuffer));
// read the packet into packetBufffer and get the senders IP addr and port number
Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
Serial.println("Contents:");
Serial.println(packetBuffer);
bool update_cmd = false;
if ( strcmp(packetBuffer, "forward1") == 0)
{
move_forward();
Serial.println("Receiving forward command");
} else if ( strcmp(packetBuffer, "backward1") == 0)
{
move_backward();
Serial.println("Receiving backward command");
} else if ( strcmp(packetBuffer, "left1") == 0)
{
turn_left();
Serial.println("Receiving left command");
} else if ( strcmp(packetBuffer, "right1") == 0)
{
turn_right();
Serial.println("Receiving right command");
} else ///////////////////////////////////////////
if ( strcmp(packetBuffer, "forward0") == 0)
{
stop_right_there();
Serial.println("forward command received");
} else if ( strcmp(packetBuffer, "backward0") == 0)
{
stop_right_there();
Serial.println("backward command received");
} else if ( strcmp(packetBuffer, "left0") == 0)
{
stop_right_there();
Serial.println("left command received");
} else if ( strcmp(packetBuffer, "right0") == 0)
{
stop_right_there();
Serial.println("right command received");
} else if ( strcmp(packetBuffer, "update") == 0)
{
update_cmd = true;
// read the value on analog input
VehicleBat_analogInput_value = analogRead(VehicleBat_analogInput);
delay(5);
VehicleBat_analogInput_value = analogRead(VehicleBat_analogInput);
Serial.print(" VehicleBat_analogInput_value ");
Serial.println(VehicleBat_analogInput_value);
VehicleBat_vout = (VehicleBat_analogInput_value * 5.0) / 1024.0;
Serial.print(" VehicleBat_vout ");
Serial.println(VehicleBat_vout);
VehicleBat_vin = VehicleBat_vout / (R2 / (R1 + R2));
Serial.print(" VehicleBat_vin ");
Serial.println(VehicleBat_vin);
for (int i = 0; i < 5; i++) {
Serial.println("Analog read");
Serial.print(i);
Serial.print(" ");
pinMode(i, INPUT);
Serial.print(analogRead(i));
}
int VehicleBat_vin_int = VehicleBat_vin * 1000;
// read the value on analog input
CameraBat_analogInput_value = analogRead(CameraBat_analogInput);
delay(5);
CameraBat_analogInput_value = analogRead(CameraBat_analogInput);
CameraBat_vout = (CameraBat_analogInput_value * 5.0) / 1024.0;
CameraBat_vin = CameraBat_vout / (R2 / (R1 + R2));
Serial.println(" CameraBat_vin ");
Serial.print(CameraBat_vin);
int CameraBat_vin_int = CameraBat_vin * 1000;
// vin = analogRead(voltage_pin) * resistorFactor;
char str_voltage[32];
sprintf(str_voltage, "vlt Car Bat %d Cam Bat %d", VehicleBat_vin_int, CameraBat_vin_int);
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(str_voltage);
Udp.endPacket();
Serial.println("update command received");
}
if (update_cmd == false)
{
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(replyBuffer);
int sentPacketSize = Udp.endPacket();
// if we failed to sent ok, we turn off all pins
if (sentPacketSize == 0)
{
stop_right_there();
}
}
}