0

$USD

$USD
TUTORIALS Robotics

Arduino Based Spy Robot

DFRobot Jul 30 2015 641
In this project you will see how simple mixture of different technologies and third-party apps allows to create a rather complex toy.
 
DFRobot
DFRobot
DFRobot


The robot does two things:

1. Arduino based spy robot moves according to commands delivered from Android RemoteControl app via bluetooth. 

2. The robot transmits video via wifi throught a third party directly to RemoteControl Android app, which is very convenient since you manage the robot and see what is going on in one single Android app

But the key advantage is how simple it is to create such a spy robot.

 

Step 1: Platform and Wiring

DFRobotDFRobot

The project iinludes:

1. Standard Turtle platform (with build-in battery module)
2. HC-06 Bluetooth module
3. Arduino Mega ADK (but any other Arduino is fine)
4. Motor shield to manage motors up to 2A
5. Android phone (on the second photo) which should be mounted in front of the robot. It serves as a camera
6. Android phone/tablet which will be used as a remote control using self-developed RemoteControl app

The project involves two flows of data: commands which manage the robot come from an Android app via bluetooth connection, which is established using HC-06, while video comes through a wifi connection

The project uses third-party IP Webcam app, which is installed on the phone. The video is tranferred to a RemoteControll app which is developed by myself using App Inventor. The RemoteControll app is installed on another Android device like phone or tablet. The RemoteControl app both receives video stream and send commands via bluetooth
 

Step 2: Arduino Code

#define CON_MOTOR1 0
#define CON_MOTOR2 0 

// Motor shield uses four pins - 4, 5, 6, 7 to manage the motors

// 4 and 7 — for direction, 5 and 6 — for speed 

#define SPEED_1 5 
#define DIR_1 4 
#define SPEED_2 6 
#define DIR_2 7 

// Shortcuts for possible robot movements

#define FORWARD 0 
#define BACKWARD 1 
#define LEFT 2 
#define RIGHT 3

// Variable for bluetooth buffer

int RX_buff; 

/* * This function is used to manage actual movements */ 

void go (int newDirection, int speed) {


boolean motorDirection_1, motorDirection_2; 
switch ( newDirection ) { 
case FORWARD: motorDirection_1 = true; motorDirection_2 = true; break; 
case BACKWARD: motorDirection_1 = false; motorDirection_2 = false; break; 
case LEFT: motorDirection_1 = true; motorDirection_2 = false; break; 
case RIGHT: motorDirection_1 = false; motorDirection_2 = true; break; 
} 

// In case of motor set-up mistakes just change the numbers

motorDirection_1 = CON_MOTOR1 ^ motorDirection_1; 
motorDirection_2 = CON_MOTOR2 ^ motorDirection_2; 

// Let's move!

analogWrite(SPEED_1, speed); 
analogWrite(SPEED_2, speed); 
digitalWrite(DIR_1, motorDirection_1); 
digitalWrite(DIR_2, motorDirection_2); 
} 

void setup() { 

Serial.begin(9600); 

// Sets pins 4, 5, 6, 7 to output mode

for(int i = 4; i <8; i++)
pinMode(i, OUTPUT);

delay(5000); 

} 

void loop() { 

// Reading bluetooth data

RX_buff = Serial.read(); 

// Responding to bluetooth data

if (RX_buff == 1) { 


go(FORWARD, 125); 
delay(1000); 
} 

if (RX_buff == 2){ 
go(LEFT, 80); 

delay(1500); 
} 

if (RX_buff == 4){ 
go(BACKWARD, 70); 

delay(1500); 
} 

if (RX_buff == 3){ 

go(RIGHT, 80); 
delay(1500); 
} 

// Stop,if necessary

if (RX_buff == 5 || RX_buff == 0){ 
analogWrite(SPEED_1, 0); 
analogWrite(SPEED_2, 0); 
} 

}

Step 3: Remote Control App - App Inventor Scheme


DFRobot
DFRobot

1. The principal element is BluetkothClient.Send1ByteNumber, which sends integer numbers to Arduino via bluetooth. When received by Arduino, those integer numbers are converted to motor commands.

2.The interface of the RemoteControl app is very simple - just four buttons for the relevant FORWARD, LEFT, RIGHT and BACK movements as well as STOP button.

3. The RemoteControl app also uses WebViewer component, which is used as recepient of the wifi video stream from the Android phone mounted on the robot. Again, the video is streamed by a thied party app (IP Webcam), which is installed on the Android phone. The advantage of IP Webcam is that it sreatms video directly to a web browser, which in RemoteControl app is replaced by WebViewer component. So, the video is streamed directly to your robot management app!