This tutorial is the second part of the Arduino Robot project, here is a quick reminder of the first part. This part will focus on the hardware and software assuming you already followed the first part and assembled the robot.
As always, I’ll start with the final Robot just to keep you focused
So our goal is to make this robot drive while avoiding obstacles ahead. Remember that last time I showed how to connect the motors to the motor shield. Now I’m going to show how to connect the servo motor and the ultrasonic sensor and operate them. After I will have all the parts connected, I’ll write the Arduino board code which will start navigating the robot.
This Tutorial Includes The Following
- Connecting the Servo Motor to the breadboard
- Connecting the Ultrasonic Sensor to the breadboard
- Writing the navigation algorithm
Connecting the Servo Motor
A servo motor has 3 wires:
- 5V – usually red
- GND – usually black
- Signal – usually white
In order to connect the Servo motor, we need to extend the protoshield output pins into the breadboard, and then connect the motor wires.
Find the 5V pin and the GND pin on the Arduino protoshield, connect a wire to each one of them and connect the other side of the wires to separate rows on the breadboard. The breadboard is useful for connecting many electronics on a single board. Now make sure the 5V and the GND of the Servo motor are connected to the 5V and GND of the protoshield. The signal pin should be connected the same way, I connected it the pin 10 (pins 8, 11, 13, 9, 3, 12 are saved for the motor shield so you shouldn’t use them).
Connecting the Ultrasonic Sensor
Like the servo motor, the Ultrasonic sensor has 3 wires:
- 5V – usually red
- GND – usually black
- Signal – usually white
Connect the wires from the sensor into the breadboard the same way we did with the motor. Make sure you choose a signal pin which is not already being used. I chose pin 7.
At this point, you should have the robot like in the image, but without his brain. Let’s start writing some code, you can Ctrl+C Ctrl+V the entire code to your Arduino IDE and it should work perfectly (assuming you connected the signal pins the same I did).
I’m using the Arduino IDE 1.0.6 under Ubuntu 14.04 machine.
Download code from GitHub
The Navigation Algorithm
Cheers