Skip to the content.

Hand Gestured control car

I am making a car that can be moved by how I move my hand!!! Since this car cannot turn to I need to turn one side of the wheels to the opposite of the other side. I use an accelerometer to determine which way my hand is pointing at so it can send information to the

Engineer School Area of Interest Grade
Khang L The Athenian School Robotics Incoming Junior

Headstone Image

Final Milestone

Second Milestone

First Milestone

Schematics

Headstone Image

Code

Here is the code for my hand using gesture control

#include <Wire.h>
const int MPU = 0x68; 
int16_t AcX, AcY, AcZ;

int moveable = 0;

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

 Wire.begin();
 Wire.beginTransmission(MPU);
 Wire.write(0x6B);
 Wire.write(0);
 Wire.endTransmission(true);
 delay(500); 
}

void read_MPU() {
  Wire.beginTransmission(MPU);
  Wire.write(0x3B); 
  Wire.endTransmission(false);
  Wire.requestFrom(MPU, 6, true); 

  AcX = Wire.read() << 8 | Wire.read(); 
  AcY = Wire.read() << 8 | Wire.read(); 
  AcZ = Wire.read() << 8 | Wire.read(); 

  AcX = map(AcX, -17000, 17000, 0, 180);
  AcY = map(AcY, -17000, 17000, 0, 180);
  AcZ = map(AcZ, -17000, 17000, 0, 180);
}

void loop() {
  read_MPU();
  Serial.print(AcX);
  Serial.print(" ");
  Serial.print(AcY);
  Serial.print(" ");
  Serial.print(AcZ);
  Serial.println(" ");
  if (AcX < 60 && moveable == 0) { 
    moveable = 1;
    Serial1.write('f');
    Serial.println("f");
  }
  if (AcX > 130 && moveable == 0) {
    
    Serial1.write('b');
    Serial.println("b");
  }
  if (AcY < 60 && moveable == 0) {
    moveable = 1;
    Serial1.write('l');
    Serial.println("l");
  }
  if (AcY > 130 && moveable == 0) {
    moveable = 1;
    Serial1.write('r');
    Serial.println("r");
  }

  if ((AcX > 70) && (AcX < 120) && (AcY > 70) && (AcY < 120) && (moveable == 1)) {
    moveable = 0;
    Serial1.write('s');
    Serial.println("s");
  }
//  put your main code here, to run repeatedly:
 if (Serial1.available()) {
   Serial.print((char)Serial1.read());
 }
 if (Serial.available())
 {
   Serial1.write(Serial.read());
 }
}

Here is my code for my hand using joysticks

int xL, yR = 0;

int xL_center = 490;
int yR_center = 490;

void setup() { 
 Serial.begin(38400);
 Serial1.begin(38400); 
} 

void read_joystick(){
  xL = analogRead(A0);
  yR = analogRead(A5);
}
void loop(){
  read_joystick();
  if (!((xL_center - 30) < xL && (xL_center + 30) > xL)) {
    if (xL < 468) {
      moveable = 1;
      Serial.println("f");
      Serial1.write('f');
    }
    if (xL > 600) {
      moveable = 1;
      Serial.println("b");
      Serial1.write('b');  
    }
  }

  else if (!((yR_center - 30) < yR && (yR_center + 30) > yR)) {
    if (yR < 456) {
      moveable = 1;
      Serial1.write('r');
      Serial.println("r");
    }
    if (yR > 524) {
      moveable = 1;
      Serial1.write('l');
      Serial.println("l");
    }
  }

  else{
    Serial.println("s");
    Serial1.write('s'); 
  }
}

Here is my code for the car

#include <SoftwareSerial.h>

#define rx 2
#define tx 3

char input_hand;
const int A1A=11;
const int A1B=10;
const int A2A=5;
const int A2B=4;
const int A3A=7;
const int A3B=6;
const int A4A=9;
const int A4B=8;

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

void setup() {
  Serial.begin(38400);
  configBt.begin(38400);
  pinMode(tx, OUTPUT);
  pinMode(rx, INPUT);

  pinMode(A1A, OUTPUT);
  pinMode(A1B, OUTPUT);
  pinMode(A2A, OUTPUT);
  pinMode(A2B, OUTPUT);
  pinMode(A3A, OUTPUT);
  pinMode(A3B, OUTPUT);
  pinMode(A4A, OUTPUT);
  pinMode(A4B, OUTPUT);
}

void forward() {
  digitalWrite(A1A,LOW);
  digitalWrite(A1B,HIGH);
  digitalWrite(A2A,LOW);
  digitalWrite(A2B,HIGH);
  digitalWrite(A3A,LOW);
  digitalWrite(A3B,HIGH);
  digitalWrite(A4A,LOW);
  digitalWrite(A4B,HIGH);
  
}

void backward() {
  digitalWrite(A1A,HIGH);
  digitalWrite(A1B,LOW);
  digitalWrite(A2A,HIGH);
  digitalWrite(A2B,LOW);
  digitalWrite(A3A,HIGH);
  digitalWrite(A3B,LOW);
  digitalWrite(A4A,HIGH);
  digitalWrite(A4B,LOW);
}

void left() {
  digitalWrite(A1A,LOW);
  digitalWrite(A1B,HIGH);
  digitalWrite(A3A,LOW);
  digitalWrite(A3B,HIGH);
  digitalWrite(A2A,HIGH);
  digitalWrite(A2B,LOW);
  digitalWrite(A4A,HIGH);
  digitalWrite(A4B,LOW);
}

void right() {
  digitalWrite(A1A,HIGH);
  digitalWrite(A1B,LOW);
  digitalWrite(A3A,HIGH);
  digitalWrite(A3B,LOW);
  digitalWrite(A2A,LOW);
  digitalWrite(A2B,HIGH);
  digitalWrite(A4A,LOW);
  digitalWrite(A4B,HIGH);
}

void coasting() {
  digitalWrite(A1A,LOW);
  digitalWrite(A1B,LOW);
  digitalWrite(A3A,LOW);
  digitalWrite(A3B,LOW);
  digitalWrite(A2A,LOW);
  digitalWrite(A2B,LOW);
  digitalWrite(A4A,LOW);
  digitalWrite(A4B,LOW);
}

void loop() {
  if(configBt.available()) {
    input_hand = configBt.read();
  }

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

  if (input_hand == 'f') {
    forward();
    Serial.println(input_hand);
  }
  if (input_hand == 'b') {
    backward();
    Serial.print(input_hand);
  }
  if (input_hand == 'l') {
    left();
    Serial.print(input_hand);
  }
  if (input_hand == 'r') {
    right();
    Serial.print(input_hand);
  }
  if (input_hand == 's') {
    coasting();
    Serial.print(input_hand);
  }
}

Bill of Materials

Part Note Price Link
Adruino Uno Logic control for car component 16.99$ Link
Adruino Micro Logic control for hand component 23.00$ Link
MPU-6050 Acceleration measurement for hand component 10.99$ Link
HC-05 Bluetooth module 9.99$ Link
Screwdriver set tool set 7.99$ Link
Solder boards Connecting wires 6.99$ Link
Electronic kits Electronic components 9.99$ Link
Electronic kits Motors for main car 9.99$ Link
9V battery clip battery clip 3.99$ Link
9V battery Powering car and hand 8.99$ Link
Car chasis hold components of the main car 19.99$ Link

Other Resources/Examples