Datasheet

Navigating with Infrared Headlights • Chapter 7
Robotics with the BOE Shield-Bot 221
Object Detection Test Code
Your BOE Shield-Bot’s infrared receivers are designed to detect infrared light (in the 980
nanometer range) flashing at a rate near 38 kHz. To make the IR LED turn on/off at that
rate, we can use the familiar
tone function that makes the speaker beep at the beginning of
each sketch.
Infrared detection takes three steps:
1. Flash the IR LED on/off at 38 kHz.
2. Delay for a millisecond or more to give the IR receiver time to send a low signal in
response to sensing 38 kHz IR light reflecting off an object.
3. Check the state of the IR receiver for either a high signal (no IR detected), or a
low signal (IR detected).
Here is an example of the three steps applied to the left IR LED (pin 9) and IR receiver (pin
10).
tone(9, 38000, 8); // IRLED 38 kHz for at least 1 ms
delay(1); // Wait 1 ms
int ir = digitalRead(10); // IR receiver -> ir variable
anode
(+) lead
Left
Right
anode
(+) lead