Smart Robot Car

by rricklic in Circuits > Robots

43361 Views, 112 Favorites, 0 Comments

Smart Robot Car

20171101_182615.jpg

I've tinkered around with Arduino and other microcontrollers for years, and was recently asked if I'd be interested in teaching a class on building a simple autonomous robot car. The "UCTRONICS Smart Robot Car Kit" is the kit that was settled on for the class. The material list should be common enough to purchase individually if the kit can no longer be found.

This project took me about 3 hours to complete in addition to taking the photos and being distracted by my 6 year old daughter and 10 month old son.

Gather Materials and Tools

material.png
tools.png
software.png

Materials:

  • Arduino UNO R3
  • L293D motor drive shield
  • HC-SR04 ultrasonic sensor
  • holder for HC-SR04
  • TowerPro SG90 servo motor
  • SG90 servo arms
  • mount for HC-SR04 and SG90 servo
  • 2 gear motors (1:48) 3V-6V DC
  • 2 tire wheels (65mm)
  • wheel mounts
  • 2 speed encoders
  • caster wheel
  • 4 AA battery pack
  • rocker switch
  • car chassis
  • screws
  • nuts
  • extender nuts
  • wires
  • male headers
  • 4 AA batteries
  • 9v battery (optional)
  • 9v battery power cord (optional)

Tools:

  • soldering iron (Weller WLC100)
  • silver bearing solder
  • solder wick
  • Phillips-head screwdriver
  • needle nose pliers
  • wire stripper
  • breadboard or foam pad (optional)
  • multimeter (optional)

Software:

  • Arduino IDE
  • computer
  • USB cable A-male to B-male

Prepare Servo Mount

20171029_085813.jpg
20171029_090059.jpg

Peal off the protected paper from servo mount.
Secure servo to mount with 2 screws and 2 nuts.

Prepare Ultrasonic Sensor Holder

20171029_090128.jpg
20171029_090223.jpg

Carefully slide the ultrasonic sensor holder around the transmitter and receiver protrusions.
You may need to file the holder holes or bend the transmitter and receiver to get it to fit.

Solder Header Pins to Motor Drive Shield

20171029_090301.jpg
20171029_090315.jpg
20171029_090722.jpg
20171029_090911.jpg
20171029_093501.jpg
20171029_094200.jpg
20171101_083725.jpg

Solder the header pins into the motor drive shield.
We will need 4 additional pins for the ultrasonic sensor: a power source, ground, I/O pin (in this cases analog pin 5), and pin 2 (for programming the interrupt when the sensor is ready to calculate the distance).

Alternatively, you could sandwich the wires between the shield and Arduino if soldering is not your thing.

Attach Motors to Chassis

20171029_094918.jpg
20171029_095009.jpg
20171029_100859.jpg
20171029_102513.jpg
20171029_104151.jpg
20171029_104644.jpg
20171029_104823.jpg

Remove any connections from the ends of the wires to expose bare wire.
Tin the wire with solder and solder them to the motor terminals.
Slide the motor mounts through the chassis and secure each motor with 2 screws and 2 nuts.
Attach the speed encoders to the inside part of the motor.

Note: the speed encoders can be used in conjunction with an optical sensor to determine how fast the wheels are spinning and/or how far the car has traveled, but that'll have to be another instructable.

Attach Caster Wheel to Chassis

20171029_105018.jpg
20171029_105217.jpg
20171029_105721.jpg
20171029_105947.jpg

Attach 4 nut extensions to the caster with screws.
Secure the caster to the chassis with screws.
The pre-drilled holes in the chassis may be off so drilling additional holes may be needed.

Attach Wheels to Motors

20171029_110130.jpg
20171029_110212.jpg

Attach the tire wheels to the outside part of the motors.

Attach Server and Ultrasonic Sensor to Chassis

20171029_110305.jpg
20171029_110528.jpg
20171029_110732.jpg
20171029_111113.jpg
20171029_111304.jpg

Secure the servo mount to the chassis with 2 screws and 2 nuts.
Try to center the servo as much as possible.
Attach a servo arm to the servo holder with 2 screws.
Be careful not to use screws that are longer than the base of the arm as it will prevent it from attaching to the servo motor securely.

