www.colmac.ie
35
8. Using the LDRs to detect a line
Before we can successfully use the LDR sensors to detect a line we must learn how to understand
the digital reading that the LDR creates in the GENIE software.
The resistance of the LDR supplied goes from approx. 1KΩ in normal light to approx. 15KΩ in
normal darkness i.e.
the resistance of an LDR increases as it gets darker
.
Theoretically it goes from 0KΩ in total brightness to 1MΩ in total darkness.
The GENIE software takes whatever analogue resistance value the LDR has at any given moment
and converts it into a digital reading of between 0 and 255.
A digital value of 0 corresponds to an LDR resistance of 1MΩ i.e.
total darkness.
Similarly, a digital reading of 255 corresponds to an LDR resistance of 0KΩ i.e.
total brightness.
Turn on your robot, connect it to the USB and select
Calibrate Sensor
from the
Microcontroller
menu on the tool bar. You should see the screen shown below.
Shows the LDRs connected to A0
and A2 and their current reading.
Move the robot around and
observe the reading change as
LDRs pass over bright and dark
surfaces.