SMARTPHONE CONTROLLED ROBOT USING BLE 4.0 !!!
by Harsh Dethe in Circuits > Robots
3489 Views, 5 Favorites, 0 Comments
SMARTPHONE CONTROLLED ROBOT USING BLE 4.0 !!!
In previous instructable I shared with you how you can use Bluetooth Module (Specifically HM10 BLE v4.0) with Arduino to control LEDs using smartphone. You can check it out here. In this instructable I will show you how to build a robot that can be controlled using smartphone via Bluetooth Low Energy. I Will try to keep it as simple as possible.
Things You Will Need :-
So here I have provided name and details of all the components you will need along with the best buy links.
1. Electronic Components :-
- Arduino UNO :- I have used UNO but you can use any other board like Mega if you want to give the robot extra features and require a lot of I/O pins or smaller Nano if you want a tiny compact bot. If you are a beginner I advice you to get the UNO cause it is more versatile and user friendly.
Link for US
Link for Europe
- Arduino Motor Shield :- I have used L293D motor shield which is cheap and efficient for this project, But if you want you can opt. for a better version Motor shield L298N which is capable of handling Larger motors.
Link for US
Link for Europe
- Bluetooth Module :- Here I used AT-09 module which is HM-10 compatible. You can go for HM-10 if you like. Even though this tutorial is basically for Bluetooth 4.0v, you can use HC-05 module too if you have that laying around.
Link for US
Link for Europe
- Geared DC Motors :- The ones I used are cheap and will get the job done. but if you really want to go professional you can buy high torque motors from here.
Link for US
Link for Europe
- Batteries :- 2 batteries will be needed for this project a 9v-12v battery for the motor driver and a 9v battery for the Arduino. Or else you can use a power bank to power it through USB
Link for US
Link for Europe - 2.2k ohm & 1k ohm resistors each.
Link for US
Link for Europe
2. Software Requirements :-
- Arduino IDE :- For writing and uploading code to the arduino board.
- BLE Joystick apk :- Use BLE joystick apk if you are using HM10/AT-09 modules. If you are using HC-05/06 modules use Bluetooth Controller App.
3. Hardware Requirements :-
Now hardware requirements differs on many aspects, Like if you want a 2 wheeled robot or a 4 wheeled one. Or maybe you want one with tracks like a Tank. So here I have provided links to few robot chassis which you can buy, or you can make one with objects you have laying around like cardboard / acrylic sheets.
I will use some parts laying around to make the body of the robot. Details in the next step.
Making the Chassis :-
Here I have used a 5mm thick Sunboard for the base , drilled holes for the motor brackets and Arduino on the top. and assembled everything as shown in the pictures. I have made similar design in a previous Instructable you can check it out here it has more details about the design :- Simple & Smart Robot Using Arduino.
Instead of making one yourself you can also buy one which will be easier. Links I have already shared in the previous step.
This post is more about controlling the robot using BLE so lets get into it.
Making Connections :-
First You have to connect the Bluetooth module to arduino like shown in the picture above.
- Tx => Rx of Arduino (Pin 0)
- Rx => Tx of Arduino (Pin 1)
- GND => GND
- Vcc => +5v
Check out the previous intractable for more details.
I soldered two resistors together.
Then I placed their terminal in arduino pins. One terminal of the 2.2k ohm resistor goes to GND and one terminal of 1k ohm resistor goes to Tx (pin 1 of arduino). The point where the two resistors are connected goes to the Rx pin of Bluetooth module.
After that I placed the motor shield on top. If you want you can solder the wires directly to the shield but I was too lazy to solder so I went the easy way... ;p
Connect the motors to M1 and M2 of the Motor Shield
Uploading Code :-
To make the robot work we have to upload a code to the Arduino. Refer the Following code , I have kept it simple and clean for beginners, If you are an experienced coder you can add more things to it like additional sensors, Lights etc.
I suggest you write the code instead of coping it so that you get a better understanding of it.
#include<AFMotor.h> AF_DCMotor motorR(1); AF_DCMotor motorL(2); char data = 0; void setup() { Serial.begin(9600); Serial.println("Motor test !"); motorR.setSpeed(200); motorL.setSpeed(200); } void forward() { Serial.println("Going Forward..."); delay(500); motorR.run(FORWARD); motorL.run(FORWARD); } void backward() { Serial.println("Going Backward..."); delay(500); motorR.run(BACKWARD); motorL.run(BACKWARD); } void left() { Serial.println("Turning Left..."); delay(500); motorR.run(FORWARD); motorL.run(RELEASE); } void right() { Serial.println("Turning Right..."); delay(500); motorR.run(RELEASE); motorL.run(FORWARD); } void hold() { Serial.println("Stop..."); delay(500); motorR.run(RELEASE); motorL.run(RELEASE); } void spinRight() { Serial.println("Spining Right..."); delay(500); motorR.run(BACKWARD); motorL.run(FORWARD); } void spinLeft() { Serial.println("Spining Left..."); delay(500); motorR.run(FORWARD); motorL.run(BACKWARD); } void loop() { if(Serial.available() > 0) { data = Serial.read(); Serial.println(data); if(data == 'a') { forward(); } else if(data == 'c') { backward(); } else if(data == 'b') { right(); } else if(data == 'd') { left(); } else if(data == 'g') { hold(); } } }
Before you upload the code, Make sure that you disconnect the Tx and Rx wires of Arduino if not the code wont upload and the IDE will throw an error. Once the code is uploaded you can connect the Tx & Rx to module again and you are good to go.
Code file is provided below.
Downloads
Testing !!!!
Power up the robot using batteries , I have used two separate batteries one for powering the arduino and another to power the motor shield. Make sure before you connect the batteries remove the jumper from the shield because if you don't it may damage the arduino board.
Once the robot is powered up you will see the light on Bluetooth module blinking, Now open the BLEJoystick app. Click on the top right corner (Bluetooth Symbol), you will see a list of bluetooth addresses (For some reason it shows the same address multiple time ) Select the first one as that is the only one that works.
When you select the bluetooth address you will notice that the blinking LED on module stops blinking and is solid on, That indicates connection is established now you can start using the controller to control the robot.
That is it for this instructable, If you have any questions or face any difficulty , feel free to ask in the comments.
Thank you.