Thursday, 19 January 2012

HOOKING UP THE LDR AND LED


Now that the LDR is set up and ready to go, with the Sensor Monitor reading the resistance for us, we're now connecting the LED light to the board and see if we can get it to fade brightness depending on the LDR.

The LED has been put into the Ground pin and 11. Pins 9, 10 and 11 are PWM - pulse width modulation, which enables us to use the fade function. I think.


So it's pinMode (11, OUTPUT) because we want the output for Pin 11. And it's analogWrite because fading requires analogue function and the 'write' bit allows for PWM. We divide 'val' (which is the LDR running at 1024) so the LED is more or less sensitive. Dividing by 4 gives the LED 256.

End result is: less light dims LED down, more light brightens LED. Very cool.

No comments:

Post a Comment