Arduino analog pin doesn't read correctly without connecting to gnd and Vcc of arduino

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) 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?

• No good showing the good working circuit cartoon. Show the bad one. Incorrect values means maybe a million volts? – Andy aka Jun 25 '17 at 17:43
• 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 – user3812911 Jun 25 '17 at 17:50
• Have you understood anything I said in my comment? – Andy aka Jun 25 '17 at 17:52
• 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. – nickagian Jun 25 '17 at 17:57
• Thank you so much ! @nickagian yes not connecting the ground of the power supply to the ground of the arduino was the problem. – user3812911 Jun 25 '17 at 18:22