You are on page 1of 6

Page 236 Robotics with the Boe-Bot

Infrared Headlights

The infrared object detection system well build on the Boe-Bot is like a cars headlights in several respects. When the light from a cars headlights reflects off obstacles, your eyes detect the obstacles and your brain processes them and makes your body guide the car accordingly. The Boe-Bot uses infrared LEDs for headlights as shown in Figure 7-1. They emit infrared, and in some cases, the infrared reflects off objects and bounces back in the direction of the Boe-Bot. The eyes of the Boe-Bot are the infrared detectors. The infrared detectors send signals indicating whether or not they detect infrared reflected off an object. The brain of the Boe-Bot, the BASIC Stamp, makes decisions and operates the servo motors based on this sensor input.

Figure 7-1 Object Detection with IR Headlights

The IR detectors have built-in optical filters that allow very little light except the 980 nm infrared that we want to detect with its internal photodiode sensor. The infrared detector also has an electronic filter that only allows signals around 38.5 kHz to pass through. In other words, the detector is only looking for infrared thats flashing on and off 38,500 times per second. This prevents IR interference from common sources such as sunlight and indoor lighting. Sunlight is DC interference (0 Hz), and indoor lighting tends to flash on and off at either 100 or 120 Hz, depending on the main power source in the region. Since 120 Hz is outside the electronic filters 38.5 kHz band pass frequency, it is completely ignored by the IR detectors.

Chapter 7: Navigating with Infrared Headlights Page 237

Some fluorescent lights do generate signals that can be detected by the IR detectors. These lights can cause problems for your Boe-Bots infrared headlights. One of the things you will do in this chapter is develop an infrared interference sniffer that you can use to test the fluorescent lights near your Boe-Bot courses.

ACTIVITY #1: BUILDING AND TESTING THE IR PAIRS


In this activity, you will build and test the infrared transmitter/detector pairs.
Parts List:
1 2 3

Infrared detectors IR LEDs (clear case) IR LED shield assemblies Resistors - 220 (red-red-brown) (2) Resistors 1 k (brown-black-red)

(2) (2) (2) (2)

1 2 3

Figure 7-2 New Parts Used in this Chapter IR detector (top) IR LED (middle)
Flattened edge

Longer lead + +

IR LED shield assembly (bottom)

Building the IR Headlights

Insert the infrared LED into the shield assembly as shown in Figure 7-3. Make sure the LED snaps into the larger part of the housing. Snap the smaller part of the housing over the LED case and onto the larger part.

IR LED will snap in.

Figure 7-3 Snapping the IR LED into the Shield Assembly

Page 238 Robotics with the Boe-Bot

One IR pair (IR LED and detector) is mounted on each corner of the breadboard. Figure 7-4 shows the IR headlights circuit as a schematic and Figure 7-5 shows the circuit as a wiring diagram. Disconnect power from your board and servos. Build the circuit shown by the schematic in Figure 7-4, using the wiring diagram for your board in Figure 7-5 as a reference for parts placement.
Vdd P2 1 k P9 220 Vss P8 1 k IR LED P0 220 Vss Vss Vss Vdd IR LED

Figure 7-4 Left and Right IR Pairs

Left IR Pair

Right IR Pair

Watch your IR LED anodes and cathodes! Remember that the anode lead is the longer lead on an IR LED by convention, but that you need to check the LEDs plastic case to make sure. The cathode lead is the one near the flat spot on the case. In Figure 7-5, the anode lead of each IR LED connects to a 1 k resistor. The cathode lead plugs into the same breadboard row as an IR detectors center pin, and that row connects to Vss with a jumper wire.

Chapter 7: Navigating with Infrared Headlights Page 239

To Servos
15 14 Vdd 13 12
Red Black

To Servos

(916) 624-8333 Rev B www.parallax.com www.stampsinclass.com

X4

X5

Vdd

Vin

Vss

Vdd X3
P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0 X2

Vin

Vss

X3
P15 P14 P13 P12 P11 P10 P9 P8 P7 P6 P5 P4 P3 P2 P1 P0 X2

Figure 7-5 Wiring Diagrams for Infrared Emitter and Receiver Circuits
anode leads

anode leads

Board of Education (left) and HomeWork Board (right).

Board of Education
Rev C 2000-2003

HomeWork Board

Testing the IR Pairs Using the FREQOUT Trick

