Gesture Controlled RC Car
This project is a simple robot with a robotic arm attached to it. The only difference is that it is controlled by hand gestures.
Engineer
Lola S
Area of Interest
Electrical Engineering
School
Loyola School
Grade
Incoming Senior
Second Milestone
For my second milestone, I wanted to gain control of my motors with my flex sensors. When I bend my fingers it controls which motors are moving. It sends this signal using the XBee which is what I had a lot of trouble with: making this device work with bluetooth. I hooked up my motors into a circuit with an H-bridge which allows the motors to move forwards or backwards. I calibrated it so that its resting mode would be when my fingers are slightly bent (at rest). When my fingers are “more bent” the wheels move forward. When my fingers are straightened the wheels move backwards. I also designed the structure of my car which has two wheels in the back which are connected by the motors and one caster ball in the front to move with the car.
#define rightMotor1 8
#define rightMotor2 7
#define leftMotor1 9
#define leftMotor2 10
int enA = 5;
int enB = 3;
int inByte = 0;
char incomingByte1;
String inputString = “”; // a string to hold incoming data
boolean stringComplete = false;
String left = “”;
String right = “”;
void setup()
{
pinMode(rightMotor1, OUTPUT);
pinMode(rightMotor2, OUTPUT);
pinMode(leftMotor1, OUTPUT);
pinMode(leftMotor2, OUTPUT);
pinMode(enA, OUTPUT);
pinMode(enB, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (stringComplete) {
int val_1 = left.toInt();
int val_2 = right.toInt();
Serial.println(val_1);
Serial.println(val_2);
left = “”;
right = “”;
stringComplete = false;
analogWrite(enA, abs(val_1));
analogWrite(enB, abs(val_2));
//Drive forwards
if (val_1 > 0) {
digitalWrite(rightMotor1, LOW);
digitalWrite(rightMotor2, HIGH);
}
//Drive backwards
else {
digitalWrite(rightMotor1, HIGH);
digitalWrite(rightMotor2, LOW);
}
if (val_2 < 0) {
digitalWrite(leftMotor2, HIGH);
digitalWrite(leftMotor1, LOW);
}
//Drive backwards
else {
digitalWrite(leftMotor2, LOW);
digitalWrite(leftMotor1, HIGH);
}
}
}
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString: // if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == ‘L’) {
left = inputString;
inputString = “”;
inChar = “”;
}
else inputString += inChar;
if (inChar == ‘\n’) {
right = inputString;
stringComplete = true;
inputString = “”;
}
}
}
int flexSensorPin1 = A2;
int flexSensorPin2 = A3;
int ledPin=13;
int b=0;
char s_str1[2];
char s_str2[2];
char s_str3[2];
char s_str4[2];
char command=’e’;
String str1,str2,str3,str4;
void setup(){
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
digitalWrite(ledPin, HIGH);
if (b = 0)
{
command=’e’;
}
// Read the values
int flexS1 = analogRead(flexSensorPin1);
int flexS2 = analogRead(flexSensorPin2);
// Numbers below is individual for each of the flex sensors
if (flexS1 < 500) flexS1 = 500;
else if (flexS1 > 600) flexS1 = 600;
if (flexS2 < 430) flexS2 = 430;
else if (flexS2 > 560) flexS2 = 560;
int flex_1_0to100 = map(flexS1, 600, 500, 255, -255);
int flex_2_0to100 = map(flexS2, 430, 560, 255, -255);
if (command==’e’){
Serial.print(flex_1_0to100);
Serial.print(“L”);
Serial.print(flex_2_0to100);
Serial.println();
delay(100);
digitalWrite(ledPin, HIGH);
}
}
First Milestone
int flexSensorPin = A0; //analog pin 0
int flexSensor2Pin = A1; //analog pin 1
int flexSensor3Pin = A2; //analog pin 2
int flexSensor4Pin = A3; //analog pin 3
void setup() {
Serial.begin(9600);
}
void loop() {
//SENSOR 1
int flexSensorReading = analogRead(flexSensorPin);
Serial.print(“flex 1: “);
Serial.println(flexSensorReading);
int flex0to100 = map(flexSensorReading, 512, 614, 0, 100);
Serial.println(flex0to100);
delay(250);//just here to slow down the output for easier reading
//SENSOR 2
int flexSensor2Reading = analogRead(flexSensor2Pin);
Serial.print(“flex 2: “);
Serial.println(flexSensor2Reading);
int flex2to100 = map(flexSensor2Reading, 512, 614, 0, 100);
Serial.println(flex2to100);
delay(250);
//SENSOR 3
int flexSensor3Reading = analogRead(flexSensor3Pin);
Serial.print(“flex 3: “);
Serial.println(flexSensor3Reading);
int flex3to100 = map(flexSensor3Reading, 512, 614, 0, 100);
Serial.println(flex3to100);
delay(250);
//SENSOR 4
int flexSensor4Reading = analogRead(flexSensor4Pin);
Serial.print(“flex 4: “);
Serial.println(flexSensor4Reading);
int flex4to100 = map(flexSensor4Reading, 512, 614, 0, 100);
Serial.println(flex4to100);
delay(250);
}