Tuesday, December 30, 2014

Protocol controlled robot

Control a robot using various Wireless Protocols
Everyone, from a basic level kid to brainy scientists, will not create robots without controlling it by wires. This make a sense and practice of wired controlled robots. Hooking up with wires, snipping it, soldering it again and again makes the process tedious and the root looks like a crap.
So, controlling a robot without touching it has been a great challenge. Then advancements in technology and science brought out various ways of controlling a robot using various communication protocols. Hmmmm…………!
clip_image002What does a protocol mean?
Ø A protocol is a set of communication languages between two
Electronic components. The common language which the components Can exchanges information and data between them. Ex. A digital device cannot communicate to analog device without the use of A to D converter between them. Here the A to D converter act as a translator between the devices.
Common wireless protocols for robots:
Ø Radio frequency modules
· Bluetooth
· 433 Mhz Transmitter and receiver
· 2.4 Ghz Transmitter and recevier
· Zigbee radio
· Wi-fi
Ø GSM
Ø Infra-red waves
As there are many protocols available for communication, these are the reliable and the easily configurable wireless modules for robotics.

 Let’s make a Bluetooth controlled robot:
Time Duration:
Expert’s: 30 minutes
Starter’s: 60 minutes
 

Overview of Bluetooth:
Ø Bluetooth is a wireless protocol utilizing short-range communications technology facilitating data transmission over short distances. Bluetooth uses frequency hopping in timeslots. Bluetooth has been designed to operate in noisy radio frequency environments, and uses a fast acknowledgement and a frequency-hopping scheme to make the communications link robust, communication-wise. Bluetooth radio modules avoid interference from other signals by hopping to a new frequency after transmitting or receiving a packet. The Bluetooth radio is built into a small microchip and operates in a globally available frequency band ensuring communication compatibility worldwide.
Ø The Bluetooth specification has two power levels defined;
· a lower power level that covers the shorter personal area within a room, and
· clip_image004a higher power level that can cover a medium range, such as within a home.
A simple Bluetooth communication:
clip_image006
ü The one which transfers becomes the master and the one which receives becomes the slave.
Pin connections in Bluetooth module HC-05/HC-06:
Vcc, Gnd, Tx, Rx
clip_image008
Ø The pin orders may vary according to model and manufacturer.
Let’s have fun with Bluetooth>
Checking the Bluetooth >>
Steps:
Ø Power the Bluetooth module using the Arduino Uno by connecting the pins below. The Arduino Uno should be powered via the data cable or with the help of external battery. You can also use FTDI converter to power the Bluetooth module by connecting it to the computer.
clip_image010
Ø Once the Bluetooth module is powered, the LED on the Bluetooth starts blinking until it gets paired to other device.
Ø Turn ON the Bluetooth of your mobile and search for he Bluetooth named HC-05 or HC-06 depending upon the model.
Ø Then connect the Bluetooth device and it asks for the pairing code. Enter the pairing code as ‘1234’ [ Just type 1234 ]
Ø clip_image012Then add the device to your mobile. And the LED in the Bluetooth stops blinking.
Yeah! Our Bluetooth module is working fine>
v As there are many ways to check the working of Bluetooth, this will be appropriate enough to proceed with the Bluetooth controlled robots.
 
Now let’s make the Bluetooth controlled robot>
There are two ways by which you can control the robot
>Using a terminal program in PC
> By using a Mobile phone app (Android)
Both the ways are easier to control and which has the same building configuration of the robot.
Things you will need:
Ø Arduino Uno
Ø Breadboard
Ø Bluetooth module HC-05/HC-06
Ø L293D Motor driver IC
Ø Single strand wires
Ø 12V battery and 9V battery
Ø Chassis
Ø Dummy axles
Ø 2 set of wheels
Ø A pair of 500rpm DC motors
Ø Android based smart phone and PC
Follow the steps:
 clip_image014clip_image016
> Assemble the chassis with the dummy axles and DC motors and attach the wheels to it firmly.
clip_image020
 
clip_image018
 
 
 
 
 
 
 
 



> Place the breadboard and Arduino board on the chassis and fix it using double side tapes.
clip_image022
Ø Pin the Bluetooth module into the breadboard and wire the pin connections of the Bluetooth to the Arduino board for making up the wireless connection.
Ø Now place the L293D IC on the breadboard and connect the pins of the IC as said in the previous project. [Scroll above to see the connections again]
Ø Follow the pin connections below for your reference.
Ø Make sure that the Arduino board do not make any electrical contact with the chassis, in case the chassis is made up of metal.
Ø Now the frame work of the robot is ready and let’s program the Arduino.
 
Pin connections:

clip_image024Fix the L293D IC on the breadboard and wire all the pins of the IC accordingly as shown in the pin configuration below:
· motor1 Pin1 = 3 on Arduino // pin 2 on L293D IC
· motor1 Pin2 = 4 on Arduino // pin 7 on L293D IC
· enable1 Pin = 5 on Arduino // pin 1 on L293D IC
· motor2 Pin1 = 8 on Arduino // pin 10 on L293D IC
· motor2 Pin2 = 9 on Arduino // pin 15 on L293D IC
· enable2 Pin = 10 on Arduino // pin 9 on L293D IC
· The out 1,2 and 3,4 is connected to motor pins.
clip_image025Fix the Bluetooth on the breadboard and make the connection below:
Ø VCC pin of Bluetooth to 5V pin of Arduino Uno
Ø Gnd pin of Bluetooth to Gnd pin of Arduino Uno
Ø Tx pin of Bluetooth to Rx pin of Arduino Uno
Ø Rx pin of Bluetooth to Tx pin of Arduino Uno
clip_image027clip_image028

