Arduino Bread Bot (w/ simple IR avoidence)

Hi, I’m new to arduino but recently picked up a freeduino from active-robots.co.uk. This is the early stage of an autonomous rover I’m working on.

I came across a few forum posts like this one > http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1281824714/all < and decided to document a more concerted effort.

I started flashing LEDs by following the tutorial over at http://www.ladyada.net/learn/arduino and continued until I ran out of the necessary components, then I moved on to the Knob tutorial here at http://arduino.cc/en/Tutorial/Knob. after that on to the servo library tutorial http://arduino.cc/en/Reference/ServoWriteMicroseconds before exploring writeMicroseconds() function and hacking together some code for the continuous rotation servo. After that I googled “arduino sharp ir sensors” and came across this page http://luckylarry.co.uk/arduino-projects/arduino-using-a-sharp-ir-sensor-for-distance-calculation/.

I ran the code as it appeared and used a ruler to determining values, then it was just a matter or merging the pieces (usually the hardest part for me), this is the first working sketch and its ruff.

// really simple Autonomous IRroaming
// by sub www.80sbaby.co.uk

#include <Servo.h>
 
Servo left;            // creates servo object called 'left' to control a servo
Servo right;          // creates servo object called 'right' to control a servo
int IRpin = 1;       // IR sensor attached to analog pin 1
int distance;       // int to store'distance' value from the sensor
int move = 0;      // dont think this is needed but Im sticking to a format at the moment 

void setup()
{
  left.attach(9);     // attaches the servo on pin 9 to the servo object
  right.attach(10);  // attaches the servo on pin 10 to the servo object
} 
 
void loop()
{   
  
    float volts = analogRead(IRpin)*0.0048828125;   // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
    float distance = 65*pow(volts, -1.10);          // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
    Serial.println(distance);                       // print the distance
  
    delay(100);
      if (distance <= 75.00) {
        move = 1;
        left.writeMicroseconds(1510);              // tell servos to go to position (stop)
        right.writeMicroseconds(1500); 
        delay(500);
        left.writeMicroseconds(1500);              // tell servos to go to position (left)
        right.writeMicroseconds(1000); 
        delay(1000);  
                                 
     } else {
        move = 0;        
        left.writeMicroseconds(2000);              // tell servos to go to position (forward)
        right.writeMicroseconds(1000); 
        delay(10);
     }
}

so far the program is basically an if statement that follows an IR scan. if distance is less than the given value stop and turn left, else go forward.

[example of autonomous roaming with the ultra simple c sketch I’ve written. the program contains an analogue read of the IR pin at the start of the loop storing a value for distance, then a single if statement decides the movement.]

I’m incorporating a few changes already, the bot now stops, goes backwards a moment then turn left. I have another parallax servo that I’m going to use for rotating the sensor, once mounted I’ll start working on some more sophisticated manoeuvres.


IMG00047-20101129-0444 by sub@icebox, on Flickr


IMG00049-20101129-0454 by sub@icebox, on Flickr

As someone who's just about to start exactly that project, I appreciate the effort you went through to post this. Thanks.

+1 Will be doing this in January after I get my LED cube into a housing.

Thank you for the feedback I really appreciate it.

I know its not a how to, but I've cited every source I used in getting from flashing the LED on pin 13 to understanding the IR sensor code in the sketch. I'm confident anyone with the materials could re create and understand the above.

Thanks to anyone reading and I hope to contribute a lot more to the community.