Home ESP8266 Wemos and LDR example

Wemos and LDR example

by iainhendry

In this example we connect a photoresistor to an Arduino, the value read from the photoresistor corresponds to the amount of light present. The photoresistor is connected to analog pin 0 in this example.

A photoresistor (or light-dependent resistor, LDR, or photocell) is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits, and light- and dark-activated switching circuits. A photoresistor is made of a high resistance semiconductor.

In the dark, a photoresistor can have a resistance as high as several megohms (MΩ), while in the light, a photoresistor can have a resistance as low as a few hundred ohms. If incident light on a photoresistor exceeds a certain frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump into the conduction band. The resulting free electrons (and their hole partners) conduct electricity, thereby lowering resistance. The resistance range and sensitivity of a photoresistor can substantially differ among dissimilar devices. Moreover, unique photoresistors may react substantially differently to photons within certain wavelength bands.

A practical example could be a dark room sensor for photography, if the reading approached a critical level an alarm could be activated or even a night light

 

 

Schematic

In this example I connected 3v3 to the module and it worked fine

 

Code

In this example we simply output the reading via the serial port.

[codesyntax lang=”cpp”]

int sensorValue;

void setup()
{
  Serial.begin(9600); // starts the serial port at 9600
}

void loop()
{
  sensorValue = analogRead(A0); // read analog input pin 0
  Serial.print(sensorValue, DEC); // prints the value read
  Serial.print(" \n"); // prints a space between the numbers
  delay(1000); // wait 100ms for next reading
}

[/codesyntax]

 

Testing

Open the serial monitor and move the LDR closer to a light, cover the LDR.

413
421
317
298
405
17
13
832
848

 
Links

You can just buy some photoresistors, they are cheap items
Photoresistors on Amazon US

Photoresistors on Amazon UK

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More