View on GitHub

TuhinM_Portfolio

BlueStamp Summer of 2024

Engineer School Area of Interest Grade
Tuhin M Bellarmine College Preparatory Electrical Engineering and Computer Science Rising Sophomore

Gesture Controlled Robot Car

First Modification: 7/8/24

Figure 1 -- Gesture Controlled Robot Car with Ultrasonic Sensor

Figure 2 -- Gesture Controlled Robot Car with Gesture Controller

Final Milestone 6/19/24

Images

Figure 3 -- Gesture Controlled Robot Car and Controller without Modifications

Figure 4 -- Gesture Controller Robot Car and Controller without Modifications

Second Milestone 6/18/24

Images

Figure 5 -- Gesture Controller without Modifications

Figure 6 -- Gesture Controller without Modifications

First Milestone: 6/14/24

Images

Figure 7 -- Gesture Controlled Robot without Modifications

Figure 8 -- Gesture Controlled Robot without Modifications

Schematics

Figure 9 -- Schematics from Hackster.io

Figure 10 -- Schematics for the Gesture Controller

Flowchart for Code Process

Figure 11 -- Flowchart of the Code Process

Code

Test Code for Running Motors 🦾

int In1 = 7; //Defining Digital Pins for Motors
int In2 = 8;
int In3 = 4;
int In4 = 12;
int ENA = 5; //Defining ENA for both sides
int ENA2 = 6;
int SPEED = 210; //Defining the speed of the wheels

void setup()
{

pinMode(In1,OUTPUT); //Designating the motors as outputs
pinMode(In2,OUTPUT);
pinMode(In3,OUTPUT);
pinMode(In4,OUTPUT);
pinMode(ENA,OUTPUT);
pinMode(ENA2,OUTPUT);

digitalWrite(In1,HIGH); //Setting the motor direction, either HIGH or LOW
digitalWrite(In2,LOW);
digitalWrite(In3,HIGH);
digitalWrite(In4,LOW);

analogWrite(ENA,SPEED); //Setting the speed for both sides
analogWrite(ENA2,SPEED);

}

void loop()
{

}

Code for the Robot Car 🤖🚗

#include <SoftwareSerial.h>
SoftwareSerial BT_Serial(2, 3); // RX, TX

#define enA 10//Enable1 L298 Pin enA 
#define in1 9 //Motor1  L298 Pin in1 
#define in2 8 //Motor1  L298 Pin in1 
#define in3 7 //Motor2  L298 Pin in1 
#define in4 6 //Motor2  L298 Pin in1 
#define enB 5 //Enable2 L298 Pin enB 

char bt_data; // variable to receive data from the serial port
int Speed = 150; //Write The Duty Cycle 0 to 255 Enable Pins for Motor Speed  

void setup() { // put your setup code here, to run once

Serial.begin(9600); // start serial communication at 9600bps
BT_Serial.begin(9600); 

pinMode(enA, OUTPUT); // declare as output for L298 Pin enA 
pinMode(in1, OUTPUT); // declare as output for L298 Pin in1 
pinMode(in2, OUTPUT); // declare as output for L298 Pin in2 
pinMode(in3, OUTPUT); // declare as output for L298 Pin in3   
pinMode(in4, OUTPUT); // declare as output for L298 Pin in4 
pinMode(enB, OUTPUT); // declare as output for L298 Pin enB 

delay(200);
}
void loop(){
if(BT_Serial.available() > 0){  //if some date is sent, reads it and saves in state     
bt_data = BT_Serial.read(); 
Serial.println(bt_data);          
}
  
     if(bt_data == 'f'){forword();  Speed=180;}  // if the bt_data is 'f' the DC motor will go forward
else if(bt_data == 'b'){backword(); Speed=180;}  // if the bt_data is 'b' the motor will Reverse
else if(bt_data == 'l'){turnLeft(); Speed=250;}  // if the bt_data is 'l' the motor will turn left
else if(bt_data == 'r'){turnRight();Speed=250;} // if the bt_data is 'r' the motor will turn right
else if(bt_data == 's'){Stop(); }     // if the bt_data 's' the motor will Stop

analogWrite(enA, Speed); // Write The Duty Cycle 0 to 255 Enable Pin A for Motor1 Speed 
analogWrite(enB, Speed); // Write The Duty Cycle 0 to 255 Enable Pin B for Motor2 Speed 

delay(50);
}

void forword(){  //forword
digitalWrite(in1, HIGH); //Right Motor forword Pin 
digitalWrite(in2, LOW);  //Right Motor backword Pin 
digitalWrite(in3, LOW);  //Left Motor backword Pin 
digitalWrite(in4, HIGH); //Left Motor forword Pin 
}

void backword(){ //backword
digitalWrite(in1, LOW);  //Right Motor forword Pin 
digitalWrite(in2, HIGH); //Right Motor backword Pin 
digitalWrite(in3, HIGH); //Left Motor backword Pin 
digitalWrite(in4, LOW);  //Left Motor forword Pin 
}

void turnRight(){ //turnRight
digitalWrite(in1, LOW);  //Right Motor forword Pin 
digitalWrite(in2, HIGH); //Right Motor backword Pin  
digitalWrite(in3, LOW);  //Left Motor backword Pin 
digitalWrite(in4, HIGH); //Left Motor forword Pin 
}

