Introduction: Smart Robot Car
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.
Step 1: Gather Materials and Tools
- 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
- extender nuts
- male headers
- 4 AA batteries
- 9v battery (optional)
- 9v battery power cord (optional)
- soldering iron (Weller WLC100)
- silver bearing solder
- solder wick
- Phillips-head screwdriver
- needle nose pliers
- wire stripper
- breadboard or foam pad (optional)
- multimeter (optional)
- Arduino IDE
- USB cable A-male to B-male
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.
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.
Step 5: Attach Motors to Chassis
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.
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.
Step 7: Attach Wheels to Motors
Attach the tire wheels to the outside part of the motors.
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.
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.
Step 10: Connect Servo and Ultrasonic Sensor to Motor Shield
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.
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.
Step 13: Connect Battery Pack and Switch to Motor Drive Shield
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.
Step 14: Download Arduino IDE, Program Sketch, and Upload to Arduino Uno
Download the Arduino IDE for your operating system and architecture:
Download the program sketch:
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.
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!
1 Person Made This Project!
- loulou15000 made it!