You might have found that your BOE Shield-Bot said it detected something even though nothing was in range. That may mean a nearby light is generating some IR light at a frequency close to 38.5 kHz. It might also mean that direct sunlight streaming through a window is causing false detections. If you try to have a BOE Shield-Bot contest or demonstration near one of these light sources, your infrared systems could end up performing very poorly! So, before any public demo, make sure to check the prospective navigation area with this IR interference “sniffer” sketch ahead of time.
The concept behind this sketch is simple: don’t transmit any IR through the IR LEDs, just monitor to see if any IR is detected. If IR is detected, sound the alarm using the piezospeaker.
You can use a handheld remote for just about any piece of equipment to generate IR interference.
TVs, VCRs, CD/DVD players, and projectors all use the same type of IR detectors you have on your BOE Shield-Bot right now. So, the remotes you use to control these devices all use the same kind of IR LED that’s on your BOE Shield-Bot to transmit messages to your TV, VCR, CD/DVD player, etc. All you’ll have to do to generate IR interference is point the remote at your BOE Shield-Bot and repeatedly press/release one of the remote’s buttons.
With this sketch, your BOE Shield-Bot should play a tone, turn on its indicator LEDs, and display a warning in the Serial Monitor any time it detects infrared. Again, since it’s not transmitting any IR, it means the 38 kHz infrared has to be coming from an outside source.
/* * Robotics with the BOE Shield - IrInterferenceSniffer * Test for external sources of infrared interference. If IR interference is * detected: Serial Monitor displays warning, piezospeaker plays alarm, and * indicator lights flash. */ void setup() // Built-in initialization block { tone(4, 3000, 1000); // Play tone for 1 second delay(1000); // Delay to finish tone pinMode(10, INPUT); // Left IR Receiver pinMode(3, INPUT); // Right IR Receiver pinMode(8, OUTPUT); // Left indicator LED pinMode(7, OUTPUT); // Right indicator LED Serial.begin(9600); // Set data rate to 9600 bps } void loop() // Main loop auto-repeats { int irLeft = digitalRead(10); // Check for IR on left int irRight = digitalRead(3); // Check for IR on right if((irLeft == 0) || (irRight == 0)) // If left OR right detects { Serial.println("IR interference!!!"); // Display warning for(int i = 0; i < 5; i++) // Repeat 5 times { digitalWrite(7, HIGH); // Turn indicator LEDs on digitalWrite(8, HIGH); tone(4, 4000, 10); // Sound alarm tone delay(20); // 10 ms tone, 10 between tones digitalWrite(7, LOW); // Turn indicator LEDs off digitalWrite(8, LOW); } } }
Always use this IrInterferenceSniffer to make sure that any area where you are using the BOE Shield-Bot is free of infrared interference.