Gesture_Controlled_Robotic_Car

Joel A. - BlueStamp Engineering Project Portfolio


Project maintained by jabraham777 Hosted on GitHub Pages — Theme by mattgraham

Gesture Controlled Robotic Car

I have been working to make a gesture controlled car. After hours of concentrated effort, I was able to create a robotic car that can move according to the movement of one’s hand. I loved where the two worlds of physical engineering and software met to create a versatile and unique rover.

This project has furthered my passion in the field as I have now gained a new understanding and appreciation of circuitry, motors, and coding. My biggest challenges were understanding the concepts of energy transfer, breadboarding, and soldering, but once I mastered the skills, creating a functional product was far easier.

Engineer School Area of Interest Grade
Joel A. Monroe Township High School, NJ Mechanical/Software Engineering Incoming Junior

Profile Pic

First Milestone

For my first milestone, I ensured that all my parts were working and came away with a working piece of hardware:

Second Milestone

For my second milestone, I was able to come away with two paired Bluetooth modules and a configured controller:

Code for Bluetooth connections

Here is the code I used to establish my Bluetooth connections

//Code for Arduino Micro Bluetooth Connection
void setup() {
  Serial.begin(38400);
  Serial1.begin(38400);
}

void loop() 
{
  if (Serial1.available())
  {
    Serial.print((char)Serial1.read());
  }
  if (Serial.available())
  {
    Serial1.write(Serial.read());
  }
}
//Code for Arduino Uno Bluetooth Connection
#include <SoftwareSerial.h>

#define tx 3
#define rx 2

SoftwareSerial configBt(rx, tx);
long tm, t, d;

void setup() {
  //Put my setup code here, to run once:
  Serial.begin(38400);
  configBt.begin(38400); // Corrected object name to configBt
  pinMode(tx, OUTPUT);
  pinMode(rx, INPUT);
}

void loop() {
  if (configBt.available()) {
    Serial.print((char)configBt.read());
  }
  if (Serial.available()) {
    configBt.write(Serial.read());
  }
}

Final Milestone

For my final milestone, I was able to code and produce a fully functional product:

Code

Here is the code for my car (Arduino Uno).

//Code for the car
// This is to receive data from the other Bluetooth module and read the gestures
// The robot should move accordingly! 

#include <SoftwareSerial.h>

#define tx 2
#define rx 3

SoftwareSerial configBt(rx, tx);

//character variable for command
char c = "";

//start at 50% duty cycle
//int s = 120;

//change based on motor pins
int in1 = 5;
int in2 = 6;
int in3 = 9;
int in4 = 10;

void setup()
{
  //opens serial monitor and Bluetooth serial monitor
  Serial.begin(38400);
  configBt.begin(38400);
  pinMode(tx, OUTPUT);
  pinMode(rx, INPUT);

  //initializes all motor pins as outputs
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
}

void loop()
{
  //checks for Bluetooth data
  if (configBt.available()){
    //if available stores to command character
    c = (char)configBt.read();
    //prints to serial
    Serial.println(c);
  }

  //acts based on character
  switch(c){
    
    //forward case
    case 'F':
      forward();
      break;
      
    //left case
    case 'L':
      left();
      break;
      
    //right case
    case 'R':
      right();
      break;
      
    //back case
    case 'B':
      back();
      break;
      
    //default is to stop robot
    case 'S':
      freeze();
    }
}

//moves robot forward 
void forward(){
  
    //chages directions of motors
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    digitalWrite(in3, HIGH);
    digitalWrite(in4, LOW);

  }

//moves robot left
void left(){

    //changes directions of motors
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);

  }

//moves robot right
void right(){

    //changes directions of motors
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    digitalWrite(in3, HIGH);
    digitalWrite(in4, LOW);

  }

//moves robot backwards
void back(){

    //changes directions of motors
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    digitalWrite(in3, LOW);
    digitalWrite(in4, HIGH);

  }

//stops robot
void freeze(){

    //changes directions of motors
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
    digitalWrite(in3, LOW);
    digitalWrite(in4, LOW);

  }

And here is the code for the controller (Arduino Micro).

#include <Wire.h>

#define MPU6050_ADDRESS 0x68

int16_t accelerometerX, accelerometerY, accelerometerZ;

void setup()
{
  Wire.begin();
  Serial1.begin(38400);

  // Initialize MPU6050
  Wire.beginTransmission(MPU6050_ADDRESS);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU6050)
  Wire.endTransmission(true);

  delay(100); // Delay to allow MPU6050 to stabilize
}

void loop()
{
  readAccelerometerData();
  determineGesture();
  delay(500);
}

void readAccelerometerData()
{
  Wire.beginTransmission(MPU6050_ADDRESS);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU6050_ADDRESS, 6, true);  // request a total of 6 registers

  // read accelerometer data
  accelerometerX = Wire.read() << 8 | Wire.read();
  accelerometerY = Wire.read() << 8 | Wire.read();
  accelerometerZ = Wire.read() << 8 | Wire.read();
}

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');
  }
}

Schematics

Below are the replicable schematics of my car and controller:

Above you can see the attachments between the battery pack, motors, motor driver, and Arduino Uno. Power is provided to the motor driver through a battery pack placed on the car. The motors are connected to each other through jumper wires, which will allow for a minimal amount of wires to be attached to the terminals of the motor driver. Rather than having 2 wires in each terminal, energy can be efficiently transferred from the motor driver, through one motor, and into the second motor on each side of the car. Furthermore, the motor driver is connected to the Arduino Uno which is then linked to the Bluetooth module with the mediation of a breadboard.

Above you can see the connections between the Arduino Micro, Bluetooth module, battery pack, and accelerometer. All the parts are powered by an external battery pack and are compactly put together on a mini breadboard. The accelerometer gets its values based on the tilt of the controller and then sends them to the Arduino Micro. The Micro then electrically sends the values to the Bluetooth module that can send the values to the car in order to move in the specified direction.

Bill of Materials

Part Note Price Link
Smart Car Kit The chasies and motors of the car $18.99 Amazon
2 Bluetooth Modules Used for communicating between the Arduino uno and micro $20.78 Amazon
Arduino Uno Controlls the car $27.60 Arduino
Arduino Micro Controlls the handpiece $25.50 Amazon
Motor Driver Controlls the motors $6.99 Amazon
Breadboards Circuts that mediate energy transfers $11.99 Amazon
Soldering Kit Melting metal to prevent energy leakage $16.99 Amazon
Velcro To fasten parts to the car $9.99 Amazon
Dupont/ Jumper Wires Electrically connects all parts $6.98, 8.56 Amazon , Amazon
Batteries Power source $9.70 Amazon
Battery Holder Power source carrier $6.99 Amazon

#

Referenced Sources