-
1Step 1
attach the servo's to the chassie and feed the servo wires through the slots at the back of the frame.
-
2Step 2
Using standoffs mount the arduino to the frame. My Arduino was in a holder but you can mount the Arduino directly to the frame if you dont have the holder.
-
3Step 3
Add the proto shield to the Arduino
-
4Step 4
Connect the servo wires. 3 wires, VCC,GND and control
-
5Step 5
Add the ultrasonic sensor to the proto board.
-
6Step 6
I added my battery box 4xAA under the Arduino frame. You can do whatever works for your power source. 9v Batter or a USB battery extender will work as well. Its a little tight but I used a rubber band around the frame to pull it down and level.
-
7Step 7
Here is the hook up diagram. Servo pwm pin to Arduino pins 6 and 7 and ultrasonic device to pin 5. Which server goes to what pin really doesnt matter. It just only impacts if the robot turns left or right when an object is found.
You also need to connect up your VCC and group to the server's and the untrasonic detector
-
8Step 8
Software, Simple basic go forward until your near and object then turn left and try again. Code fragments have been taken from a number of online reference.
#include <Servo.h> //include Servo library
const int RForward = 0;
const int RBackward = 180;
const int LForward = RBackward;
const int LBackward = RForward;
const int RNeutral = 90;
const int LNeutral = 90;
const int pingPin = 5;
const int dangerThresh = 10;
Servo leftMotor;
Servo rightMotor; //declare motors
long duration;
void setup()
{
rightMotor.attach(6);
leftMotor.attach(7);
}
void loop()
{
int distanceFwd = ping();
if (distanceFwd>dangerThresh) //clear path
{
//go fowards
leftMotor.write(LForward);
rightMotor.write(RForward);
delay(500);
}
else
{
//blocked turn a little and try again.
leftMotor.write(LNeutral);
rightMotor.write(RNeutral);
delay(1000);
}
}
long ping()
{
// Send out PING))) signal pulse
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
//Get duration it takes to receive echo
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
//Convert duration into distance
return duration / 29 / 2;
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.