Gesture Controlled Car

In this project I built a car and wired motors and a battery to power it. Then I uploaded code to program the car. My next steps are to connect my bluetooth module to the car and the master bluetooth module to the remote arduino, which makes the car gesture controlled. Think, Power Rangers megazord.

Engineer

Lailah B.

Area of interest

Robotics, computer programing

School

Success Academy High School of Liberal Arts

Grade

Incoming Sophomore

Final Milestone

Materials:

Arduino Uno

wires

Ultra sonic sensor

Servo

Step 1

ultrasonic sensor

Serial Monitor

oip
4

*insert code here*

Step 2

Servo

Serial Monitor

img_0521

*insert code here*

Step 3

Integrate both codes

Serial Monitor

20200723_143026-1

*insert code here*

My final milestone. 4 MODIFICATION OBSTACLE AVOIDANCE -INCLUDE ULTRA SONIC SENSOR -INCLUDE SERVO – CODE AND DISTANCE BIG TAKE AWAY IS THAT MY CAR SWITCED FROM AUTONUMES command to a programed command NEXT MODIFICATION WITH NEO PIXLES WHAT i LEARNED I did a little bit of everything in this project -OERSEVRANCE AND LOTS OF PROBLEM SOLVING SKILLS, THERE IS A LOT OF FAILUR IN ENGNNERING BUT TURNING THOES L’a into W’s makes it with it and gives me a sense of fulfilment Thank you for watching my journey

Second Milestone

Materials:

Arduino Uno

Arduino Nano

nrf24l01 module (2)

accelerometer

bread board

wires

Step 1

First I had to set up and connect both my nrf24l01 modules. One was the transmitter and the other was the receiver.

The Transmitter was connected to the Arduino Nano and the Receiver was connected to the Arduino Uno.

The nrf’s use radio waves that communicate like walkie – talkies.

annotation-2020-07-03-205317
reciver-photo

connection guide

Arduino Nano/Uno -> nrf24l01

3.3v -> VCC/VIN

GND -> GND

8 -> CSN

7 -> CE

13 -> SCK

11 -> MOSI

12 -> MISO

Serial Monitor

Lailah B.
Nrf_"Hello world"_Transmitter_code
  1. /*
  2. * Arduino Wireless Communication Tutorial
  3. *     Example 1 - Transmitter Code
  4. *                
  5. * by Dejan Nedelkovski, www.HowToMechatronics.com
  6. * 
  7. * Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
  8. */
  9. #include <SPI.h>
  10. #include <nRF24L01.h>
  11. #include <RF24.h>
  12. RF24 radio(7, 8); // CE, CSN
  13. const byte address[6] = "00001";
  14. void setup() {
  15.   radio.begin();
  16.   radio.openWritingPipe(address);
  17.   radio.setPALevel(RF24_PA_MIN);
  18.   radio.stopListening();
  19. }
  20. void loop() {
  21.   const char text[] = "Hello World";
  22.   radio.write(&text, sizeof(text));
  23.   delay(1000);
  24. }
Nrf_"Hello world"_Receiver_code
  1. /*
  2. * Arduino Wireless Communication Tutorial
  3. *       Example 1 - Receiver Code
  4. *                
  5. * by Dejan Nedelkovski, www.HowToMechatronics.com
  6. * 
  7. * Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
  8. */
  9. #include <SPI.h>
  10. #include <nRF24L01.h>
  11. #include <RF24.h>
  12. RF24 radio(7, 8); // CE, CSN
  13. const byte address[6] = "00001";
  14. void setup() {
  15.   Serial.begin(9600);
  16.   radio.begin();
  17.   radio.openReadingPipe(0, address);
  18.   radio.setPALevel(RF24_PA_MIN);
  19.   radio.startListening();
  20. }
  21. void loop() {
  22.   if (radio.available()) {
  23.     char text[32] = "";
  24.     radio.read(&text, sizeof(text));
  25.     Serial.println(text);
  26.   }
  27. }
Step 2

Then I had to set up my accelerometers, by plunging it in my Arduino Nano. The accelerometer measures angles and positions, which is important for gesture control because its based on hand movement, and the car will recognize the gesture into direction.

image

Connections Guide:

Accelerometer -> Arduino

VCC -> 3.3 V / 5 V (better)

GND -> GND

SCL -> A5

SDA -> A4

Serial Monitor