void turnLeft(){ //turnLeft
digitalWrite(in1, HIGH); //Right Motor forword Pin 
digitalWrite(in2, LOW);  //Right Motor backword Pin 
digitalWrite(in3, HIGH); //Left Motor backword Pin 
digitalWrite(in4, LOW);  //Left Motor forword Pin 
}

void Stop(){ //stop
digitalWrite(in1, LOW); //Right Motor forword Pin 
digitalWrite(in2, LOW); //Right Motor backword Pin 
digitalWrite(in3, LOW); //Left Motor backword Pin 
digitalWrite(in4, LOW); //Left Motor forword Pin 
}

Code for the Gesture Controller 👋🕹️

#include <SoftwareSerial.h>
SoftwareSerial BT_Serial(3, 2); // RX, TX

#include <Wire.h> // I2C communication library

const int MPU = 0x68; // I2C address of the MPU6050 accelerometer
int16_t AcX, AcY, AcZ;

int flag=0;

void setup () {// put your setup code here, to run once

  Serial.begin(9600); // start serial communication at 9600bps
  BT_Serial.begin(9600); 

  // Initialize interface to the MPU6050
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission(true);

  delay(500); 
}

void loop () {
  Read_accelerometer(); // Read MPU6050 accelerometer

  if (AcX<60  && flag==0) {
    flag=1;
    BT_Serial.write('f');
  }
  if (AcX>130 && flag==0) {
    flag=1;
    BT_Serial.write('b');
  }
        
  if (AcY<60  && flag==0) {
    flag=1;
    BT_Serial.write('l');
  }
  if (AcY>130 && flag==0) {
    flag=1;
    BT_Serial.write('r');
  }
    
  if((AcX>70) && (AcX<120) && (AcY>70) && (AcY<120) && (flag==1)) {
    flag=0;
    BT_Serial.write('s');
  }

  delay(100);  
}

void Read_accelerometer(){
  // Read the accelerometer data
  Wire.beginTransmission(MPU);
  Wire.write(0x3B); // Start with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  Wire.requestFrom(MPU, 6, true); // Read 6 registers total, each axis value is stored in 2 registers

  AcX = Wire.read() << 8 | Wire.read(); // X-axis value
  AcY = Wire.read() << 8 | Wire.read(); // Y-axis value
  AcZ = Wire.read() << 8 | Wire.read(); // Z-axis value

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

  Serial.print(AcX);
  Serial.print("\t");
  Serial.print(AcY);
  Serial.print("\t");
  Serial.println(AcZ); 
}

Code for the Bluetooth Connection 🛜

#include <SoftwareSerial.h>

SoftwareSerial Bluetooth(3, 2);

void setup() 
{
  Serial.begin(9600);
  Bluetooth.begin(38400);
}

void loop(){
  if (Bluetooth.available())
    Serial.write(Bluetooth.read());
  
  if (Serial.available())
    Bluetooth.write(Serial.read());
}

Bill of Materials

Part Note Price Link
Arduino UNO Used to control the robot movement $25.81 Link
Arduino Nano R3 Used for the hand mounted part $23.23 Link
Inertial Measurement Unit (IMU) (6 deg of freedom) Used for sensing changes and movement $5.99 Link
SparkFun Dual H-Bridge motor drivers L298 Used to control the motors $7.21 Link
Solderless Breadboard Half Size Used to hold the pins and devices for the controller $4.96 Link
HC-05 Bluetooth Module Used for connecting the robot car to the controller on the wrist $10.39 Link
Male/Male Jumper Wires Used to connect electronics to the boards $2.10 Link
Male/Female Jumper Wires Used to connect electronics to the boards $4.11 Link
DC Motor, 12 V Used to make the robot move $2.10 Link
Pimoroni Maker Essentials - Micro-motors & Grippy Wheels Used to translate the motor power to movement $33.79 Link
Rocker Switch, SPST Used to switch the robot and controller on and off $1.26 Link
9V Battery Clip Used to connect to the battery pack $0.309 Link
9V battery (generic) Used to power the robot $1.54 Link
Battery Holder, 18650 x 2 Used to hold the batteries $9.48 Link
Arduino IDE Used to code the functionalities of the robot $0.00 Link

Other Resources/Examples

Arduino Starter Project: 6/12/24

Code

//Defining the LED position on the Breadboard
#define LED_PIN 8
//Defining the Button position on the Breadboard
#define BUTTON_PIN 7

void setup() {
  //Defining the LED as the Output
  pinMode(LED_PIN, OUTPUT);
  //Defining the Button as the Input
  pinMode(BUTTON_PIN, INPUT);
}
void loop() {
  if (digitalRead(BUTTON_PIN) == HIGH) { //If the button is pressed
    digitalWrite(LED_PIN, HIGH); //Turn on the LED
  }
  else { //If the button is not pressed
    digitalWrite(LED_PIN, LOW); //Keep the LED off
  }
}

Bill of Materials

Part Note Price Link
Arduino Uno Control the circuit power and ground $24.50 Link
USB A -> B cable Connection to computer $9.89 Link
Arduino Proto Shield Used to make easier wire connections $9.95 Link
Breadboard Used to hold LED, Button, and wiring $2.90 Link
Male to Male Connectors Used to connect electronics $2.10 Link