BOB3 has a purple IR-sender-LED and a black IR-phototransistor.
The sender LED sends an IR light. This light is then reflected from objects nearby and received by the phototransistor:
Depending on how near, e.g. you hold your hand in front of the sensors, the phototransistor receives more or less IR light.
We can retrieve this value by calling the method
In line 10 we ask the phototransistor how much IR light is being received at the moment:
This value is going to be stored in the variable
int irValue = bob3.getIRSensor();
In lines 13 to 17 we're going to programme BOBs reaction depending on the sensor's value:
If the value is larger than 8
if (irValue > 8)
i.e. an object is near the sensor,
then both eyes should light up red:
the objects are farther away,
then both eyes should be off:
If everything worked, then BOB3 should react to the distance of your hand, for example. If it doesn't work well, try it with a white piece of paper.
Tip: Remember to set the jumper to ON if BOBs helmet isn't on!
„Help! It's not working...“
What happens if you change the value in line 13 from 8 to 2 ?