The FREQOUT command was designed mainly to synthesize audio tones. The actual range of the FREQOUT command is 1 to 32768 Hz. One interesting phenomenon of digitally synthesized tones is that they contain signals called harmonics. A harmonic is a higher frequency tone thats mixed in with the tone you want to hear. These tones are outside human abilities to detect sound, which tend to range from 20 Hz to 20 kHz. The harmonics generated by the FREQOUT command start at 32769 Hz and go upward. You can directly control these harmonics using Freq1 arguments above 32768. In this activity, you will use the command FREQOUT 8, 1, 38500 to send a 38.5 kHz harmonic that lasts 1 ms to P8. The infrared LED circuit connected to P8 will broadcast this harmonic. If the infrared light is reflected back to the Boe-Bot by an object in its path, the infrared detector will send the BASIC Stamp a signal to let it know that the reflected infrared light was detected.

Page 240 Robotics with the Boe-Bot

FREQOUT Command - Fundamentals and Harmonics


The fundamental frequency is the value of the Freq1 argument when its at or below 32768. For example, when you use the command FREQOUT 4, 2000, 3000, the fundamental frequency is 3000 Hz. That's the intended sound, but there is also a harmonic sound that accompanies it. This harmonic is a much higher frequency that the human ear can detect, in the neighborhood of 62.5 kHz. Here's how to calculate the harmonic frequency given the fundamental and visa versa. Whenever you use the FREQOUT command to send a tone in this range, it contains that hidden (harmonic) tone as well. The equation for the harmonic is: harmonic frequency = 65536 Freq1, Freq1 <= 32678

Whenever you use the FREQOUT command with a Freq1 argument above 32768 to send a harmonic, it contains a fundamental tone. The equation for the fundamental is: fundamental frequency = 65536 Freq1, Freq1 > 32768

The key to making each IR LED/detector pair work is to send 1 ms of 38.5 kHz FREQOUT harmonic, and then, immediately store the IR detectors output in a variable. Here is an example that sends the 38.5 kHz signal to the IR LED connected to P8, then stores the IR detectors output, which is connected to P9, in a bit variable named irDetectLeft.
FREQOUT 8, 1, 38500 irDetectLeft = IN9

The IR detectors output state when it sees no IR signal is high. When the IR detector sees the 38500 Hz harmonic reflected by an object, its output is low. The IR detectors output only stays low for a fraction of a millisecond after the FREQOUT command is done sending the harmonic, so its essential to store the IR detectors output in a variable immediately after sending the FREQOUT command. The value stored by the variable can then be displayed in the Debug Terminal or used for navigation decisions by the Boe-Bot.
Example Program: TestLeftIrPair.bs2

Reconnect power to your board. Enter, save, and run TestLeftIrPair.bs2.

' Robotics with the Boe-Bot - TestLeftIrPair.bs2 ' Test IR object detection circuits, IR LED connected to P8 and detector ' connected to P9. ' {$STAMP BS2}

Chapter 7: Navigating with Infrared Headlights Page 241

' {$PBASIC 2.5} irDetectLeft DO FREQOUT 8, 1, 38500 irDetectLeft = IN9 DEBUG HOME, "irDetectLeft = ", BIN1 irDetectLeft PAUSE 100 LOOP VAR Bit

Leave the Boe-Bot connected to the serial cable, because you will be using the Debug Terminal to test your IR pair. Place an object, such as your hand or a sheet of paper, about an inch from the left IR pair, in the manner shown in Figure 7-1 on page 236. Verify that when you place an object in front of the IR pair the Debug Terminal displays a 0, and when you remove the object from in front of the IR pair, it displays a 1. If the Debug Terminal displays the expected values for object not detected (1) and object detected (0), move on to the Your Turn section following the example program. If the Debug Terminal does not display the expected values, try the steps in the Trouble-Shooting box.
Trouble-Shooting If the Debug Terminal does not display the expected values, check for circuit and program entry errors. If you are always getting 0, even when an object is not placed in front of the Boe-Bot, there may be a nearby object that is reflecting the infrared. The surface of the table in front of the Boe-Bot is a common culprit. Move the Boe-Bot so that the IR LED and detector cannot possibly be reflecting off any nearby object. If the reading is 1 most of the time when there is no object in front of the Boe-Bot, but flickers to 0 occasionally, it may mean you have interference from a nearby fluorescent light. Turn off any nearby fluorescent lights and repeat your tests.

Your Turn

Save TestLeftIrPair.bs2 as TestRightIrPair.bs2.

You might also like