In this activity, you will build infrared object detector circuits on the cyber:bot robot's breadboard.
Parts List
(2) IR receivers
(2) IR LEDs (clear case)
(2) IR LED shield assemblies
(2) Resistors, 220 Ω (red-red-brown)
(2) Resistors, 2 kΩ (red-black-red)
(misc) Jumper wires
Gather the parts in the Parts List, using the drawings below to help identify the infrared receivers, LEDs, and shield assembly parts.
Make sure you are using infrared LEDs and not phototransistors. The infrared LED has a taller and more rounded plastic dome:
The infrared LEDs are designed to sit in the standoff tubes a certain way. The flat spot on the LED dome matches a flat ledge inside the tube. Holes on the bottom of the tube are labeled for the anode (+) and cathode (-) leads.
Each IR object detector requires its own IR LED and IR receiver, mounted together on a corner of the breadboard closest to the very front of the cyber:bot.
Note that the anode lead of each IR LED connects to a 2 kΩ resistor (red-black-red). Also note that each IR LED and each IR receiver has its own ground connection wire. In the diagram, the IR LED ground wires are shown in blue to help tell them apart.
Watch your IR LED anodes and cathodes!
The anode lead is the longer lead on an IR LED by convention. The cathode lead is shorter and mounted in the plastic case closer to its flat spot. These are the same conventions as the red LEDs in the kit.
Object detection with the IR LED and receiver circuits you built on your cyber:bot takes three steps:
The function ir_detect handles all of these steps for us. Here is an example from our next script:
The ir_detect function generates a square wave on the IR LED pin; here the arguments specify a 37500 Hz signal on P14. This square wave last about 2 milliseconds. Then, the function checks the state of the IR receiver pin; P13 in this example, and stores the result in the variable irL. The state of the IR receiver pin. IR receiver detects a reflection of the 37500 Hz infrared light signal, irL will store a zero, and if not, irL will store a 1— remember that this receiver is an "active low" sensor.
This script only tests the cyber:bot’s left IR detector. Focusing on only one of the two object detector circuits at a time helps simplify trouble-shooting. This is yet another example of subsystem testing. After the subsystems check out, we can move to system integration. But first, let's make sure to test and correct any wiring or code entry errors that might have crept in.
#test_left_IR from cyberbot import * while True: irL = bot(14, 13).ir_detect(37500) bot(20).write_digital(irL)
Once the script is fully flashed and running, the cyber:bot board, the LED labeled P20 should come on.
Now it is time to modify the script to test the right-side object detector.
#test_both_IR_indicators from cyberbot import * bot(22).tone(3000, 1000) while True: irL = bot(14, 13).ir_detect(37500) irR = bot(1, 2).ir_detect(37500) bot(20).write_digital(irL) bot(21).write_digital(irR)