View on GitHub

KameronBlueStamp-Portfolio

This is a template portfolio for the students attending the BlueStamp Engineering program.

Gesture Control Robot

This project uses the gestures of your hand movements to control the direction and speed of the car. Using an accelerometer to read the gestures to Arduino modules by bluetooth. | Engineer | School | Area of Interest | Grade | |:–:|:–:|:–:|:–:| | Kameron N | Courtland Highschool | Electrical Engineering | Incoming Senior

![Headstone Image]IMG_1665

Demo Night

[![Demo Night]

Final Milestone

My final milestone is allowing the bluetooth to read gestures from the accelorometer and have the car be able to move foward and backwards. After getting my car built and wired up to the arduino, H bridge and motors the last thing i needed was for the ADXL345 to communicate the chracters of the gestures to the robot. Once I got the accelormeter, which reads gestures, to connect to my blutooth and allow the arduino micro to read the code. This allowed the car to move based off the gestures of the accelerometer

[![Final Milestone]

First Milestone

My first milestone was configuring the accelerometer to to my arduino uno allowing it to read the acceleration and tilt needed to make my car. After many tries I was able to read my XYZ values on the serial monitor for Arduino IDE. Using ADXL345 and installing its software I used a sensortest to test the values.

[![First Milestone]

Schematics

gesture_schem

Materials

Part Qty Description Cost Site
Robot Kit 1 chassis, battery pack, DC motors, wheels, ect. 19.99 amazon
Arduino Micro 1 microcontroller board 19.44 amazon
Arduino UNO 1 main programming board 25.94 amazon
H-Bridge 1 controls DC motors 5.99 amazon
HC-05 bluetooth module 2 Allows communication between each other 9.99 amazon
Multi colored jumper wires 1 Wires to connect 6.98 amazon
ADXL345 1 Digital accelerometer 2.15 amazon

Tools Required

| Tool | Cost | Site | |:–:|:-:|:-:| | Soldering Kit | 20.99 | amazon | Screwdriver Kit | 6.99 | amazon

Final Code

#include

void setup() { Wire.begin(); Serial.begin(9600); Serial.println(“I2C Scanner”); }

void loop() { byte error, address; int nDevices;

Serial.println(“Scanning…”);

nDevices = 0; for(address = 1; address < 127; address++ ) { Wire.beginTransmission(address); error = Wire.endTransmission();

if (error == 0)
{
  Serial.print("I2C device found at address 0x");
  if (address < 16)
    Serial.print("0");

  Serial.print(address,HEX);
  Serial.println("  !");

  nDevices++;
}
else if (error==4)
{
  Serial.print("Unknown error at address 0x");
  if (address < 16)
    Serial.print("0");

  Serial.println(address,HEX);
}   }

if (nDevices == 0) Serial.println(“No I2C devices found”); else Serial.println(“done”);

delay(5000); // wait 5 seconds for next scan } 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()); } } #include

#define tx 2 #define rx 3

SoftwareSerial configBt(rx, tx); long tm,t,d; //variables to record time in seconds

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

void loop() { if (configBt.available()) { Serial.print((char)configBt.read()); } if (Serial.available()) { configBt.write(Serial.read()); } } int motor1f = 7; int motor1b = 8; int motor2f = 12; int motor2b = 11; void setup() { //opens serial monitor and bluetooth serial monitor Serial.begin(38400); Serial1.begin(38400);

//initializes all motor pins as outputs pinMode(motor1f, OUTPUT); pinMode(motor1b, OUTPUT); pinMode(motor2f, OUTPUT); pinMode(motor2b, OUTPUT); }

void loop() { Serial.println(“forward”); forward(); delay(3000); Serial.println(“backward”); back(); delay(3000); Serial.println(“left”); left(); delay(3000); Serial.println(“right”); delay(3000); Serial.println(“freeze”); freeze(); delay(3000); }

//moves robot forward void forward(){

//chages directions of motors
digitalWrite(motor1f, HIGH);
digitalWrite(motor1b, LOW);
digitalWrite(motor2f, HIGH);
digitalWrite(motor2b, LOW);   }

//moves robot left void left(){

//changes directions of motors
digitalWrite(motor1f, HIGH);
digitalWrite(motor1b, LOW);
digitalWrite(motor2f, LOW);
digitalWrite(motor2b, HIGH);   }

//moves robot right void right(){

//changes directions of motors
digitalWrite(motor1f, LOW);
digitalWrite(motor1b, HIGH);
digitalWrite(motor2f, HIGH);
digitalWrite(motor2b, LOW);   }

//moves robot backwards void back(){

//changes directions of motors
digitalWrite(motor1f, LOW);
digitalWrite(motor1b, HIGH);
digitalWrite(motor2f, LOW);
digitalWrite(motor2b, HIGH);   }

//stops robot void freeze(){

//changes directions of motors
digitalWrite(motor1f, LOW);
digitalWrite(motor1b, LOW);
digitalWrite(motor2f, LOW);
digitalWrite(motor2b, LOW);   }   #include <Wire.h> #include <Adafruit_Sensor.h> #include <Adafruit_ADXL345_U.h>

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void setup(void) { #ifndef ESP8266 while (!Serial); #endif Serial.begin(9600); Serial.println(“Accelerometer Test”); Serial.println(“”);

if(!accel.begin()) { Serial.println(“Ooops, no ADXL345 detected … Check your wiring!”); while(1); }

accel.setRange(ADXL345_RANGE_16_G);

Serial.println(“”); }

