# LDR photosensor with arduino

**URL:** <https://forum.arduino.cc/t/ldr-photosensor-with-arduino/659971>\
**Category:** General Electronics\
**Created:** [June 10, 2020, 3:39pm UTC](https://forum.arduino.cc/t/ldr-photosensor-with-arduino/659971 "2020-06-10T15:39:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![szevlin](https://avatars.discourse-cdn.com/v4/letter/s/db5fbb/32.png) [@szevlin](https://forum.arduino.cc/u/szevlin)\
**Post date:** [June 10, 2020, 3:39pm UTC](https://forum.arduino.cc/t/ldr-photosensor-with-arduino/659971/1 "2020-06-10T15:39:27Z")

</div>

I have connected my LDR between A0 and 3volts on my board and a 10k resistor between 3volts and ground, as i have seen on a schematic,  
but i only get high values, its giving 1024 even in low light and it only goes down to 600 even if i cover it,  
i tried to change the resistor to 3.3k ohms but its still the same.  
is there a problem with the sensor or the resistor value?

---

<div class="post-metadata">

**Author:** ![MK1888](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MK1888](https://forum.arduino.cc/u/MK1888)\
**Post date:** [June 10, 2020, 3:49pm UTC](https://forum.arduino.cc/t/ldr-photosensor-with-arduino/659971/2 "2020-06-10T15:49:28Z")

</div>

Your schematic is wrong if it shows those connections.

---

<div class="post-metadata">

**Author:** ![Ron\_Blain](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ron_blain/32/1126393_2.png) [@Ron\_Blain](https://forum.arduino.cc/u/Ron_Blain)\
**Post date:** [June 10, 2020, 4:09pm UTC](https://forum.arduino.cc/t/ldr-photosensor-with-arduino/659971/3 "2020-06-10T16:09:57Z")

</div>

Make it look like this:

 ![](https://europe1.discourse-cdn.com/arduino/original/4X/6/e/e/6eef19235374027c0aafa960468f964d99a4ab4e.png)

Then try reversing the positions of the 10K resistor and the LDR. What happens then?

Ron

---

<div class="post-metadata">

**Author:** ![groundFungus](https://avatars.discourse-cdn.com/v4/letter/g/73ab20/32.png) [@groundFungus](https://forum.arduino.cc/u/groundFungus)\
**Post date:** [June 10, 2020, 4:54pm UTC](https://forum.arduino.cc/t/ldr-photosensor-with-arduino/659971/4 "2020-06-10T16:54:46Z")

</div>

Or for a simple test, connect the LDR from analog input to ground. Set the pinMode of the input to INPUT\_PULLUP to enable the internal pullup resistor. Then no external resistor is needed.

example of LDR on input pullup analog input pin:

```cpp
const byte ldrPin = A0;

void setup()
{
  Serial.begin(115200);
  Serial.println("LDR Test Program");
  pinMode(ldrPin, INPUT_PULLUP);
}

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

```

Reads low numbers when in light, high when dark. Often when using the internal pullup the sensitivity is OK, but if not then use an external resistor.

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [June 10, 2020, 7:03pm UTC](https://forum.arduino.cc/t/ldr-photosensor-with-arduino/659971/5 "2020-06-10T19:03:45Z")

</div>

> but i only get high values, its giving 1024 even in low light and it only goes down to 600 even if i cover it,

So you need to drop the value of the resistor in the circuit shown in reply #2.

For best results measure the resistance of the LDR in the mid light level you want and make the resistor as close to this value as you can.

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [June 11, 2020, 5:56am UTC](https://forum.arduino.cc/t/ldr-photosensor-with-arduino/659971/6 "2020-06-11T05:56:41Z")

</div>

> szevlin:  
> I have connected my LDR between A0 and 3volts on my board and a **10k resistor between 3volts and ground,** as i have seen on a schematic,  
> but i only get high values, its giving 1024 even in low light and it only goes down to 600 even if i cover it,  
> i tried to change the resistor to 3.3k ohms but its still the same.  
> is there a problem with the sensor or the resistor value?

Try the resistor between A0 and gnd, with the LDR between 3V and A0.  
Tom... 🙂

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 2:33am UTC](https://forum.arduino.cc/t/ldr-photosensor-with-arduino/659971/7 "2021-05-06T02:33:42Z")

</div>

Closed on May 6, 2021, 2:33am UTC


