Gesture Controlled Robot
The Gesture Controlled Robot is a Bluetooth-powered project consisting of two separate components: the car itself and the controller. The controller isn’t your typical joystick, as it uses your hand gestures to move the car accordingly with the use of an accelerometer. The project consists of lots of wiring and coding which caused many setbacks in my project but I was still able to persevere and complete the project.
Engineer | School | Area of Interest | Grade |
---|---|---|---|
Tristan F | Dublin High School | Electrical Engineering | Incoming Senior |
Final Milestone
In my final milestone, I added my modification which was an ultra-sonic sensor that can detect how close it is to an object while moving forward and will stop once the object is a close distance away from it. Not much was added to my project during this time other than the modification but I did run into problems with the ultra-sonic sensor since I wasn’t sure how to get the correct code for it to start working. Overall, this was a fun part of my project since I was able to add something that was once an idea to my physical project and it was great seeing it work.
Second Milestone
In my second milestone, I completed the baseline project of the gesture-controlled robot which involved building the controller, setting up and connecting the Bluetooth devices, and using the code that would run the final product. Throughout this week, I ran into many problems with the wiring which caused me to have many setbacks in my project where I had to reevaluate my project. Every time I thought I had fixed an error in my wiring a new one would appear which made the project very challenging during this milestone. Though it was a challenge, I got through it and was able to create my finished baseline product which was worth it in the end. I also began the start of my project modification that will be completed by my final milestone.
First Milestone
I set up the code and build of the car during my first week and completed it which was my first milestone. By the end of the week, I had my car moving forward, backward, left, and right. How I set up my project was by using videos and online resources that showed me how to get my Arduino plugged into my H-bridges which are what control the motors. I experienced a lot of trial and error with my coding in making the correct outputs/wheels move in the proper direction when needed. Overall, I learned a lot during this project and was able to use my experience with breadboarding to solve a problem that involved getting the 5V port to more than one H-bridge by putting the 2 wires in the same row with a 5V wire.
Schematics
Car Schematic (Uno)
Controller Schematic (Micro)
Code
Arduino Uno
#include <SoftwareSerial.h>
#define tx 2
#define rx 3
SoftwareSerial configBt(rx, tx);
char c ="";
//renaming each digital pin to the H-bridge port its plugged into
const int A_1B = 5;
const int A_1A = 6;
const int B_1B = 9;
const int B_1A = 10;
const int A_1B2 = 7;
const int A_1A2 = 8;
const int B_1B2 = 11;
const int B_1A2 = 12;
const int trigPin = 4;
const int echoPin = 13;
void setup() {
Serial.begin(38400);
configBt.begin(38400);
pinMode (tx, OUTPUT);
pinMode (rx, INPUT);
Serial.begin(9600);
pinMode (trigPin, OUTPUT);
pinMode (echoPin, INPUT);
//making digital pins outputs
pinMode(A_1B, OUTPUT);
pinMode(A_1A, OUTPUT);
pinMode(B_1B, OUTPUT);
pinMode(B_1A, OUTPUT);
pinMode(A_1B2, OUTPUT);
pinMode(A_1A2, OUTPUT);
pinMode(B_1B2, OUTPUT);
pinMode(B_1A2, OUTPUT);
}
void loop() {
if (configBt.available()){
c = (char)configBt.read();
Serial.println(c);
}
switch(c){
case 'F':
forward();
break;
case 'L':
left();
break;
case 'R':
right();
break;
case 'B':
backward();
break;
case 'S':
freeze();
}
long duration, distance;
// Send a pulse from the ultrasonic sensor
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Calculate distance based on the time taken for the echo
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 29.1;
// Display the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
if (distance < 20) { // If an object is within 20 cm
freeze();
} else {
switch(c);
}
delay(100);
}
void forward(){
digitalWrite(A_1B, HIGH);
digitalWrite(A_1A, LOW);
digitalWrite(B_1B, LOW);
digitalWrite(B_1A, HIGH);
digitalWrite(A_1B2, HIGH);
digitalWrite(A_1A2, LOW);
digitalWrite(B_1B2, LOW);
digitalWrite(B_1A2, HIGH);
}
//moves robot backwards
void backward() {
digitalWrite(A_1B, LOW);
digitalWrite(A_1A, HIGH);
digitalWrite(B_1B, HIGH);
digitalWrite(B_1A, LOW);
digitalWrite(A_1B2, LOW);
digitalWrite(A_1A2, HIGH);
digitalWrite(B_1B2, HIGH);
digitalWrite(B_1A2, LOW);
}
//turns robot right
void right() {
digitalWrite(A_1B, HIGH);
digitalWrite(A_1A, LOW);
digitalWrite(B_1B, HIGH);
digitalWrite(B_1A, LOW);
digitalWrite(A_1B2, HIGH);
digitalWrite(A_1A2, LOW);
digitalWrite(B_1B2, HIGH);
digitalWrite(B_1A2, LOW);
}
//turns robot left
void left() {
digitalWrite(A_1B, LOW);
digitalWrite(A_1A, HIGH);
digitalWrite(B_1B, LOW);
digitalWrite(B_1A, HIGH);
digitalWrite(A_1B2, LOW);
digitalWrite(A_1A2, HIGH);
digitalWrite(B_1B2, LOW);
digitalWrite(B_1A2, HIGH);
}
//stops robot
void freeze() {
digitalWrite(A_1B, LOW);
digitalWrite(A_1A, LOW);
digitalWrite(B_1B, LOW);
digitalWrite(B_1A, LOW);
digitalWrite(A_1B2, LOW);
digitalWrite(A_1A2, LOW);
digitalWrite(B_1B2, LOW);
digitalWrite(B_1A2, LOW);
}
Arduino Micro
#include <Wire.h>
#define MPU6050_ADDRESS 0x68
int16_t accelerometerX, accelerometerY, accelerometerZ;
void setup() {
Wire.begin();
Serial1.begin(38400);
Wire.beginTransmission(MPU6050_ADDRESS);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
delay(100);
}
void loop() {
readAccelerometerData();
determineGesture();
delay(500);
}
void readAccelerometerData()
{
Wire.beginTransmission(MPU6050_ADDRESS);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU6050_ADDRESS, 6, true);
accelerometerX = Wire.read() <<8 | Wire.read();
accelerometerY = Wire.read() <<8 | Wire.read();
accelerometerZ = Wire.read() <<8 | Wire.read();
Serial.print(accelerometerX);
Serial.print(accelerometerY);
}
void determineGesture()
{
if (accelerometerY >= 6500) {
Serial1.write('F');
}
else if (accelerometerY <= -4000) {
Serial1.write('B');
}
else if (accelerometerX <= -3250) {
Serial1.write ('L');
}
else if (accelerometerX >= 3250) {
Serial1.write('R');
}
else{
Serial1.write('S');
}
}
Bill of Materials
Part | Note | Price | Link |
---|---|---|---|
Car Chassis | Base of Car | $21.29 | Link |
Screw Driver Kit | Screw driver | $6.99 | Link |
H Bridges | Motor/Arduino Connecter | $5.99 | Link |
Arduino Uno Clone | Arduino used for the car | $16.99 | Link |
Motors | DC motors that connect to H-Bridges and move the wheels | $10.99 | Link |
Electronics Kit | Mainly used for the wires | $14.99 | Link |
Breadboard Kit | Breadboards | $8.79 | Link |
Arduino Micro | Arduino used for controller | $21.50 | Link |
Micro USB Cable | Arduino Micro connector into computer | $5.19 | Link |
Accelerometer | Tracks movements on the x and y coordinates, used for the controller to track hand gestures | $9.90 | Link |
HC05 x2 | Bluetooth device, 1 for controller and 1 for car | $9.99 | Link |
BreadBoard Power Supply | Barrel Jack for 9V battery & power supplies | $8.00 | Link |
9V Batteries | Battery | $12.36 | Link |
Velcro Tape | Used to attach loose parts | $8.00 | Link |
DMM | Multimeter | $11.00 | Link |