clip_image030
Let’s program the Arduino>
Ø The codes and algorithm is same as previous robot. The functions for moving the robot forward, backward, left and right are set and it is executed only when a command is given. This command is sent serially as output by the user via the Bluetooth in PC/Mobile and Arduino reads the serial input via the receiving Bluetooth. As per the command, specific function is enabled until the next command is received by the Arduino.
clip_image031
Hmmm….. What is serial communication mean?
 



Let’s learn some stuff>
Ø The word serial means “one after the other”. Information is passed back and forth between the computer and Arduino by setting the pin HIGH or LOW. Serial interfaces stream their data, one single bit at a time. These interfaces can operate on as little as one wire, usually never more than four.

clip_image033



clip_image035
clip_image037






In case of Bluetooth module, this communication happens in terms of wireless manner by the form of radio waves in air. Then the serial communication happens between the Bluetooth module and Arduino board for data communication.
clip_image038The following code does the function given below:
Robot moves,
Ø Forward – if 1 is pressed in Bluetooth enabled device
Ø Backward - if 5 is pressed in Bluetooth enabled device
Ø Left - if 2 is pressed in Bluetooth enabled device
Ø Right - if 4 is pressed in Bluetooth enabled device
Ø Stop - if 3 is pressed in Bluetooth enabled device


>> You can change the numbers in the program for which the specific function takes place.


int motor1Pin1 = 3; // pin 2 on L293D IC
int motor1Pin2 = 4; // pin 7 on L293D IC
int enable1Pin = 5; // pin 1 on L293D IC
int motor2Pin1 = 8; // pin 10 on L293D IC
int motor2Pin2 = 9; // pin 15 on L293D IC
int enable2Pin = 10; // pin 9 on L293D IC
int state;

void setup() {
    // sets the pins as outputs:
    pinMode(motor1Pin1, OUTPUT);
    pinMode(motor1Pin2, OUTPUT);
   pinMode(enable1Pin, OUTPUT);
    pinMode(motor2Pin1, OUTPUT);
    pinMode(motor2Pin2, OUTPUT);
    pinMode(enable2Pin, OUTPUT);
    // sets enable1Pin and enable2Pin high so that motor can turn on:
    digitalWrite(enable1Pin, HIGH);
    digitalWrite(enable2Pin, HIGH);
    // initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
}

void loop() {
    //if some date is sent, reads it and saves in state
    if(Serial.available() > 0){     
      state = Serial.read();   
    }   
    // if the state is '1' the DC motor will go forward
    if (state == '1') {
        digitalWrite(motor1Pin1, HIGH);
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, HIGH);
        }
    
    
    // if the state is '2' the motor will turn left
    else if (state == '2') {
    
        digitalWrite(motor1Pin1, HIGH); 
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, HIGH);
        digitalWrite(motor2Pin2, LOW);
    }
    // if the state is '3' the motor will Stop
    else if (state == '3' ){
        digitalWrite(motor1Pin1, LOW); 
        digitalWrite(motor1Pin2, LOW); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, LOW);
        }
    // if the state is '4' the motor will turn right
    else if (state == '4') {
        digitalWrite(motor1Pin1, LOW); 
        digitalWrite(motor1Pin2, HIGH); 
        digitalWrite(motor2Pin1, LOW);
        digitalWrite(motor2Pin2, HIGH);
    }
    // if the state is '5' the motor will Reverse
    else if (state == '5') {
        digitalWrite(motor1Pin1, LOW); 
        digitalWrite(motor1Pin2, HIGH);
        digitalWrite(motor2Pin1, HIGH);
        digitalWrite(motor2Pin2, LOW);
    }
}

Yup! Upload the program into the Arduino and the robot is ready to control>
clip_image043
Steps to control the robot>

By using a Terminal program in PC/Laptop
ü In case of using a PC/laptop, make sure you have the Bluetooth connected with it. Most Laptops have in-built Bluetooth with it. But for PC’s, buy a Bluetooth and insert it to the computer.
ü After installing the Bluetooth device, Right click on Bluetooth icon on the right corner of the task bar and click add a device or you can go to control panel and add a device by that way.
ü It will search for the device and it shows HC-O5. [Make sure to turn on the Bluetooth device on the Arduino]
ü Add the passcode as 1234 and the Bluetooth gets paired. This is identified by the LED indication on the Bluetooth device. The LED light’s continuously if it’s get paired to any device.
ü Now then download any terminal software on your PC/Laptop such as Hyper Terminal, Tera Term and install it. Hope it’s free to download and use.
ü Open the Hyper terminal program and choose a name and icon to new connection. Now a window opens for you to choose a port for making connection. Choose the outgoing port number which is allocated for your Bluetooth device. This can be found out by right clicking on the Bluetooth device in PC/Laptop and going to ‘properties’ and clicking ‘Hardware’ tab.
clip_image045clip_image047
clip_image049clip_image051
clip_image052ü After choosing the correct port, the hyper terminal will establish the serial communication with the Bluetooth device connected with Arduino.
ü Once done, the robot is ready to control. Type the number in the hyper terminal workspace to do a specific function in the robot.
clip_image054
By using an Android app:
Ø Instead of using the terminal program in PC/laptop, you can use your android phone to control the robot functions.
Ø Install the app from the link below:
Click here to get the app

Ø After installing it, pair the Bluetooth device HC-05 to your mobile phone using the passcode 1234.
Ø After pairing, open the app, and search for device and connect again. Once connected, you can click the buttons in the app for doing the specific functions of the robot.
Follow the video for the step by step procedure:





clip_image058
clip_image060


                             Yeah! We controlled the robot using the Bluetooth.


No comments:

Post a Comment