Datasheet

Navigating with Infrared Headlights • Chapter 7
Robotics with the BOE Shield-Bot 233
return ir;
}
3. Replace these digitalRead calls:
byte wLeft = digitalRead(5);
byte wRight = digitalRead(7);
4. …with these calls to irDetect:
int irLeft = irDetect(9, 10, 38000);
int irRight = irDetect(2, 3, 38000);
5. Replace all instances of wLeft with irLeft and wRight with irRight.
6. Update the
/*…*/ and // comments.
Example Sketch RoamingWithIr
Open RoamingWithWhiskers.
Save it as RoamingWithIr.
Modify it so that it matches the sketch below.
Save the sketch and run it on the Arduino.
Disconnect the BOE Shield-Bot from its programming cable.
Reconnect the battery pack and move the 3-position switch to position 2.
Place your BOE Shield-Bot somewhere where it can roam and avoid obstacles.
Verify that it behaves like RoamingWithWhiskers (aside from the fact that there’s
no contact required).
/*
* Robotics with the BOE Shield - RoamingWithIr
* Adaptation of RoamingWithWhiskers with IR object detection instead of
* contact switches.
*/
#include <Servo.h> // Include servo library
Servo servoLeft; // Declare left and right servos
Servo servoRight;
void setup() // Built-in initialization block
{
pinMode(10, INPUT); pinMode(9, OUTPUT); // Left IR LED & Receiver
pinMode(3, INPUT); pinMode(2, OUTPUT); // Right IR LED & Receiver