void loop(void) { sensors_event_t event; accel.getEvent(&event); double accelerationX = event.acceleration.x; double accelerationY = event.acceleration.y; double accelerationZ = event.acceleration.z; if (accelerationY >= 7.50) { Serial.println(‘F’); } else if (accelerationY <= -5) { Serial.println(‘B’); } else if (accelerationX <= -5.25) { Serial.println(‘L’); } else if (accelerationX >= 5.25) { Serial.println(‘R’); } else { Serial.println(‘S’); } delay(500); } #include #include #include #include #define tx 2 #define rx 3

SoftwareSerial configBt(rx, tx);

Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void setup(void) {

configBt.begin(38400); pinMode(tx, OUTPUT); pinMode(rx, INPUT); Serial.begin(9600); Serial.println(“Accelerometer Test”); Serial.println(“”);

if(!accel.begin()) { Serial.println(“Ooops, no ADXL345 detected … Check your wiring!”); while(1); }

accel.setRange(ADXL345_RANGE_16_G);

Serial.println(“”); }

void loop(void) { sensors_event_t event; accel.getEvent(&event); double accelerationX = event.acceleration.x; double accelerationY = event.acceleration.y; double accelerationZ = event.acceleration.z; if (accelerationY >= 7.50) { configBt.write(‘w’); } else if (accelerationY <= -5) { configBt.write(‘a’); } else if (accelerationX <= -5.25) { configBt.write(‘s’); } else if (accelerationX >= 5.25) { configBt.write(‘d’); } delay(500); } #define motor1f 7; #define motor1b 8; #define motor1e 9; #define motor2f 12; #define motor2b 11; #define motor2e 10;

//character variable for command char c = “”;

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

void setup() { //opens serial monitor and bluetooth serial monitor Serial.begin(38400); Serial1.begin(38400);

//initializes all motor pins as outputs pinMode(motor1f, OUTPUT); pinMode(motor1b, OUTPUT); pinMode(motor1e, OUTPUT); pinMode(motor2f, OUTPUT); pinMode(motor2b, OUTPUT); pinMode(motor2e, OUTPUT); }

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

//acts based on character switch(c){

//forward case
case 'w':
  forward();
  break;
  
//left case
case 'a':
  left();
  break;
  
//right case
case 's':
  right();
  break;
  
//back case
case 'd':
  back();
  break;
  
//speed up case
case 'q':
  speedup();
  break;
  
//slow down case
case 'e':
  slowdown();
  break;
  
//default is to stop robot
default:
  freeze();
} }

//moves robot forward void forward(){

//chages directions of motors
digitalWrite(motor1f, HIGH);
digitalWrite(motor1b, LOW);
digitalWrite(motor2f, HIGH);
digitalWrite(motor2b, LOW);

//writes the speed
analogWrite(motor1e, s);
analogWrite(motor2e, s);   }

//moves robot left void left(){

//changes directions of motors
digitalWrite(motor1f, HIGH);
digitalWrite(motor1b, LOW);
digitalWrite(motor2f, LOW);
digitalWrite(motor2b, HIGH);

//writes the speed
analogWrite(motor1e, s);
analogWrite(motor2e, s);   }

//moves robot right void right(){

//changes directions of motors
digitalWrite(motor1f, LOW);
digitalWrite(motor1b, HIGH);
digitalWrite(motor2f, HIGH);
digitalWrite(motor2b, LOW);

//writes the speed
analogWrite(motor1e, s);
analogWrite(motor2e, s);   }

//moves robot backwards void back(){

//changes directions of motors
digitalWrite(motor1f, LOW);
digitalWrite(motor1b, HIGH);
digitalWrite(motor2f, LOW);
digitalWrite(motor2b, HIGH);

//writes the speed
analogWrite(motor1e, s);
analogWrite(motor2e, s);   }

//stops robot void freeze(){

//changes directions of motors
digitalWrite(motor1f, LOW);
digitalWrite(motor1b, LOW);
digitalWrite(motor2f, LOW);
digitalWrite(motor2b, LOW);

//writes the speed
analogWrite(motor1e, 0);
analogWrite(motor2e, 0);   }

//speeds up robot void speedup(){

//adds 10 to speed s+=10;

//saturates speed so it doesn’t write improper value if(s>255) s = 255; }

void slowdown(){

//subtracts 10 from speed s -= 10;

//saturates speed so it doesn’t write improper value if(s<0) s = 0; } BTMotor.ino 4 KB