Arduino Robot Car

by zanowi65 in Circuits > Arduino

565 Views, 3 Favorites, 0 Comments

Arduino Robot Car

IMG_2306.jpg

This is an Arduino controlled car that can be wirelessly controlled via a Bluetooth app, can line follow, as well as autonomously parallel park.

Supplies

Elegoo-Uno-Front-1024x556.png
61p+QTbMf5L._SX522_.jpg
61KoTA82O+L._AC_SX300_SY300_.jpg
  • Arduino Logic Controller
  • Chanzon half size breadboard
  • 2 pcs photocells
  • 3 pcs Ultrasonic Sensors (HCSR04)
  • Numerous jumper cables
  • 4 RC car dc motors
  • vehicle chassis/frame for assembly
  • 4 pc Hiletgo plastic tire wheel for dc motors
  • 18650 lithium battery cell box
  • HM10 Bluetooth module
  • 14 m4 screws
  • 4 plastic/acrylic spacers
  • 5 - 6 hexagonal threaded brass spacers
  • 4 m4 retaining nuts
  • L298N motor driver
  • 2 mini breadboards
  • HCSR04 ultrasonic sensor mount
  • electrical tape
  • 2 pcs 10k ohm resistor

Assemble Vehicle Chassis

IMG_2307.jpg
IMG_2308.jpg

Use hexagonal threaded brass spacers and m4 screws to affix the upper and lower pieces of the vehicle chassis. Use 5 to 6 hexagonal brass spacers and a total of 10 - 12 m4 screws to secure the spacer to the top and bottom of the vehicle chassis.

Mount Arduino, Motor Driver and DC Motors

IMG_2309.jpg
IMG_2310.jpg
IMG_2313.jpg
Arduino mount.jpg
  1. Use two m4 screws, two plastic spacers, and two retaining nuts to secure the arduino in the center of the top chassis plate
  2. Use this same hardware to secure the L298N motor driver in the center of the bottom base plate
  3. Mount the 4 DC motors at each corner of the vehicle
  4. Use existing holes in the vehicle chassis to secure with hardware or use glue to affix motors to base plate

Mount Breadboards, and US Sensors

Us1.jpg
bb.jpg
us2.jpg
us3.jpg
dual-h-bridge-motor-driver-l298n-44325-750x750.jpg
MFG_3647_HC-SR04.jpg
  1. Use double sided tape to secure two mini breadboards at the front and back of the vehicle.
  2. Mount the Ultrasonic sensors in these mini breadboards
  3. Mount the half-size breaboard at the front of the vehicle, the side closest to the reset button on the Arduino board.
  4. Mount the remaining ultrasonic sensor using the ultrasonic mount on the right side of the vehicle.

Attach Photocells/photoresistors

IMG_2318.jpg
09088-02-L.jpg
  • Solder jumper cables to each leg of each photocell
  • Glue or tape the photocells so that the photoresistor faces towards the ground
  • Arrange both photocells about 2 inches from the center
  • tape or glue the wires leading to and from the photocells to the vehicle body

Wiring

mechwiring.png

For the Motors

  • Wire the motors on the right side of the vehicle in parallel and the motors on the left side in parallel
  • For the right motors wire both positive cables and both negative cables to the OUT1 and OUT2 pins of the L298N motor driver
  • Repeat on the left side with the left motors and OUT3 and OUT4 respectively
  • ENA, IN1, IN2 goes to pin 3, pin 8, and pin 9 respectively
  • ENB, IN3, IN4 goes to pin 6, 10, 11

For the Battery Pack

  • Wire the positive lead of the battery pack to the 20V pin of the motor driver
  • GND to GND from battery to motor driver
  • Wire GND from motor driver to Arduino board
  • Use 5V output pin of motor driver to power Arduino board through Vin pin

For the Photocells

  • Connect one leg of each photocell to one leg of the 10k ohm resistor
  • Connect the other leg of each photocell to the 5V rail on breadboard
  • Ground the other leg of the resistor
  • In line with the leg of the photocell that is going to the 10k ohm resistor, connect the corresponding analog pins
  • The left photocell connects to A0, the right photocell connects to A1

For the Ultrasonic Sensors

  • For all, VCC goes to 5V rail, GND goes to GND rail
  • The front US has TRIG pin 4, and ECHO pin 5
  • The back US has TRIG pin 13, ECHO pin 12
  • The right US has TRIG pin 7, ECHO pin 2

For HM10 Bluetooth Module

  • VCC goes to 5V, GND to GND
  • TXD goes to pin 0
  • RXD goes to pin 1

WIFI Control Code

Control.jpg
Gamepad.jpg
  • This code utilizes the Dabble ios app
  • Use the connect feature in the upper right corner of app and select BT05 to connect to HM10 module
  • The beginning of the code enables and identifies the EN and IN pins for both sets of motors left and right
  • The code utilizes if else statements to correspond the gamepad up, down, left and right buttons on the app to the corresponding forward, back, left and right outputs of the motors

Downloads

Line Tracking Code

linefollow.png
  • The beginning of the code identifies the motor pins and the analog pins for the photocells
  • The code takes the difference between the two photocells (left - right)
  • Using an if statement the code compares the abs value of this difference to see if it meets a threshold value that is experimentally determined
  • If this value is reached that enters the second if loop
  • If the difference is greater than zero that means the right photocell is seeing a lower value and is thus on the black tape so digital write functions are implemented to turn the car right (away from the black line)
  • if the difference is less than zero that means the left photocell is seeing a lower value and the vehicle is turned left

Parallel Parking Code

parallelparking.png
  • The beginning of the code initializes the pins for the US sensors and motors
  • the code uses a term "check" that measures the distance obtained from the right sensor
  • If this distance is greater than some experimentally determined value a spot is found and the check integer changes from 0 to 1
  • Once check == 1, a "space" variable ensures the parking spot is 50 cm wide by measuring the distance traveled the car takes with the right US sensor
  • Once both these conditions are satisfied the car stops and a parking sequence is initiated

Common Mistakes

  1. Since the 0 and 1 pins are being utilized. These pins need to be unplugged when uploading code. The Arduino uses these pins to communicate with the serial monitor. Once the code has been uploaded these pins can be utilized
  2. Make sure to remove the Vin pin when uploading codes to Arduino board
  3. If the motors are spinning opposite the intended direction check wiring to ensure that the motors on the right side and left side are in parallel with each other (positive leads to same IN pin and negative leads to same IN pin).
  4. If the line tracking is not functioning ensure that the photocells are positioned properly and in the same place, also check the threshold value in the line following code. Adjust this value based on ambient lighting conditions and the contrast between the line and the driven surface

Bill of Lading

  • Note only motors, and hardware from this kit were used
  • All other materials came from Arduino kits, personal collections, prior projects, ECE resource center, project labs, etc.