Saturday, March 31, 2012

First object avoidance test.

This short video demonstrates the first attempt at object avoidance using IR. It seems to partly work in that it will detect objects in motion, but it won't detect an object that its moving towards. The IR emitter was removed from an old remote and the IR receiver module was pulled from an old appliance. The receiver works on a 38Khz - 40Khz carrier which is modulated via a command code specific to the device.

Timer2 on the Arduino was set to run at 40Khz continuous. I tried modulating the carrier to simulate the output from a commercial remote and tried the Arduino IR library but couldn't seem to get it to detect stationary objects. It would seem that IR receivers designed for remote control application are suitable for use in detecting objects - party because it does not indicate distance, it presents only TTL output.

There are IR sets out there that do provide output proportional to distance from object and these would obviously work well in this application. The other object of this test was to try out the L298 dual bi-directional motor controller module (H-bridge). It works very well and is easy to use.


img src - http://www.ebay.com.au/itm/280714490010?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649


So, my plan to build an army of evil robots to help take over the world will have to wait a little longer......:)





The code for this test is very simple:

#define MOTOR_OFF B00000000;
#define MOTOR_FWD B10010000;
#define MOTOR_REV B01100000;
#define MOTOR_LFT B10100000;
#define MOTOR_RHT B01010000;

int sensorPin = 2;
int sensorValue = LOW;
int irON = false;


void startIR() {
TCCR2A = _BV(COM2A0) | _BV(WGM21) | _BV(WGM20);
TCCR2B = _BV(WGM22) | _BV(CS20);
OCR2A = B11000111;
}

void stopIR() {
TCCR2A = 0;
TCCR2B = 0;
}

void setup() {
pinMode(11, OUTPUT);
pinMode(sensorPin,INPUT);
PORTD = MOTOR_OFF;
delay(500);
PORTD = MOTOR_FWD;
startIR();
Serial.begin(9600);

}


void loop() {
sensorValue = digitalRead(sensorPin);

if(sensorValue == LOW) {
Serial.println(sensorValue);
PORTD = MOTOR_OFF;
delay(500);
PORTD = MOTOR_LFT;
delay(1000);
PORTD = MOTOR_OFF;
delay(125);
PORTD = MOTOR_FWD;
delay(125);

}

}

No comments:

Post a Comment