Microbot Infrared Object Sensor

Microbot Infrared Object Sensor

posted in: MicrobotFirmware | 0

Fullscreen capture 7242015 33644 PM

The following defines are for the IR_LEDs, and the IR_SENSORs .

#define IR_LED_R 1 // IR LED Left used for reflective wall sensing
#define IR_LED_L 7 // IR LED Left used for reflective wall sensing
#define IR_38Khz 3 // IR LED 38khz Cathode connection

#define IR_SENSOR_R 15 // Right input from 38khz bandpass filter connected to IR PIN diode radio
#define IR_SENSOR_L 16 //

#define WALL_DETECTED 0 // Wall detected
#define WALL_NOT_DETECTED 1 // Wall not detected

The following sets the IR_LEDs to be outputs.

pinMode(IR_LED_R, OUTPUT);// sets the digital pin as output
pinMode(IR_LED_L, OUTPUT);

pinMode(IR_38Khz, OUTPUT);

digitalWrite(IR_LED_R, 1); // 0 = off
digitalWrite(IR_LED_L, 1); // 0 = off
digitalWrite(IR_38Khz, 0);

pinMode(IR_SENSOR_R, INPUT);
pinMode(IR_SENSOR_L, INPUT);

The following code checks is the IR_LEDs are sensing the wall, and telling it what to do if the statement is true or false.

digitalWrite(LED_B, digitalRead(IR_SENSOR_L)); // Set the Blue LED to turn ON when the Left IR sensor sees a wall

if (digitalRead(IR_SENSOR_R) == WALL_DETECTED) // this if statement does the same thing as the above lines but is written with an IF statement
{
digitalWrite(LED_G, LED_ON); // Turn ON the Green LED
}
else
{
digitalWrite(LED_G, LED_OFF); // Turn OFF the Green LED
}

 

Leave a Reply