# How to setup LDR'S

**URL:** <https://forum.arduino.cc/t/how-to-setup-ldrs/508705>\
**Category:** Sensors\
**Created:** [February 16, 2018, 2:37pm UTC](https://forum.arduino.cc/t/how-to-setup-ldrs/508705 "2018-02-16T14:37:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![luciocr](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@luciocr](https://forum.arduino.cc/u/luciocr)\
**Post date:** [February 16, 2018, 2:37pm UTC](https://forum.arduino.cc/t/how-to-setup-ldrs/508705/1 "2018-02-16T14:37:48Z")

</div>

Hello, everyone! I would like to know what is the best method to calibrate sensor LDR and how i find the values for sensitivity and threshold? Thank very much

---

<div class="post-metadata">

**Author:** ![LesserMole](https://avatars.discourse-cdn.com/v4/letter/l/35a633/32.png) [@LesserMole](https://forum.arduino.cc/u/LesserMole)\
**Post date:** [February 16, 2018, 2:50pm UTC](https://forum.arduino.cc/t/how-to-setup-ldrs/508705/2 "2018-02-16T14:50:09Z")

</div>

[This](https://learn.adafruit.com/photocells)might help

---

<div class="post-metadata">

**Author:** ![knut\_ny](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/knut_ny/32/1013044_2.png) [@knut\_ny](https://forum.arduino.cc/u/knut_ny)\
**Post date:** [February 16, 2018, 8:01pm UTC](https://forum.arduino.cc/t/how-to-setup-ldrs/508705/3 "2018-02-16T20:01:56Z")

</div>

I made an LDR-based Luxmeter for my sons car headlights..  
calibrated by comparison with the BH1750FVI

my code

```cpp
/*  
 *  Running pr. 20.11.17
 *  calculate Rldr first  -> Then  Rldr * x^-1.6 
 *  R ser =  6k8
  The circuit: 2lines 16 char LCD panel
  LCD RS pin to digital pin 2
  LCD Enable pin to digital 4
  LCD D4 pin to digital pin 5
  LCD D5 pin to digital pin 6
  LCD D6 pin to digital pin 7
  LCD D7 pin to digital pin 8
  LCD R/W pin to ground pin 3
  LCD VSS pin to ground
  LCD VCC pin to 5V
  10K resistor:
  ends to +5V and ground
  wiper to LCD VO pin 2k2 pot

  http://www.arduino.cc/en/Tutorial/LiquidCrystal

  Circuite runs from 3*1,5V AA batteries
  resistors for battery check 47k/12k , ref 1.1V => 5V returns analog read 948
*/
#define Rsel 3
#define Enable 4
#define Db4 5
#define Db5 6
#define Db6 7
#define Db7 8

#define vpin A0
#define s1pin A6  // !!!! this is for the pro mini , Change if using UNO

#include <LiquidCrystal.h>
LiquidCrystal lcd(Rsel, Enable, Db4, Db5, Db6, Db7);
unsigned int v1, i ; // voltage1, sensor1
float battery, Lux,Rldr,s1;

void setup()
{
  Serial.begin(115200);
  //Battery check
  analogReference(INTERNAL); // 1.1V
  analogRead(vpin); delay(300); analogRead(vpin);
  v1 = analogRead(vpin);

  analogRead(s1pin); // dummy read
  lcd.begin(16, 2);
  lcd.print("Batteri : ");
  battery = v1 / 193.0;
  if (battery > 3.5)
  {
    lcd.print(battery, 1);
    lcd.print(" V");
  }
  else lcd.print("low !");
  lcd.setCursor(0, 1);
  lcd.print("Lys : ");
  analogReference(DEFAULT); // back to supply current
  analogRead(s1pin); delay(100);
  analogRead(s1pin); delay(100);
}

void loop()
{
  s1 = 0;
  for (i = 0; i < 20; i++)  s1 = s1 += analogRead(s1pin);
  s1 = s1/20.0; 
  Rldr= 68.0*(1023-s1)/s1;
  Lux = 200000.0*pow(Rldr,-1.6);
  Serial.println(Lux);
  lcd.setCursor(6, 1);
  lcd.print(Lux,0);
  lcd.print(" Lux  ");
  delay(999);
}

```

---

<div class="post-metadata">

**Author:** ![wvmarle](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/wvmarle/32/1013044_2.png) [@wvmarle](https://forum.arduino.cc/u/wvmarle)\
**Post date:** [February 17, 2018, 7:27am UTC](https://forum.arduino.cc/t/how-to-setup-ldrs/508705/4 "2018-02-17T07:27:26Z")

</div>

If you want to measure whether it's dark outside, or if a light is on or off, an LDR will do fine.

If you want to measure lux, get a lux meter, such as the TSL2591 (or the older TSL2561).

---

<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, 10:20am UTC](https://forum.arduino.cc/t/how-to-setup-ldrs/508705/5 "2021-05-06T10:20:28Z")

</div>

Closed on May 6, 2021, 10:20am UTC