accphoto
Accelerometer _Basic Reading Example code
  1. // Basic demo for accelerometer readings from Adafruit MPU6050
  2.  
  3. #include <Adafruit_MPU6050.h>
  4. #include <Adafruit_Sensor.h>
  5. #include <Wire.h>
  6.  
  7. Adafruit_MPU6050 mpu;
  8.  
  9. void setup(void) {
  10.   Serial.begin(115200);
  11.   while (!Serial)
  12.     delay(10); // will pause Zero, Leonardo, etc until serial console opens
  13.  
  14.   Serial.println("Adafruit MPU6050 test!");
  15.  
  16.   // Try to initialize!
  17.   if (!mpu.begin()) {
  18.     Serial.println("Failed to find MPU6050 chip");
  19.     while (1) {
  20.       delay(10);
  21.     }
  22.   }
  23.   Serial.println("MPU6050 Found!");
  24.  
  25.   mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
  26.   Serial.print("Accelerometer range set to: ");
  27.   switch (mpu.getAccelerometerRange()) {
  28.   case MPU6050_RANGE_2_G:
  29.     Serial.println("+-2G");
  30.     break;
  31.   case MPU6050_RANGE_4_G:
  32.     Serial.println("+-4G");
  33.     break;
  34.   case MPU6050_RANGE_8_G:
  35.     Serial.println("+-8G");
  36.     break;
  37.   case MPU6050_RANGE_16_G:
  38.     Serial.println("+-16G");
  39.     break;
  40.   }
  41.   mpu.setGyroRange(MPU6050_RANGE_500_DEG);
  42.   Serial.print("Gyro range set to: ");
  43.   switch (mpu.getGyroRange()) {
  44.   case MPU6050_RANGE_250_DEG:
  45.     Serial.println("+- 250 deg/s");
  46.     break;
  47.   case MPU6050_RANGE_500_DEG:
  48.     Serial.println("+- 500 deg/s");
  49.     break;
  50.   case MPU6050_RANGE_1000_DEG:
  51.     Serial.println("+- 1000 deg/s");
  52.     break;
  53.   case MPU6050_RANGE_2000_DEG:
  54.     Serial.println("+- 2000 deg/s");
  55.     break;
  56.   }
  57.  
  58.   mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
  59.   Serial.print("Filter bandwidth set to: ");
  60.   switch (mpu.getFilterBandwidth()) {
  61.   case MPU6050_BAND_260_HZ:
  62.     Serial.println("260 Hz");
  63.     break;
  64.   case MPU6050_BAND_184_HZ:
  65.     Serial.println("184 Hz");
  66.     break;
  67.   case MPU6050_BAND_94_HZ:
  68.     Serial.println("94 Hz");
  69.     break;
  70.   case MPU6050_BAND_44_HZ:
  71.     Serial.println("44 Hz");
  72.     break;
  73.   case MPU6050_BAND_21_HZ:
  74.     Serial.println("21 Hz");
  75.     break;
  76.   case MPU6050_BAND_10_HZ:
  77.     Serial.println("10 Hz");
  78.     break;
  79.   case MPU6050_BAND_5_HZ:
  80.     Serial.println("5 Hz");
  81.     break;
  82.   }
  83.  
  84.   Serial.println("");
  85.   delay(100);
  86. }
  87.  
  88. void loop() {
  89.  
  90.   /* Get new sensor events with the readings */
  91.   sensors_event_t a, g, temp;
  92.   mpu.getEvent(&a, &g, &temp);
  93.  
  94.   /* Print out the values */
  95.   Serial.print("Acceleration X: ");
  96.   Serial.print(a.acceleration.x);
  97.   Serial.print(", Y: ");
  98.   Serial.print(a.acceleration.y);
  99.   Serial.print(", Z: ");
  100.   Serial.print(a.acceleration.z);
  101.   Serial.println(" m/s^2");
  102.  
  103.   Serial.print("Rotation X: ");
  104.   Serial.print(g.gyro.x);
  105.   Serial.print(", Y: ");
  106.   Serial.print(g.gyro.y);
  107.   Serial.print(", Z: ");
  108.   Serial.print(g.gyro.z);
  109.   Serial.println(" rad/s");
  110.  
  111.   Serial.print("Temperature: ");
  112.   Serial.print(temp.temperature);
  113.   Serial.println(" degC");
  114.  
  115.   Serial.println("");
  116.   delay(500);
  117. }
Step 3

The last step was to write a code that combined the nrf module and accelerometer, for each receiver and transmitter Arduino.

This is so the Nrf module can transmit and receive values form the accelerometer.

*Notice how the serial monitor reads “turn right” and “move backward”, down below.

Serial Monitor

nrfphoto
Transmitter(Nfr/Accelerometer)_ code
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

RF24 radio(7, 8); // CE, CSN

const byte address[6] = "00001";

char gesture = '0'; //by default, the car is not moving

