You are on page 1of 16

Qrio Level 1

Session 8: Black / White


Sensor
What is Black and
White Sensor!?
The B/W sensor can detect color and distance. It emits
IR rays and then detects if it receives a reflection. This
sensor is often used in line following robots, edge
detection. The sensor allows you to sense white or black
surfaces by reading the value it receives.
 When light falls on a white
surface, it’s almost reflected.

 Arduino gets 1 as in input.

o When light falls on a black


surface, light is completely
absorbed.

o Arduino gets 0 as input.


ConnectionS
Now let’s get to work!
Exercise 1
Make a code where if the B/W sensor
detects white, the LED turns On
and then goes Off
when the sensor detects no white.
Code:
P.S: IO_pin# is whatever pin
you wish to connect the B/W
sensor to it.
*Check the in-board LED to
see the result
To see the result more clearly, you can
connect a LED to the Arduino Board to any
pin you want and define its pin in the code as
int LED= IO_pin;

Then it’ll all be done and clear


But!
What if we have more
than one sensor and LEDs??!
What if I have more than
one condition that I need
to fulfill a certain operation!?
?!WHAT DO WE DO!?
ti o n!
s o l u
s t he
re ’
He i c
e l o g
s th
It’ a t o r s !
o p er
Logic Operators

Arithmetic Logical
Operators Relational Operators
Operators
or and not
Example of logic
operations
or

not
and
Exercise 2!
Let’s work on 2 sensors and 2 LEDs at the same time!
1. If both sensors read white, the two LEDs turn On
2. If one of the sensors reads white, only the green LED
turns on!
3. If both sensors aren’t reading, only the red LED turns
on!
For each of the three cases, we want to see the result on
the SERIAL MONITOR!
Remember to use the logic operators right!
Code:

SEE YOU NEXT WEEK

You might also like