I'm a high school student trying to make a light tracking single axis solar panel. I am using an Arduino Uno rev3 board.

When I first finished building it, the system failed to operate. I spent a few hours figuring out the problem. Then I decided to test my LDRs again (already once checked before building). Then something weird happened. One of my LDRs gives around 50-59 serial output, whereas the other one goes from 0 - 300 - 0 - 300. I thought my LDR was faulty but I had once tested it and it worked fine.

Another thing, when I cover the LDR with my hand it outputs a steady 0. Then theoretically, it's still detecting light right?

Here's the code:

int sensorPin = A0;

void setup() 

void loop() 
  int sensorValue = analogRead(sensorPin);

Here's the circuit diagram I used to test the LDR:

Here's the circuit diagram I used to test the LDR

New contributor
ElevenBits is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 2
    \$\begingroup\$ What is the source of light? Fluoros will give you a fluctuating signal at mains frequency. Leds may give you a fluctuating signal at high frequency. Daylight will be continuous and incandescent should be similar. \$\endgroup\$
    – Kartman
    Nov 23 at 3:39
  • \$\begingroup\$ Try putting a filter capacitor or just do a software average. Why not simply use the panel output which is about the largest light sensitive component in existance? \$\endgroup\$ Nov 23 at 7:11
  • \$\begingroup\$ If swapping that one LDR in and out of the circuit causes and removes the problem, that's probably it. Try to get your hands on a few more to see if others match your good one. Also try measuring the "bad" one with a multi-meter. \$\endgroup\$
    – Drew
    Nov 23 at 7:52
  • \$\begingroup\$ Just to be clear on terminology: what you posted is not a circuit diagram. That's a drawing (made probably with Fritzing or similar software) that illustrates the physical layout of the circuit. A circuit diagram, or schematic, is a different thing. Don't call that a circuit diagram in presence of an electrical engineer, someone could be pissed off. \$\endgroup\$ Nov 23 at 23:22

If both LDR parts are the same model, then I agree with @Drew that the other unit may be defective. Otherwise, of both units are not the same model (which is my guess here) then this could explain the different readings since LDRs come in a variety of resistance ranges. If you have an old analog resistance meter, then that could be used to test the units. Watching the needle move as you shine more light on it is a great test.

Understanding the nominal LDR resistance for the light conditions you want to operate it is important. The expected operating range of the LDR resistance can vary by quite a lot (such as 50k for cloudy down to 0.1k for direct sun, but that depends on your unit) so experiment with different divider resistor values for the best performance. Ideally, you don't want the reading to saturate for the brightest condition since that is what you are searching, so find the divider resistor that tops out the reading around 4.8V for direct sun. Finding the right divider resistor will depend on the LDR you have on-hand.

As Marcantonio suggested, just average over several readings to remove noise. The LDR that gives you 50-59 is not bad, only 50mV noise. A software average should take care of this.

Also, you can expect reading 0 when covered by hand, since the LDR has a very high dark resistance (generally > 1M ohm), and your circuit is using a low divider resistor value (appears to be 1K ohm). Doing the math, Vain = 5V * 1k / (1k + 1M) = 5mV. This is on the order of 1 LSB for the 10-bit Arduino ADC (5V/1024 = 5mV), so reading 0 is close. So yes, the LDR is reading light assuming your hand isn't creating a completely dark environment, but your ADC circuit cannot read down to this small value. Using an amplifier would help, but then again your application is only to track to the brightest, not dim conditions.

  • 1
    \$\begingroup\$ Hey thanks for showing interest ! I figured out the problem. None were defective. I was using jumper wires for connecting the LDR to the breadboard.. One of the jumpers had a female to male connection which was terribly loose. That caused the serial output to fluctuate. \$\endgroup\$
    – ElevenBits
    Nov 24 at 4:13

Your Answer

ElevenBits is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.