In this tutorial, we will learn how to make a Gesture Control Robot Car. Using Two HC 05 Bluetooth Modules And Arduino. This is also an Arduino project that will impress others. This robot car is controlled by the accelerometer control transmitter. The transmitter consists of an MPU6050 sensor, an Arduino board, and a Bluetooth module configured as the master. This can control a distance between fifteen and twenty meters.
You can watch the following video or read the written tutorial below.
Overview
The connection between the Gesture Control Robot Car and the transmitter is through Bluetooth. The two HC-05 Bluetooth modules I use are configured as master and slave. The important sensor used by the transmitter is the MPU6050. It consists of a 3-axis Gyroscope and a 3-axis Accelerometer. All parts of the transmitter are assembled by me on a 2-cell 18650 battery holder. The slave Bluetooth module was used for the robot car and the master Bluetooth module was used for the transmitter.
When the transmitter moves, the car moves accordingly. It becomes more clear by watching the first part of the video above.
Components Needed
The purchase links are in the description of my YouTube video.
- Arduino UNO Board
- Arduino NANO Board
- MPU6050 sensor module
- 4-wheel chassis kit with DC motors
- L298N motor driver module
- Two HC-05 Bluetooth Modules. ( configured as master and slave.)
- Four 18650 Li-ion Rechargeable Battery 3.7V
- Two cell 18650 Li-ion battery holder, two required
- Toggle Switch
- Jumper wires
Assemble the 4 Wheel Smart Car Chassis kit
How to assemble the 4 Wheel Smart Car Chassis kit is explained in the post I have presented before. This can be assembled very easily. The link of that article is mentioned below.
Link – How To Assemble 4WD Robot Smart Car Chassis Kits
Circuit Diagram
The circuit diagram of this project is actually quite simple. As depicted in the circuit diagram, the procedure for connecting the module wires is further explained below. The circuit diagram of the transmitter and the motor are in the same figure. You can download this circuit diagram. For that, click on the download button below and download it.
Assembly of parts of the car
Attach the Arduino board, L298N motor drive, and battery holder with a glue gun or screws as shown in the image below. You can change this as needed. I have soldered the switch to the battery holder. Connect the switch as shown in the circuit diagram.
Connecting the four-gear motors to the l298N Motor Driver.
If you assembled the 4 Wheel Smart Car Chassis kit in the same way I did, connect the motor wires to the motor drive as mentioned below. If not, the direction of motor operation may change in some cases. It can be fixed by changing the motor connection wires of the motor drive. The two gear motors on the right are connected to OUT3 and OUT4 of the L298N Motor Driver. The two gear motors on the left are connected to OUT2 and OUT1 of the L298N Motor Driver.
In this way, connect the wires of the gear motors to the motor power connectors of the l298N motor driver.
- Connect the two right motor Red wires to the “OUT3” terminals on the L298N motor driver.
- Connect the two right motor Black wires to the “OUT4” terminals on the motor driver.
- Connect the two left motor Black wires to the “OUT1” terminals on the motor driver.
- Connect the two left motor Red wires to the “OUT2” terminals on the motor driver.
Connect the L298N Motor Drive to the Arduino UNO
In this way, connect the digital pins of the Arduino board and the inputs of the L298N motor driver by jumper wires.
- Connect the IN1 pin of the motor driver to digital pin D5 on the Arduino.
- Connect the IN2 pin of the motor driver to digital pin D6 on the Arduino.
- Connect the IN3 pin of the motor driver to digital pin D3 on the Arduino.
- Connect the IN4 pin of the motor driver to digital pin D9 on the Arduino.
Battery Power Connection of Car
Use two 3.7V 18659 li-ion batteries to provide power. Do not use more than two batteries. It cannot use 9V battery. If a 9V battery is used, only the ultrasonic sensor and servo motor will work. Gear motor not working. The reason for that is that the 9V battery does not have enough amperage.
First solder the switch to the battery holder. Solder the red wire of the battery holder to one end of the switch and solder a red wire to the other end of the switch. Stick the switch to the battery holder with the glue gun.
- Connect the Red wire (+) of the battery holder to the 12V In of the L298N Motor Driver and to the VIN Pin of the Arduino board.
- Connect the Black wire (-) of the battery holder to the GND In of the L298N Motor Driver and to the GND Pin of the Arduino board.
Connecting the Slave Bluetooth module to the receiver car.
The Gesture Control Robot Car uses two HC-05 Bluetooth modules. Those two Bluetooth modules should be configured as master and slave by AT Command. Details about that are available in this article.
Link – How to Configure HC-05 Bluetooth Module As Master and Slave Via AT Command
The receiver car uses the slave Bluetooth module.
In this way, connect the Arduino board and the Slave Bluetooth module by jumper wires.
- Connect the VCC (power) pin of the Bluetooth module to the 5V pin on the Arduino.
- Connect the GND (ground) pin of the Bluetooth module to the GND pin on the Arduino.
- Connect the TXD pin of the Bluetooth module to digital pin D10 on the Arduino.
- Connect the RXD pin of the Bluetooth module to digital pin D11 on the Arduino.
Assembling parts of the transmitter.
I assemble the parts of the transmitter, on the 18650 battery holder. Arduino NANO, MPU6050 and Master Bluetooth Module are installed by glue gun. You can also assemble this on hand gloves. The master Bluetooth module is used for this.
Connecting the Master Bluetooth module to the Arduino NANO board.
Connect the Master Bluetooth module with a female jumper wire and solder the wires to the Arduino Nano board. Connect the wires as shown below. This does not need to be soldered. Can also be connected using jumper wires. Because soldering is easy for me, I do.
In this way, connect the Arduino nano board and the Master Bluetooth module by jumper wires.
- Connect the VCC (power) pin of the Bluetooth module to the 5V pin on the Arduino.
- Connect the GND (ground) pin of the Bluetooth module to the GND pin on the Arduino.
- Connect the TXD pin of the Bluetooth module to digital pin D10 on the Arduino.
- Connect the RXD pin of the Bluetooth module to digital pin D11 on the Arduino.
Connect the MPU6050 Sensor to the Arduino NANO board.
To integrate the MPU6050 sensor with the Arduino NANO board in the Gesture Control Robot Car project, connect the specified pins using jumper wires or soldering for a secure connection. If opting for soldering, connect the VCC of the MPU6050 sensor to the 5V pin on the Arduino, ensuring a stable power supply. Establish a common ground by connecting the GND of the sensor to the GND on the Arduino. Facilitate I2C communication by connecting the SDA pin to pin A4 and the SCL pin to pin A5 on the Arduino. Finally, connect the INT pin of the MPU6050 sensor to pin D2 on the Arduino. This meticulous wiring configuration ensures a reliable and accurate communication link between the accelerometer-equipped MPU6050 sensor and the Arduino NANO, enabling the accurate interpretation of gestures for controlling the robot car.
Connect the battery wire to the transmitter
Connect the red wire of the battery holder to Arduino VCC pin and the black wire to GND. Connect the black wire(-) of the battery holder to the GND of the Arduino Nano. Connect the Red wire(+) of the battery holder to the VIN of the Arduino Nano.
Upload Arduino code to receiver car and transmitter.
First, upload the transmitter code
First, upload the transmitter code If you copy and paste the above code into the Arduino IDE, you will need to add three libraries. You can go to this link and download the zip file containing the code and libraries. Connect the Arduino Nano board in the transmitter to the computer. Select board and port and upload the code. Before uploading the code to Arduino NANO board select its processor as old bootloader. The bootloader selected via Tools > Processor > ATmega328P (Old Bootloader) is the “ATmegaBOOT” bootloader. If this is difficult to do, watch a tutorial video.
Transmitter Code
// www.robotlk.com
//Robot LK YouTube channel
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#include "Wire.h"
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // CONNECT BT RX PIN TO ARDUINO 11 PIN | CONNECT BT TX PIN TO ARDUINO 10 PIN
#define OUTPUT_READABLE_YAWPITCHROLL
#define INTERRUPT_PIN 2
#define LED_PIN 13
MPU6050 mpu;
bool blinkState = false;
bool dmpReady = false;
uint8_t mpuIntStatus;
uint8_t devStatus;
uint16_t packetSize;
uint16_t fifoCount;
uint8_t fifoBuffer[64];
// orientation/motion vars
Quaternion q;
VectorFloat gravity;
float ypr[3];
float pitch = 0;
float roll = 0;
float yaw = 0;
int x;
int y;
volatile bool mpuInterrupt = false;
void dmpDataReady() {
mpuInterrupt = true;
}
void setup() {
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
Wire.setClock(400000);
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
Serial.begin(38400);
BTSerial.begin(9600);
while (!Serial);
Serial.println(F("Initializing I2C devices..."));
mpu.initialize();
pinMode(INTERRUPT_PIN, INPUT);
Serial.println(F("Testing device connections..."));
Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
Serial.println(F("Initializing DMP..."));
devStatus = mpu.dmpInitialize();
mpu.setXGyroOffset(126);
mpu.setYGyroOffset(57);
mpu.setZGyroOffset(-69);
mpu.setZAccelOffset(1869);
if (devStatus == 0) {
Serial.println(F("Enabling DMP..."));
mpu.setDMPEnabled(true);
Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING);
mpuIntStatus = mpu.getIntStatus();
Serial.println(F("DMP ready! Waiting for first interrupt..."));
dmpReady = true;
packetSize = mpu.dmpGetFIFOPacketSize();
} else {
Serial.print(F("DMP Initialization failed (code "));
Serial.print(devStatus);
Serial.println(F(")"));
}
pinMode(LED_PIN, OUTPUT);
}
void loop() {
if (!dmpReady) return;
while (!mpuInterrupt && fifoCount < packetSize) {
}
mpuInterrupt = false;
mpuIntStatus = mpu.getIntStatus();
fifoCount = mpu.getFIFOCount();
if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
mpu.resetFIFO();
Serial.println(F("FIFO overflow!"));
} else if (mpuIntStatus & 0x02) {
while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
mpu.getFIFOBytes(fifoBuffer, packetSize);
fifoCount -= packetSize;
#ifdef OUTPUT_READABLE_YAWPITCHROLL
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
yaw = ypr[0] * 180 / M_PI;
pitch = ypr[1] * 180 / M_PI;
roll = ypr[2] * 180 / M_PI;
if (roll > -100 && roll < 100)
x = map (roll, -100, 100, 0, 100);
if (pitch > -100 && pitch < 100)
y = map (pitch, -100, 100, 100, 200);
Serial.print(x);
Serial.print("\t");
Serial.println(y);
if((x>=45 && x<=55) && (y>=145 && y <=155)){
BTSerial.write('S');
}else if(x>60){
BTSerial.write('R');
}else if(x<40){
BTSerial.write('L');
}else if(y>160){
BTSerial.write('B');
}else if(y<140){
BTSerial.write('F');
}
#endif
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}
}
Code language: PHP (php)
Transmitter Code
To verify the proper functionality of the uploaded transmitter code in the Gesture Control Robot Car project, connect the transmitter to the computer and open the serial monitor in the Arduino IDE. Ensure the baud rate is set to 38400. When the transmitter is manipulated, observe changes in the values displayed on the serial monitor. If the values respond to the movement as expected, it indicates that the transmitter is functioning correctly. If encountering difficulties with this verification process, it is recommended to watch a tutorial video for a step-by-step guide, assisting in confirming the proper operation of the transmitter and ensuring a successful integration with the overall robot car system.
Second, upload the receiver code
Connect the Arduino Uno board in the receiver car to the compute Copy the following Arduino code and paste it into a new sketch in the Arduino IDE. Select the board and port, and upload the code. If you find this difficult, you can watch a tutorial video. The receiver code of the Gesture Control Robot Car.
The receiver code of the Gesture Control Robot Car
You can download the Arduino code and open it directly through the Arduino IDE. Click the Download button below to download the Arduino code
//Robot lk
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // CONNECT BT RX PIN TO ARDUINO 11 PIN | CONNECT BT TX PIN TO ARDUINO 10 PIN
char tiltDirection;
int motorInput1 = 5;
int motorInput2 = 6;
int motorInput3 = 3;
int motorInput4 = 9;
void setup() {
pinMode(motorInput1, OUTPUT);
pinMode(motorInput2, OUTPUT);
pinMode(motorInput3, OUTPUT);
pinMode(motorInput4, OUTPUT);
digitalWrite(motorInput1, LOW);
digitalWrite(motorInput2, LOW);
digitalWrite(motorInput3, LOW);
digitalWrite(motorInput4, LOW);
Serial.begin(38400); // Serial communication is activated at 38400 baud/s.
BTSerial.begin(9600); // HC-05 default speed in AT command more
}
//Robot lk
void loop() {
if (BTSerial.available()) {
tiltDirection = BTSerial.read();
if(tiltDirection == 'F'){
Serial.println("Forward");
reverse();
}else if(tiltDirection == 'B'){
Serial.println("Reverse");
forward();
}else if(tiltDirection == 'R'){
Serial.println("Right");
left();
}else if(tiltDirection == 'L'){
Serial.println("Left");
right();
}else if(tiltDirection == 'S'){
Serial.println("Stop");
stopCar();
}
}
}
//Robot lk
void forward()
{
digitalWrite(motorInput1, LOW);
digitalWrite(motorInput2, HIGH);
digitalWrite(motorInput3, LOW);
digitalWrite(motorInput4, HIGH);
}
void reverse()
{
digitalWrite(motorInput1, HIGH);
digitalWrite(motorInput2, LOW);
digitalWrite(motorInput3, HIGH);
digitalWrite(motorInput4, LOW);
}
void right()
{
digitalWrite(motorInput1, LOW);
analogWrite(motorInput2, 150);
analogWrite(motorInput3, 150);
digitalWrite(motorInput4, LOW);
}
void left()
{
analogWrite(motorInput1, 150);
digitalWrite(motorInput2, LOW);
digitalWrite(motorInput3, LOW);
analogWrite(motorInput4, 150);
}
void stopCar() {
digitalWrite(motorInput1, LOW);
digitalWrite(motorInput2, LOW);
digitalWrite(motorInput3, LOW);
digitalWrite(motorInput4, LOW);
}
Code language: PHP (php)
To verify the successful implementation of the receiver code in the Gesture Control Robot Car project, connect the receiver car to the computer and open the serial monitor in the Arduino IDE, setting the baud rate to 38400. Upon inserting batteries into the transmitter, it activates, and after a few seconds, the two Bluetooth modules establish a connection. Subsequently, when the transmitter is manipulated, observe changes in the values displayed on the serial monitor. If the values respond appropriately to the movement, it indicates that both the transmitter and receiver car are functioning correctly. In case of any difficulties during this verification process, it is recommended to watch a tutorial video for detailed guidance, ensuring the successful operation of the entire robot car system with gesture control.
Control Your Gesture Control Robot Car
Upon turning on both the receiver and transmitter, the two Bluetooth modules establish a binding connection after a brief initialization period. Once successfully bound, the Gesture Control Robot Car can be intuitively maneuvered based on the orientation of the transmitter. Tilting the transmitter forward prompts the car to move forward, while leveling the transmitter parallel to the ground halts its movement. Tilt the transmitter to the left, and the car responds by moving left; similarly, tilting it to the right induces a rightward motion. If the transmitter is tilted backward, the car moves in reverse. This gesture-controlled mechanism offers a straightforward and responsive method for users to control the robot car’s movements, providing an interactive and engaging experience with the implemented accelerometer-based control system.
Conclusion
In conclusion, the Gesture Control Robot Car project presents an innovative and interactive application of Arduino-based robotics, combining accelerometer technology and Bluetooth communication for intuitive control. Through meticulous assembly and connection of components such as the Arduino boards, MPU6050 sensor, L298N motor driver, and Bluetooth modules, users can create a functional robot car capable of responding to gestures transmitted by the accelerometer-equipped transmitter. The step-by-step instructions for assembly, circuit connection, and code uploading ensure accessibility for users with varying levels of expertise. The incorporation of gesture-based control adds an engaging element to the project, allowing the robot car to move forward, backward, left, and right in response to the user’s hand movements. Overall, this Gesture Control Robot Car project serves as an educational and entertaining exploration of Arduino robotics and sensor integration, fostering hands-on learning experiences for enthusiasts and learners alike.