Autonomous Robotic Car

by 800009724 in Circuits > Arduino

36 Views, 0 Favorites, 0 Comments

Autonomous Robotic Car

WIN_20241206_10_35_47_Pro.jpg

I made an autonomous robotic car for a project in one of my classes. It's purpose was to be able to detect obstacles and drive smoothly with no stop.

Supplies

For this project you will need:

  1. Acrylic or Cardboard
  2. Laser Cutter
  3. Arduino and Motorshield
  4. Ultrasonic Sensor
  5. Battery Pack (one that can connect to the Motor Shield)
  6. 4 Wheels (ones that work with the Motor Shield)
  7. Soldering Iron
  8. 4 Male to Female Wires
  9. Hot Glue or Tape
  10. (optional) Zip Ties for Organization

Make a Car Chasis With Adobe Illustrator

Screenshot 2024-12-06 101553.png

Make a Car Chasis that can fit your wheels and make sure to add holes for the wires. Leave lots of space on top for the Motor Shield, Arduino, Battery Pack, and Ultrasonic Sensor. Then Laser cut it and see how it looks. Always use cardboard on your first try so that if you mess up you can fix it and make sure your acrylic version looks better.

Motorshield and Wheels

WIN_20241206_10_35_47_Pro.jpg

On the bottom of the car hot glue the wheels to the frame, make sure the wires go through the holes. Once all four wheels are hot glued, take out the Arduino and place the Motorshield on top of it. Then hook the wires into the slots and add a battery pack. Then get to the coding.

Add a Ultrasonic Sensor

WIN_20241206_10_35_47_Pro.jpg

Add the Ultrasonic Sensor and an Ultrasonic Sensor stand if you have. If you don't just use a breadboard or just tape it down. Then solder 4 pins into the Motorshield. Solder the male part, not the female part. Solder into 5V, GND (Ground), Pin 2, and Pin 13. Make sure there's no bridges or else redo it. Then put the 5V wire into VCC, put the GND wire into GND, put 2 into TrigPin, and 13 into EchoPin. Then re-enforce it at the front of your car.

Coding

Screenshot 2024-12-06 104225.png
Screenshot 2024-12-06 104300.png
Screenshot 2024-12-06 104329.png

You need to download a file called AFMotor because that file controls the Motorshield. Then you will have to put this code in. This code worked for me but it might not for you so you will have to change some things such as the distance variable, the delay after the else statement and also the speeds for the motors.

#include <AFMotor.h>

AF_DCMotor motor1(1, MOTOR12_64KHZ);

AF_DCMotor motor2(2, MOTOR12_64KHZ);

AF_DCMotor motor3(3, MOTOR12_64KHZ);

AF_DCMotor motor4(4, MOTOR12_64KHZ);

const int trigPin = 2;

const int echoPin = 13;

int threshold = 8000;

long distance;


void setup() {

 motor1.setSpeed(100);

 motor2.setSpeed(100);

 motor3.setSpeed(100);

 motor4.setSpeed(100);

 pinMode(trigPin, OUTPUT);

 pinMode(echoPin, INPUT);

 Serial.begin(9600);

}


void loop() {

 digitalWrite(trigPin, LOW);

 delay(10);

 digitalWrite(trigPin, HIGH);

 delay(100);

 digitalWrite(trigPin, LOW);


 distance = pulseIn(echoPin, HIGH);

 Serial.println(distance);

 if (distance > threshold) {

  motor1.run(FORWARD);

  motor2.run(FORWARD);

  motor3.run(FORWARD);

  motor4.run(FORWARD);

 }

 else {

  motor1.run(BACKWARD);

  motor2.run(RELEASE);

  motor3.run(RELEASE);

  motor4.run(BACKWARD);

 }

 delay(500);

}