A simple robot meant to endlessly avoid obstacles in its path.
The robot uses the ultrasonic sensors to "see" in front of it (~120 degrees combined). If the sensors notice something near them (~12in away), the robot turns left, right, or reverses depending on where the object is. This continues until either you turn it off, or the battery runs out. See the comments in the code for the specific functional details.
Note: The ultrasonic sensors work by bouncing a high frequency (40kHz) pulse of off anything in front of it, then converting the time it takes for the pulse to return (Time of Flight) into distance. Consequently, if the object is at an angle from the sensor, them the sensor is effectively blind to it. Additionally, If the object is below or above the sensor's "viewing" range (~30 degrees per sensor), the sensor will not notice it either... so, obstacle avoidance...within reason.
- Arduino Mega - The brains of the robot
- Ultrasonic Sensors (3) - Used for sensing obstacles
- Sensor Mounts (3) - To hold the ultrasonic sensors
- Motor Driver - Controls the DC motors
- Cheap Chassis - The robot's body
- 7.4v LiPo battery - To power the whole thing
- Toggle switch - To turn it ON/OFF
- Mini breadboard - To power all the peripherals from the same source
Warning: This motor driver has a 5v regular output that I use to power the ultrasonic sensors via the mini breadboard. In case you don't use this motor driver, you will need to find a different way to regulate the power going into the sensors.
Since this mini project was made out of spare parts from other projects, the items listed above might be overkill.
The Uno has 4 PWM pins and 8 other digital pins (along with 6 analog pins that can also be used as digital pins). You need 4 PWM pins to drive the L298 motor driver at a user defined speed. Alternatively, you can always use digital pins and have to robot running at full speed. Though, you might have to mess with the distance threshold based on the kind of sensor response you get while running at full speed.
Since the DC motors are working as pairs (left-side motors and right-side motors), you can simply connect two motors per side on the motor driver. Allowing you to drive the robot with 4 pins rather than 8.
This motor driver does have a 5v regulator already connected to the enable pins, so, you could use one of those 5v pins to provide power to the ultrasonic sensors, but you have to make sure to also power the enable pin if you want both sides of the motor driver to work.