circuit_1.jpg (192514Bytes)
I am making a robot using arduino and i need an easy object avoidance code
Here is what i found:
#include "URMSerial.h"
#include <Servo.h>
Servo lservo;
Servo rservo;
// The measurement we're taking
#define DISTANCE 1
#define TEMPERATURE 2
#define ERROR 3
#define NOTREADY 4
int ledPin = 13;
URMSerial urm;
void setup() {
Serial.begin(9600); // Sets the baud rate to 9600
urm.begin(2,3,9600); // RX Pin, TX Pin, Baud Rate
pinMode(ledPin, OUTPUT);
lservo.attach(9); // attaches the servo on pin 9 to the servo object
rservo.attach(10); // attaches the servo on pin 10 to the servo object
}
void loop()
{
// Request a distance reading from the URM37
urm.requestMeasurement(DISTANCE); // You may call this as many times as you like. It will only send once
// Avoid fetching the distance until we're sure the reading is ready
if(urm.hasReading())
{
int value; // This value will be populated
switch(urm.getMeasurement(value)) // Find out the type of request
{
case DISTANCE: // Double check the reading we recieve is of DISTANCE type
Serial.println(value); // Fetch the distance in centimeters from the URM37
if (value < 25) // Less than 25cms turn, else carry on.
{
digitalWrite(ledPin, HIGH);
lservo.write(110);
rservo.write(110);
}
else
{
digitalWrite(ledPin, LOW);
lservo.write(110);
rservo.write(50);
}
delay(200);
break;
}
}
}
But it wont work! can anybody modify the code? please
There is a pic of the wireing i am using