instructables
Smart Robot Car
by rricklic
I've tinkered around with Arduino and other longer be found.
microcontrollers for years, and was recently asked if
I'd be interested in teaching a class on building a This project took me about 3 hours to complete in
simple autonomous robot car. The "UCTRONICS addition to taking the photos and being distracted by
Smart Robot Car Kit" is the kit that was settled on for my 6 year old daughter and 10 month old son.
the class. The material list should be common
enough to purchase individually if the kit can no
Smart Robot Car: Page 1
Step 1: Gather Materials and Tools
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
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
Smart Robot Car: Page 2
1 5
1 6
2 4
13
3
12 4
19 11 3 5
15 22 14
2
20
6 7 10 9 21
8
7
16 17 23 24
18
1. car chassis 1. soldering iron
2. gear motor 2. solder
3. gear motor 3. solder wick
4. tire wheel 4. Phillips-head screwdriver
5. tire wheel 5. needle nose pliers
6. Arduino UNO R3 6. wire stripper
7. L293D motor drive shield 7. breadboard or foam pad (optional)
8. HC-SR04 ultrasonic sensor
9. TowerPro SG90 servo motor
10. SG90 servo arms
11. mount for HC-SR04 and SG90 servo
12. wheel mounts
13. speed encoder
14. speed encoder
15. caster wheel
16. AA battery pack
17. AA batteries
18. rocker switch
19. screws, nuts, extender nuts
20. wires (make sure long enough!)
21. male headers
22. holder for HC-SR04
23. 9v battery (optional)
24. 9v battery power cord (optional)
Smart Robot Car: Page 3
3
1. Arduino IDE
2. USB cable A-male to B-male
3. computer
Step 2: Prepare Servo Mount
Peal off the protected paper from servo mount.
Secure servo to mount with 2 screws and 2 nuts.
Step 3: Prepare Ultrasonic Sensor Holder
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.
Smart Robot Car: Page 4
Step 4: Solder Header Pins to Motor Drive Shield
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.
Smart Robot Car: Page 5
1
1. Pin 2 header for interrupt
Step 5: Attach Motors to Chassis
Remove any connections from the ends of the wires motor.
to expose bare wire.
Tin the wire with solder and solder them to the motor Note: the speed encoders can be used in conjunction
terminals. with an optical sensor to determine how fast the
Slide the motor mounts through the chassis and wheels are spinning and/or how far the car has
secure each motor with 2 screws and 2 nuts. traveled, but that'll have to be another instructable.
Attach the speed encoders to the inside part of the
Smart Robot Car: Page 6
Step 6: Attach Caster Wheel to Chassis
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.
Smart Robot Car: Page 7
Step 7: Attach Wheels to Motors
Attach the tire wheels to the outside part of the motors.
Smart Robot Car: Page 8
Step 8: Attach Server and Ultrasonic Sensor to Chassis
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.
Smart Robot Car: Page 9
Step 9: Attach Arduino Uno and Motor Drive Shield to Chassis
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.
1. Attach screw and nut here
Smart Robot Car: Page 10
Step 10: Connect Servo and Ultrasonic Sensor to Motor Shield
There are dedicated servo pins on the motor drive attach 4 wire jumpers.
shield so attach the servo cord to "servo one" being Attach the opposite ends to the power, ground, A5,
sure the colors are brown, red, and orange for pins 1, and pin 2 headers soldered in from earlier.
2, and 3 respectively. The remaining pins can be used for future projects.
Bend the pins on the ultrasonic sensor so that they
are perpendicular to the back of the sensor and
1. Brown-red-orange
1. Ground-2-A5-Vcc
1 2 1
1. Vcc-ground 1. 2 (Echo)
2. A5 (Trig)
Smart Robot Car: Page 11
Step 11: Connect Motors to Motor Drive Shield
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
Step 12: Attach Battery Pack and Rocker Switch to Chassis
Secure the battery pack to the chassis with 2 screws and 2 nuts.
Snap the rocker switch into place with the terminals facing upwards.
Smart Robot Car: Page 12
Step 13: Connect Battery Pack and Switch to Motor Drive Shield
Cut the power (red) wire roughly in half so that we Optionally, a 9v batter can be used to power the
can solder it through the rocker switch. Arduino separately.
Attach the power wire from the switch and the ground Powering the Arduino separately will prevent any
from the battery pack to the power and ground voltage drops from resetting the Arduino code being
terminal on the motor drive shield. executed.
This will also power the Arduino. Similarly, the 9v battery could also be wired into the
Put 4AA batteries into the battery pack, hit the switch switch instead of the battery pack.
to the "on" position, and ensure that both the motor
shield and Arduino power indicator lights are
illuminated.
1. Power indication light lit
Smart Robot Car: Page 13
Step 14: Download Arduino IDE, Program Sketch, and Upload to Arduino Uno
Download the Arduino IDE for your operating get proper clearance.
system and architecture: Open up the program sketch in the IDE.
https://www.arduino.cc/en/Main/Software Download Under the "Tools" menu item, ensure that the board is
the program sketch: set to "Arduino/Genuino Uno" and that the port is your
https://github.com/rricklic/arduino.uctronics.robo... Arduino (eg: /dev/ttyACM0).
The code will have the car move forward at full speed Hit the check button to ensure the sketch compiles.
until it detects an obstacle. Hit the arrow button to upload the sketch to the
It will scan from 60 to 120 degrees in front and attached Arduino.
determine if it should back up and turn left or right.
Once done it will continue moving forward again at NOTE: If you are using a Linux distribution as your
full speed. operating system, you may need to set permissions
by adding your user to the "dialout" group:
How to upload program sketch to Arduino Uno: $ sudo usermod -a -G dialout $USER
Attach the USB cord to your computer and the other
end to the Arduino. Rebooting makes this change permanent.
You will likely need to remove the ultrasonic sensor to
Smart Robot Car: Page 14
1
1. check = compile
arrow = upload
Step 15: 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!
Smart Robot Car: Page 15