1

i am new to micro controller programming and in need of help. i have managed to interface a light sensor to a micro controller (atmega 32a) and can read the value i.e. (1023) as per the set prescale. however i intended to achieve a single decimal value as the result. in this case (1) every time the sensor is exposed to light and successively perform an incremented tally as lights go on and off around the sensor ( i am using a LDR for this). i am currently having problem getting my micro controller to do this. i have searched all over the internet but no seems to assist me on this... please any insight on how to achieve this will be much appreciated. i know its a simple thing,HELP :(

basically just a means of making my micro controller count the number of times light falls on the LDR

Bob Otieno
  • 11
  • 1

1 Answers1

2

There are 2 common light sensor types. The photo diode and the photo resistor. The first produces small amounts of current and operates fast. The second changes resistance and operates (very) slowly.

There is a good stack exchange response here for how to use a photo diode. Often the photo diode output is small and additional hardware is used to amplify the signal. As discussed in this stack exchange response.

The photo resistor or cadmium sulphide cell or Light Dependent Resistor is much easier to interface with an Arduino. However, the response time is very slow. On the order of hundreds of milliseconds to seconds. This is acceptable when controlling street lights. But is not acceptable in applications requiring fast light detectors such as those used for communication.

Before going on, verify which device you are using in your design.

Generally, Arduinos contain a 10 bit ADC. This results in values from 0 to 210−1 or 0 to 1023. Should you consistently get a reading at or near the limits of the ADC check your hardware. Do this by measuring the voltage at the input of the ADC pin used. Do this under varying conditions to verify the hardware is operating as expected.

A good software design uses hysteresis to convert an analog value to a logical 1 or 0. Here is a stack exchange response about using hysteresis with Arduinos.

st2000
  • 7,513
  • 2
  • 13
  • 19