NaveedK_Portfolio

I'm an incoming sophomore at Saratoga High School. I like engineering and making things.


Project maintained by NaveedKasnavi Hosted on GitHub Pages — Theme by mattgraham

RC Obstacle Avoidance Car

My project is a RC car that doesn’t hit obstacles.

Engineer School Area of Interest Grade
Naveed K Saratoga High School Electrical Engineering Incoming Sophomore

Fourth Milestone

My fourth milestone was the modify the car chassis to have axle steering instead of tank steering and have the controller be able to drive the car around while not hitting obstacles. The regular arduino servo wasn’t strong enough, so I got a 20kg servo for the steering. To turn the wheels, I 3d printed a ball joint, which would connect to the servo. I used a ball joint because the lever moves horizontally, so if i hadn’t used a ball joint it would’ve bent and either would cause a lot of friction or would break.

Third Milestone

My third milestone was to make a custom controller to control the car. I used Kevin Miller’s library to send data between two ESPs, but it didn’t work at first because I forgot to get the mac address of each ESP. When I got it working, I plugged in two potentiometers, one for throttle, and one for turning, and sent data from the controller ESP to the car ESP. I also 3d printed a custom case for the controller to house the ESP and potentiometer.

Milestone 3

Second Milestone

My second milestone was to get the obstacle avoidance working. I made a simple program that would move forward if there was no obstacle in front of it, and if there was, it would turn to the right. The main issue I ran into was that it would not detect obstacles that didn’t touch the ground but were just above the ultrasonic. Other than that, it worked flawlessly, even with thin obstacles. I also switched from the Arduino to the ESP32, which has an integrated bluetooth module and created an app on a phone to control the car.

Milestone 2

First Milestone

My first milestone was getting the ultrasonic sensor working and allowing it to detect any obstacle, even if it was thin. To do so, I mounted it on a servo with 3d printed parts that were secure enough so it wouldn’t move even though it was secured with tape. I also assembled the chassis and got all the electronics wired up, including the motor driver and all 4 motors. I also made a test program where the robot would only move if there was no obstacle in front of it.

First Milestone

Reflection

Final Code

//#include <ultrasonic.h>
#include <motorlib.h>
#include <ESP32Servo.h>
#include "BluetoothSerial.h" 

int SPEED = 140;

// init Class:
BluetoothSerial ESP_BT; 

Motor leftMotor = Motor(33, 32, 25);
Motor rightMotor = Motor(5, 18, 19);
//Ultrasonic ut = Ultrasonic(26, 27);
Servo angleServo;

int minAngle = 10;
int maxAngle = 75;

float distance;
int minDistance = 10;
bool foundObstacle = false;

int turnDuration = 200;
int incoming;
float times = 0;

int trigPin = 26;
int echoPin = 27;

void setup() {
  Serial.begin(9600);
  ESP_BT.begin("ESP32_Control");
  leftMotor.setup();
  leftMotor.reverse();
  leftMotor.spin(0);

  rightMotor.setup();
//  rightMotor.reverse();
  rightMotor.spin(0);
  

  angleServo.attach(23);

//  ut.setup();

  setupUltrasonic();
}

void loop() {
//  Serial.println("WORKING");
  if (ESP_BT.available()) {
    incoming = ESP_BT.read();
  }
//  incoming = 49;
  if (incoming == 49) {
    angleServo.write(minAngle);
    checkUltrasonic();
    angleServo.write(maxAngle);
    checkUltrasonic();
  } else {
    Serial.println("FALSE");
    leftMotor.spin(0);
    rightMotor.spin(0);
  }
  
}

void checkUltrasonic() {
  unsigned long curTime = millis();
  bool tempFoundObstacle = false;
  while (millis() - curTime < turnDuration) {
    updateUltrasonic();
//    ut.update();
//    Serial.println(ut.distance);
     Serial.println(distance);
    if (distance < minDistance && distance != 0) {
      
      tempFoundObstacle = true;
      foundObstacle = true;
    }
    drive();
    delay(5);
  }
  //Serial.println(foundObstacle);
  foundObstacle = tempFoundObstacle;
}

void drive() {
  if (!foundObstacle) {
    leftMotor.spin(250);
    rightMotor.spin(250);
  } else {
    leftMotor.spin(200);
    rightMotor.spin(-200);
  }
}

void setupUltrasonic() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void updateUltrasonic() {
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  times = pulseIn(echoPin, HIGH);

  distance = (times * 0.034) / 2;
}

Car CAD:

FinalCar

Controller CAD:

FinalController

Car Circuit

FinalCarCircuit

Controller Circuit:

ControllerCircuit