I'm using an LDR (photoresistor) with arduino and i have the following two cases:

Case 1: I connect the input of LDR to Vcc of the arduino, The ground of the LDR to the ground of the arduino and the output of the LDR to A0 (analog pin) of arduino and it reads the values correctly. (like the figure below) enter image description here Case 2: I make the same exact wiring but instead of taking Vcc from arduino, i take it from an external power supply (also providing 5v) and i connect the ground of the LDR to the ground of the power supply..So input and ground are connected externally and output pin is connected to A0. In this case the arduino reads values incorrectly!

So what's wrong with case 2 why is it not working? Note : in case 2 i measured the voltage between the output of the LDR and the ground is giving a correct value, so why connecting that output to arduino gives incorrect values?

In other words: Why do I need to connect input and ground of LDR to arduino and not to an external power supply?

  • 2
    \$\begingroup\$ No good showing the good working circuit cartoon. Show the bad one. Incorrect values means maybe a million volts? \$\endgroup\$ – Andy aka Jun 25 '17 at 17:43
  • \$\begingroup\$ The bad is the following, using external power supply: (1) connected to external 5 volt, (3) is connected to external ground, (2) is connected to A0 as is, And the incorrect values are so irrelevant like:1023,0,95,43 and so on they do not have any pattern @Andyaka \$\endgroup\$ – user3812911 Jun 25 '17 at 17:50
  • \$\begingroup\$ Have you understood anything I said in my comment? \$\endgroup\$ – Andy aka Jun 25 '17 at 17:52
  • \$\begingroup\$ Agreed with Andy aka: Or maybe show both, the good and the bad circuits. But definitely the bad. In the second case, is the external power supply ground connected to the ground of the Arduino? If not, that's probably your problem. If, in the second case, you measure the voltage between the LDR output and the Arduino's ground, I guess you would measure the same, "incorrect" as you call them, values that the ADC measures. \$\endgroup\$ – nickagian Jun 25 '17 at 17:57
  • \$\begingroup\$ Thank you so much ! @nickagian yes not connecting the ground of the power supply to the ground of the arduino was the problem. \$\endgroup\$ – user3812911 Jun 25 '17 at 18:22

My answer is actually transferred from my comment above, so now I know it is correct. However, it was not clear from the original question how the connections were made in the second case with the "incorrect" measurements.

So, my initial assumption, which was later indeed confirmed, was that the GND of the external power supply you have used is not connected with the GND of the Arduino. That means that the GND of the LDR circuit is not connected with the GND of the ADC of the Arduino. As a consequence, there is most probably some fluctuating voltage difference between the two GNDs.

So you basically measure a voltage and the ADC doesn't have the same reference voltage (GND) with the voltage you want to measure, which leads to the incorrect measurements.

The solution is to use the same GND for both the LDR circuit and the Arduino.


Your Answer

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.