Loading...

IR-sensor part 1

__info__

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:

__info__

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 bob3.getIRSensor();.

__info__

In line 10 we ask the phototransistor how much IR light is being received at the moment:
bob3.getIRSensor();

This value is going to be stored in the variable irValue:
int irValue = bob3.getIRSensor();

__info__

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:
bob3.setEyes(RED, RED);

If not
else
the objects are farther away,

then both eyes should be off:
bob3.setEyes(OFF, OFF);

__task__

Try the program on your BOB3!


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...“

__task__

What happens if you change the value in line 13 from 8 to 2 ?

Test it out!





__quiz__

1: What happens if you change the ">" to a "<" in line 13? 
 You haven’t completed anything yet!
 Super, so far so good…
 Super, you got it all right!
 Sadly not correct…
 One answer is correct
 A couple are correct…
Fahre mit der Maus über die Symbole!