Right way of using resistor with ldr sensor

Why does the LDR sensor work fine with the analog pin (green wire) being "directly" connected to the sensor terminal, before the resistor...

...and it doesn't work when the analog pin is connected "after" the resistor? (It only outputs "0" into the serial monitor)

I thought that the voltage doesn't change whether if it's before or after the resistor. Is it a hardware problem that only I'm facing? Does it have to do with resistor value?

1 Like

Hi,
In the second diagram, you have the analog input connected to GND, it will not change potential as it is the GND that the UNO uses as GND reference.

The first diagram, the voltage changes because the CURRENT through the LDR and resistor changes as the light level changes on the LDR.
Because the resistor is fixed in value, it will drop a voltage proporional to the total current flowing through the LDR and resistor.

Google:

ohm's law arduino ldr

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

3 Likes

I get it now. It was reading the GND the entire time, that's why it was showing 0.
After quickly reading an article, it really clarified everything for me.
Thanks Tom :+1:

What you're doing is forming a potential divider (aka, voltage divider) with the LDR and the resistor:

So you choose the value of the fixed resistor to give a suitable Vout to your ADC over the range of light levels of interest.

1 Like

The Phet-Simulations are very easy to use. Much easier than other circuit-simulations


Rebuilt this circuit
Set battery-voltage to 100V and both resistors to 100 Ohm
Then change the value of one resistor and watch the two voltage measurings

best regards Stefan

1 Like

I often use the internal pullup resistor as the load resistor with a LDR. If the sensitivity is OK it saves using another resistor.

image

Code to read LDR on A0 with internal pullup as LDR load resistor:

const byte ldrPin = A0;

void setup()
{
   Serial.begin(115200);
   // enable internal pullup on pin A0
   pinMode(ldrPin, INPUT_PULLUP);
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 1000;
   if (millis() - timer >= interval)
   {
      timer = millis();
      int ldrValue = analogRead(ldrPin);
      Serial.print("Light reading = ");
      Serial.println(ldrValue);
   }
}

The same method can be used with a Force Sensitive Resistor.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.