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.

Motor Control Code: ON 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 = “”;
}
}
}

Motor Control Code: ON GLOVE


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

}

}

STEM Summer Classes

First Milestone

For my first milestone in this project, my plan was to be able to gain a reading from the bending of the fingers of my glove. I have set up a circuit of four flex sensors for each finger (excluding the thumb). Each flex sensor is a variable resistor which has an increased resistance as it is bent. This then changes the end voltage which is what is being measured in this circuit. To create the code for this circuit, I found the code to find the voltage using just one resistor. I then made it so that four of these flex sensors would be included in the code with each one set up to a different analog pin. My circuit is fairly simple. Each sensor is hooked up to the same 5V power source on the Arduino Uno. Each pin has a 22K Ohm resistor which acts as a base resistance and this would connect to the ground. Then, each sensor is connected to its own analog pin.
Flex Sensor Code

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

}

Starter Project

So for my starter project, I chose to assemble SparkFun’s BigTime Watch Kit. It comes with multiple parts: a microcontroller, a 7-segment display, 2 capacitors, a resistor, a crystal oscillator, a battery, a printed circuit board, a button, and other parts for its enclosure. The microcontroller is a ATmega328 which came preprogrammed to be able to control the whole circuit. The 7-segment display shows the final product of this circuit which is to display the time and have it change every minute. To be able to change the time every minute, the circuit contains a 32kHz crystal oscillator which causes the voltage itself to oscillate through its set frequency which changes the time every minute. This circuit also contains a coin cell battery which provides the voltage to provide the flow of electricity throughout this circuit.

Leave a Comment

Start typing and press Enter to search

Bluestamp Engineering