Attach Arduino Uno and Motor Drive Shield to Chassis

20171029_094304.jpg
20171029_094430.jpg
20171029_111832.jpg
20171029_113749.jpg
20171029_134835.jpg

Attach the shield onto the top of the Arduino making sure that the male pins line up with the appropriate female pins.
Secure the Arduino and shield to the chassis with 2 screws and 2 nuts.
Depending on the length of the screws, additional nuts may be necessary to act as spacers to ensure the Arduino it securely attached to chassis.

Connect Servo and Ultrasonic Sensor to Motor Shield

20171029_113913.jpg
20171029_111416.jpg
20171029_111549.jpg
20171029_111741.jpg
20171101_083810.jpg
20171101_083750.jpg

There are dedicated servo pins on the motor drive shield so attach the servo cord to "servo one" being sure the colors are brown, red, and orange for pins 1, 2, and 3 respectively.
Bend the pins on the ultrasonic sensor so that they are perpendicular to the back of the sensor and attach 4 wire jumpers.
Attach the opposite ends to the power, ground, A5, and pin 2 headers soldered in from earlier.
The remaining pins can be used for future projects.

Connect Motors to Motor Drive Shield

20171029_114850.jpg
20171029_114936.jpg
20171029_115541.jpg
20171103_084356.jpg

Remove any connections from the wires soldered to the motors and attach to the motor drive shield.
In this case, motor 3 and 4 on the shield were used due to their close proximity to the motor terminals.
Depending on how you soldered the wires to the motors, you may need to switch the wires at the screw terminals

Attach Battery Pack and Rocker Switch to Chassis

20171029_115927.jpg
20171029_120213.jpg
20171029_120313.jpg

Secure the battery pack to the chassis with 2 screws and 2 nuts.
Snap the rocker switch into place with the terminals facing upwards.

Connect Battery Pack and Switch to Motor Drive Shield

20171029_120643.jpg
20171101_182755.jpg
20171101_182735.jpg
20171029_121839.jpg
20171103_084423.jpg

Cut the power (red) wire roughly in half so that we can solder it through the rocker switch.
Attach the power wire from the switch and the ground from the battery pack to the power and ground terminal on the motor drive shield.
This will also power the Arduino.
Put 4AA batteries into the battery pack, hit the switch to the "on" position, and ensure that both the motor shield and Arduino power indicator lights are illuminated.

Optionally, a 9v batter can be used to power the Arduino separately.
Powering the Arduino separately will prevent any voltage drops from resetting the Arduino code being executed.
Similarly, the 9v battery could also be wired into the switch instead of the battery pack.

Download Arduino IDE, Program Sketch, and Upload to Arduino Uno

20171103_085324.jpg
20171103_085356.jpg
20171103_085425.jpg
20171103_085335.jpg

Download the Arduino IDE for your operating system and architecture:
https://www.arduino.cc/en/Main/Software

Download the program sketch:
https://github.com/rricklic/arduino.uctronics.robo...

The code will have the car move forward at full speed until it detects an obstacle.
It will scan from 60 to 120 degrees in front and determine if it should back up and turn left or right.
Once done it will continue moving forward again at full speed.

How to upload program sketch to Arduino Uno:
Attach the USB cord to your computer and the other end to the Arduino.
You will likely need to remove the ultrasonic sensor to get proper clearance.
Open up the program sketch in the IDE.
Under the "Tools" menu item, ensure that the board is set to "Arduino/Genuino Uno" and that the port is your Arduino (eg: /dev/ttyACM0).
Hit the check button to ensure the sketch compiles.
Hit the arrow button to upload the sketch to the attached Arduino.

NOTE: If you are using a Linux distribution as your operating system, you may need to set permissions by adding your user to the "dialout" group:
$ sudo usermod -a -G dialout $USER

Rebooting makes this change permanent.

Experiment! Have Fun!

The code was made fairly simple, but the functionality is defined well in functions allowing for easily modifying the default behavior. There are also 5 analog pins that can be used for more sensors (eg: optical sensor for use with speed encoders), room for 2 more motors on the shield, and a set of servo pins so this base car can be enhance quite a bit!