Categories

Follow Us

Arduino and LDR example

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.

photoresistor (or light-dependent resistorLDR, or photo-conductive cell) 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-activated 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 photoelectric device can be either intrinsic or extrinsic. An intrinsic semiconductor has its own charge carriers and is not an efficient semiconductor, for example, silicon. In intrinsic devices the only available electrons are in the valence band, and hence the photon must have enough energy to excite the electron across the entire bandgap. Extrinsic devices have impurities, also called dopants, added whose ground state energy is closer to the conduction band; since the electrons do not have as far to jump, lower energy photons (that is, longer wavelengths and lower frequencies) are sufficient to trigger the device. If a sample of silicon has some of its atoms replaced by phosphorus atoms (impurities), there will be extra electrons available for conduction. This is an example of an extrinsic semiconductor

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

Here is our sensor, it was part of a 37 in 1 sensor kit, links at the bottom

LDR sensor

LDR sensor

Schematic

arduino and ldr schematic

arduino and ldr schematic

Code

In this example we simply output the reading via the serial port. You can monitor this in the Serial Port Monitor

 

int sensorValue;
 
void setup()
{
Serial.begin(9600); // starts the serial port at 9600
}
 
void loop()
{
sensorValue = analogRead(0); // 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
}

 

In this example we check the value returned by the photoresistor, if it drops beneath a certain value we switch the onboard LED on, if it goes above this value the LED will switch off

int sensorValue;
int led = 13;
 
void setup()
{
pinMode(led, OUTPUT);
}
 
void loop()
{
sensorValue = analogRead(0); // read analog input pin 0
//daylight was 700 – so lets detect a reading under 300
if (sensorValue < 300)
{
digitalWrite(led, HIGH);
}
else
{
digitalWrite(led, LOW);
}
delay(1000); // wait 100ms for next reading
}

 

Links

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

Photoresistors on Amazon UK

Here are links to the sensor kit

Ultimate 37 in 1 Sensor Modules Kit for Arduino from Amazon UK
Ultimate 37 in 1 Sensor Modules Kit for Arduino from Amazon US

Share

Comments are closed.