Adafruit_MPU6050 mpu;

void setup() {

radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();

Serial.begin(115200);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens

Serial.println("Adafruit MPU6050 test!");

// Try to initialize!
if (!mpu.begin()) {
Serial.println("Failed to find MPU6050 chip");
while (1) {
delay(10);
}
}
Serial.println("MPU6050 Found!");

mpu.setAccelerometerRange(MPU6050_RANGE_8_G);
Serial.print("Accelerometer range set to: ");
switch (mpu.getAccelerometerRange()) {
case MPU6050_RANGE_2_G:
Serial.println("+-2G");
break;
case MPU6050_RANGE_4_G:
Serial.println("+-4G");
break;
case MPU6050_RANGE_8_G:
Serial.println("+-8G");
break;
case MPU6050_RANGE_16_G:
Serial.println("+-16G");
break;
}
mpu.setGyroRange(MPU6050_RANGE_500_DEG);
Serial.print("Gyro range set to: ");
switch (mpu.getGyroRange()) {
case MPU6050_RANGE_250_DEG:
Serial.println("+- 250 deg/s");
break;
case MPU6050_RANGE_500_DEG:
Serial.println("+- 500 deg/s");
break;
case MPU6050_RANGE_1000_DEG:
Serial.println("+- 1000 deg/s");
break;
case MPU6050_RANGE_2000_DEG:
Serial.println("+- 2000 deg/s");
break;
}

mpu.setFilterBandwidth(MPU6050_BAND_21_HZ);
Serial.print("Filter bandwidth set to: ");
switch (mpu.getFilterBandwidth()) {
case MPU6050_BAND_260_HZ:
Serial.println("260 Hz");
break;
case MPU6050_BAND_184_HZ:
Serial.println("184 Hz");
break;
case MPU6050_BAND_94_HZ:
Serial.println("94 Hz");
break;
case MPU6050_BAND_44_HZ:
Serial.println("44 Hz");
break;
case MPU6050_BAND_21_HZ:
Serial.println("21 Hz");
break;
case MPU6050_BAND_10_HZ:
Serial.println("10 Hz");
break;
case MPU6050_BAND_5_HZ:
Serial.println("5 Hz");
break;
}

Serial.println("");
delay(100);


}

void loop() {

/* Get new sensor events with the readings */
sensors_event_t a, g, temp;
mpu.getEvent(&a, &g, &temp);


/* Print out the values */
Serial.print("Acceleration X: ");
Serial.print(a.acceleration.x);
Serial.print(", Y: ");
Serial.print(a.acceleration.y);
Serial.print(", Z: ");
Serial.print(a.acceleration.z);
Serial.println(" m/s^2");

Serial.print("Rotation X: ");
Serial.print(g.gyro.x);
Serial.print(", Y: ");
Serial.print(g.gyro.y);
Serial.print(", Z: ");
Serial.print(g.gyro.z);
Serial.println(" rad/s");

//Serial.print("Temperature: ");
//Serial.print(temp.temperature);
//Serial.println(" degC");

//Serial.println("");
//delay(500);

//new

//add code here to convert the accelerometer data into a command for the robot
//forward gesture occures when acceleration.x is greater than 4
//move backwards gesture occurs when
if (a.acceleration.x == 0.0)
{
gesture = 0;
Serial.println("stop moving");
radio.write(&gesture, sizeof(gesture));
}
if (a.acceleration.x > 4.0)
{
gesture = 1;
Serial.println("move foward");
radio.write(&gesture, sizeof(gesture));
}

//move backwards gesture occurs when
if (a.acceleration.x < 2.0)
{
gesture = 2;
Serial.println("move backward");
radio.write(&gesture, sizeof(gesture));
}

//move right gesture occurs when
if (a.acceleration.x > -2.0)
{
gesture = 3;
Serial.println("turn right");
radio.write(&gesture, sizeof(gesture));

}
//move left gesture occurs when
if (a.acceleration.x > 10.0)
{
gesture= 4;
Serial.println("turn left");
radio.write(&gesture, sizeof(gesture));
}
//send the gesture signal to the Arduino Uno
}
Receiver_(Nfr/Accelerometer)_ code
/*
* Arduino Wireless Communication Tutorial
* Example 1 - Receiver Code
* 
* by Dejan Nedelkovski, www.HowToMechatronics.com
* 
* Library: TMRh20/RF24, https://github.com/tmrh20/RF24/
*/

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <L298N.h>

RF24 radio(7, 8); // CE, CSN

const byte address[6] = "00001";
int value=-1;

//pin definition
#define ENa 5
#define IN1 2
#define IN2 6

