Monday, May 3, 2010

Arduino Light Dependent Resistor

Well, tonight, the board has a light dependent resistor (LDR). Only two of the three leads are used, so it's a little tacky, but this is, after all, prototyping. It will be cleaned up later- functionality is the name of the game right now. The analog value returned from the LDR drops with the light level. Using this value will enable the implementation of a small night-light circuit rather easily.

The easiest approach is to take the value returned from the LDR and feed it into an analogWrite command and use PWM to alter the brightness of the LED. Doing this directly would normally dim the LED as the light was dimmed. The LED was reversed and now operates as the inverse of the value read from the LDR. That is, as the light dims, the LDR returns a lower value, that value is fed into the analogWrite command and as the value drops, the LED gets brighter. Quick, easy, effective.

Here is the code in action:



Here is the board in action:


Happy breadboarding!