Simple Robot
I had a gh-311rt ultrasonic sensor which did not have a datasheet. So i ran it with a ping))) program. You can easily try it with the cheapest 3 pin sensor . No need to go after ping)))
Get the Stuff
here is what you need.
1x Gh 311-rt sensor (if you have ping))) use it.If you have hc sr04 modulate the code) from here.
2x BO motors (75 rpm)
1x motor driver module. over here.(i used a motor driver if you want to reduce it use servomotors modified for 360)
1x Chassis set here (i scavenged one from one kit)
1x Arduino uno (it is awesome)
1x programming cable
wires
2x batteries (i suggest duracell enercell or one from radioshack)
croc clips
now begin
Assembly
start with the caster.
now mount the motors.
mount those gigantic nut like things as shown.
now mount the motor driver on the supposedly top plate (identified with more screw holes).
and the awesome arduino on the other side of the same plate.
Motor Driver
here are the connections.
motor1 + to the m1 output lead screw tab number 1
motor1 - t the m1 output lead
same are followed on the other side.
if the motors donot move in the wanted direction just change the leads on the arduino. On the arduino.!!!
Arduino Connection
now connect the m1 enable + lead to pin 2 on the arduino and the - lead to pin 4.
then m2 enable + to pin 7 on arduino and - to pin 8 on the arduino.
Ultrasonic
mount the ultrasonic sensor as shown ,on the bottom plate.
here are the connections,
vcc or + to 5v
gnd or - to gnd
output to pin 12 on arduino.
Finishing Touch
get it together (chassis) leave a wire on the motor drivers power pins positioned behind and here is the program.
//this is a code for controlling a simple robot using an arduino and a motor driver.
//created by robobot3112
const int loopPeriod = 20;
unsigned long loopdelay = 0;
const int sensor = 12; // ARDUINO OUTPUT PIN FOR SENSOR INPUT/OUTPUT
const int p1 = 8; // ARDUINO OUTPUT PIN FOR MOTOR INPUTS
const int p2 = 7; // ARDUINO OUTPUT PIN FOR MOTOR INPUTS
const int p3 = 4; // ARDUINO OUTPUT PIN FOR MOTOR INPUTS
const int p4 = 2; // ARDUINO OUTPUT PIN FOR MOTOR INPUTS int ultraDistance;
int ultraDuration;
void setup()
{
Serial.begin(9600);
pinMode(p1 , OUTPUT);
pinMode(p2 , OUTPUT);
pinMode(p3 , OUTPUT);
pinMode(p4 , OUTPUT); }
void loop()
{
if(millis() - loopdelay >= loopPeriod)
{
readUltrasonicSensors();
motorstate();
loopdelay = millis();
}
}
void readUltrasonicSensors()
{
pinMode(sensor , OUTPUT);
digitalWrite(sensor , LOW);
delay(2);
digitalWrite(sensor , HIGH);
delayMicroseconds(10);
digitalWrite(sensor , LOW);
pinMode(sensor , INPUT);
ultraDuration = pulseIn(sensor , HIGH);
ultraDistance = (ultraDuration/2)/29;
}
void motorstate() // MOTOR CONTROL FUNCTION
{
if((ultraDistance > 15)||(ultraDistance < 0))
{
digitalWrite(p3 , HIGH);
digitalWrite(p1 , HIGH);
digitalWrite(p2 , LOW);
digitalWrite(p4 ,LOW); }
else
{
digitalWrite(p1 , HIGH);
digitalWrite(p2 , LOW);
digitalWrite(p3 , HIGH);
digitalWrite(p4 , LOW);
}
}
Finished Is Your Robot
let me hope your robot worked well.
if you face any problem let me know :)
the end
Let There Be Lifeeeeee!
To power this beast you require 2 9v batteries (1 for motor driver and other for the Arduino).