Let's Make Robots!

My alternative to the SHR

kingkong95's picture
Avoid (most) objects

After several half complete robot projects (see that tank/mess of wires in the background?) and lots of experimentation I thought I should probably actually finish a robot and get it posted on here, so here it is!

Basically this is just a not that great version of the start here robot.. only it's using an arduino, a massive 7.2v 4700 mah battery and a cheap IR detector for sensors. Here's a more detailed description:

To begin with I started with my collection of parts, so I already had all the electronic components I needed :D That is: two continuous servo's, two IR LED's, my arduino duemilanove, a 38khz IR receiver and a tamiya RC battery - all ready to use!

Then I needed a chassis for the robot, and I already wanted an excuse to test out a laser cutting service I had found, so I sent off some very (very) basic plans I drew up in Inkscape. I actually made the chassis a while ago, I just never got round to using it until now :P The service was actually quite good, it takes a couple of weeks for them to process your order and there isn't a great deal of materials to choose from, but it allowed me to use my own design at the fairly reasonable cost of around £10. :)

The circuit is quite simple, it's just two IR LED's in series connected to PWM pin 11, an IR receiver connected to pin 5, two servo's in Pins 10 and 11, and a notification LED in 13. Thanks to Ro-Bot-X for his tutorial on that, although I actually used some other code I found on here somewhere for oscillating the LED at 38khz and merged the two together :)

Here is the code:

 

#define IR_CLOCK_RATE    38000L
#define pwmPin 11
#define IRsensorPin 5
#define D13ledPin 13 
#include <Servo.h>

Servo left;
Servo right;

void setup()  {
  
  right.attach(10);
  left.attach(9);

  TCCR2A = _BV(WGM21) | _BV(COM2A0);
  TCCR2B = _BV(CS20);
  OCR2A = (F_CPU/(IR_CLOCK_RATE*2L)-1);
  pinMode(pwmPin, OUTPUT);
  
  pinMode(D13ledPin, OUTPUT);
  digitalWrite(D13ledPin, LOW);
  
}

void loop() 
{
  
  if (digitalRead(IRsensorPin)==LOW){
    
    digitalWrite(D13ledPin, HIGH);
    Backwards();
    delay(1000);
    Left();
    delay(1000);
    
  } else {
    
    digitalWrite(D13ledPin, LOW);
    Forwards();
    
  }
  delay(100);
}

void Forwards ()
{
  left.write(10);
  right.write(170);
}

void Backwards ()
{
  left.write(170);
  right.write(10);
}

void Left ()
{
  left.write(80);
  right.write(170);
}

void Right ()
{
  left.write(10);
  right.write(100);
}

void Stop ()
{
  left.write(90);
  right.write(90);
}

Lessons learnt from this project:

  1. Use a ball caster with a radius greater than the thickness of the carpet and one that doesn't hook onto everything
  2. Use sensors nearer to ground level - there's a blind spot almost as long as their detection threshold
  3. RC batteries are great! I don't know how much current these servo's draw, but even if it's 500 mah each that's around 4.5 hours of running time for 4.5 hours of charging :D

Anyway, now onto my next project.. I'm thinking I'll add some autonmous controls to my rc buggy (heavily inspired by some of frits' stuff). The tank in the back of the photo there can be fixed another day :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Ro-Bot-X's picture

Nice robot! I'm glad you used the simple IR receiver sensor!

Before I started to use Arduino, I programmed the ATmega8 in Bascom-AVR. There, I was using the Timers to generate the frequency for the IR LEDs. I tried with Timer2 and with Timer1. On Arduino I needed the Timers for other stuff and I realized that light is fast and the LED pulses for only a few miliseconds. So I was happy to just generate the pulses in the code. But yeah, for the record, it can be done this way too. Thanks for reminding me and showing others how can be done.

kingkong95's picture

Thanks! I was originally going to use your code all the way through but for some reason the LED is constantly lit, as though the receiver is always low? I expect it's just hardware error on my part somewhere though.

David Schwarz's picture

I like rc batteries too, 3700mah is a big battery for this.

Laser Cutters are nice - I use my high school's one.

Not quite shure what this is for?

char i;
  for(i='A'; i<='Z'; i++)
  {
    Serial.print(i);
  }
  delay(40);
kingkong95's picture

Yeah they are very useful things. I actually typed the wrong thing, it's a 4700 mah batery, so yeah probably is a bit too big for this robot really! But seeing as it's all I had and lasts for ever I thought I might as well use it :D

Ermm, to be honest I'm not really sure! It was part of the 38khz LED code, which I didn't fully understand, so I left it in. It turns out that it works without it though so I'll change that now.