#define ENb 3
#define IN3 9
#define IN4 4
//create a motor instance
L298N motor(ENa, IN1, IN2);
L298N motor2(ENb, IN3,IN4 );
//motor 2= left output 3&4
//motor= right output 1&2
//max speed = 255
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_MIN);
radio.startListening();
}

void loop() {
if (radio.available()) {
// char text[32] = "";

radio.read(&value, sizeof(value));
Serial.println(value);

if (value == 0)
{
//motors should all be off
motor.setSpeed(0);
motor2.setSpeed(0);
Serial.println ("Motors off");
}
else if (value == 1)
{
//motors should drive forward
//add code here for motors to drive forward
motor.setSpeed(250);
motor2.setSpeed(250);
motor.forward();
motor2.forward();
Serial.println ("Driving foward");
}
else if (value == 2)
{
//motors should drive backward
//add code here for motors to drive backward

motor.setSpeed(200);
motor2.setSpeed(200);
motor.backward();
motor2.backward();
Serial.println ("Driving backward");
} 
else if (value == 3)
{
//motors should drive right

motor.setSpeed(250);
motor2.setSpeed(0);
motor.forward();
motor2.forward();
Serial.println ("turning right");
} 
else if (value == 4)
{

//motors should drive left
motor.setSpeed(0);
motor2.setSpeed(250);
motor.forward();
motor2.forward();
Serial.println ("turning left");
}
}
}
My second milestone was working on the gesture control aspect and to complete this I had to configure the accelerometer and then use the nrf modules to transmit and receive the accelerometer values. Why, because the accelerometer measures angles and position, which is needed for the car to recognize hand motions as driving directions. How, once the accelerometer and nrf are connected, I write in the code what accelerometer values correspond with directions. Now the car moves when I move. This is the final product of my base project, my next challenge will be modifications.

First Milestone

Materials:

Car chassis kit

motor diver

Arduino Uno

wires

battery pack

Step 1

First I had to build my chassis.

The main components of the kit are the two motors, two drive wheels, and a large base.

Step 2

Next, I had to power my car with a motor driver and connect many wires to my Arduino.

The motor driver allows me to power both motors at the same time and connect the Arduino and battery pack. The Arduino commands the motors’ wheel movement.

Step 3

Finally, I uploaded code to program the motors and get my wheels running.

The code explains the motor driver connections and the movement and speed commands.

Code for wheel function

#include <L298N.h>

//pin definition
#define ENa 9
#define IN1 7
#define IN2 6
#define ENb 3
#define IN3 5
#define IN4 4
//create a motor instance
L298N motor(ENa, IN1, IN2);
L298N motor2(ENb, IN3,IN4 );
void setup() {

//used for display information
Serial.begin(9600);

motor.setSpeed(80); // an integer between 0 and 255
motor2.setSpeed(80); // an integer between 0 and 255
}

void loop() {

//tell the motor to go forward (may depend by your wiring)
motor.forward();
motor2.forward();
//print the motor satus in the serial monitor
Serial.print(“Is moving = “);
Serial.println(motor.isMoving());
Serial.println(motor2.isMoving());
delay(3000);

//stop running
motor.stop();
motor2.stop();

Serial.print(“Is moving = “);
Serial.println(motor2.isMoving());
Serial.println(motor.isMoving());
delay(3000);

//change the initial speed
motor.setSpeed(200);
motor2.setSpeed(200);

//tell the motor to go back (may depend by your wiring)
motor.backward();
motor2.backward();

Serial.print(“Is moving = “);
Serial.println(motor.isMoving());
Serial.println(motor2.isMoving());

delay(3000);

//stop running
motor.stop();
motor2.stop();

Serial.print(“Is moving = “);
Serial.println(motor.isMoving());
Serial.println(motor2.isMoving());

//change the initial speed
motor.setSpeed(255);
motor2.setSpeed(255);

Serial.print(“Get new speed = “);
Serial.println(motor.getSpeed());
Serial.println(motor2.getSpeed());

delay(3000);
}

My first milestone was when I completed programming the motors of my chassis to move the wheels. After I had built the chassis I had to connect the battery, which powers the base, to the motors using a motor driver. Afterward, I connected the motor driver to the Arduino, to receive the program from my computer. Then there was the matter of connecting the battery wire to the switch to stop and allow power to the motors. Finally, in the actual programming I used a pre written code but I was faced with the challenge of making it command both motors, which I completed successfully. However, an issue I would have to fix is my wiring and control of the wheel since I can’t make both wheels move continuously and simultaneously every time.

Leave a Comment

Start typing and press Enter to search

Bluestamp Engineering