Introduction

A photoresistor is an electronic component used to measure light intensity. It is a resistor whose value changes according to the light it receives.

Photoresistors can be used for projects using light, such as a darkness detector that turns on an LED at a certain level of darkness, or a sun tracker for solar panels.

There are other sensors that capture light and output it in the form of electrical signals. These include photodiodes and phototransistors.

How does it works?

It works with a resistor: the brighter the light, the lower its resistivity. This resistor takes on a value of 50 kΩ in darkness and varies up to 500 Ω in full light. To convert this variation in value into a variation in current, the resistor must of course be powered.

The photoresistor uses the analog pins on the arduino board. This means that the light intensity will be transformed into a voltage which will be read by our program.

The unit of measurement used by the photoresistor

The unit of measurement for light is the lux. Here are a few examples to give you an idea:

  • Full-moon night: 0.5 lux
  • Well-lit apartment: [ 200- 400] lux
  • Outdoors under an open sky: [500 to 25,000] lux
  • Outdoors in full sun: [50,000 -100,000] lux

Photoresistor electrical symbol

In electronic circuits, you’ll see the symbol opposite to represent the photoresistor.

How do I choose the right model?

It’s sometimes difficult to decide which photoresist you need for your project. Photoresistors all have the same external characteristics, what will change is the value of the internal resistance and the technical characteristics as shown in the table below:

As you can see, the values are more than sufficient for arduino projects, which is why most photoresistors are sold in the same package, even if they have different part numbers.

However, there’s another way to choose your photoresist, and that’s the difference between light resistors.

As you can see from the table, depending on the project you’re going to do, you’ll need greater precision in the dark, or a higher resistance that will cover a wider range of light. This is what makes you choose the different resistors. You’ll find these values on the data sheet for the photoresist you’ve chosen.

Display photoresistance value on serial monitor

Now we’ll see how to display the voltage value read by the photoresistor. It will be displayed on the serial monitor.

int photoresistance_value;
void setup() {
  Serial.begin(9600);
}
 
void loop() {
  photoresistance_value = analogRead(A0); // photoresistance is connected to analog terminal A0
  Serial.println(“Here's the photoresistance value:”); 
  Serial.println(photoresistance_value); 
  delay(100);
}

Obscurity detector

Now let’s see how to make a darkness detector. To do this, we’ll use a photoresistor, and when a certain darkness threshold is reached, the arduino board will light up a LED.

Here’s the circuit diagram:

For this project, we’ve chosen a dark detection value of 15, which can be changed depending on when you want your LED to light up:

const int led = 8;      
 
void setup() {
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}
 
void loop() {
  int value_photoresistance = analogRead(A0); // The photoresistor is connected to analog terminal A0
  if(value_photoresistance < 15) { // If measured value < 15 (No light)
    Serial.println(“-------------”);
    digitalWrite(led, HIGH); // We turn on the led
    Serial.println(“It's night, let's turn on the LED!”);
    delay(2000);                
  }
  else { 
    Serial.println(“-------------”);
    Serial.println(“It's daytime, turn the LED off!”);
    digitalWrite(led, LOW); // Turn off the LED
    delay(2000);                
  }    
}

Solar tracker

Let’s take a look at how to make a solar tracker. This project could be really useful if you want to make solar panels that move according to the sun, for example:

Here we have made the servomotor move if the light value is below “40”, however this value can be changed at your convenience: 

#include <Servo.h> // Servomotor library
Servo myServomotor; // Servomotor declaration
int pos = 0; // Initial servomotor position
     
 
void setup() {
  myServomotor.attach(9); // The servomotor is connected to terminal A0.
}
 
void loop() {
  int value_photoresistance = analogRead(A0); // The photoresistor is connected to analog terminal A0.
  pos = map(value_photoresistance, 1,310,0,180); // A cross product is generated with the photoresistance value.
  myServomotor.write(pos); // Update servomotor position
}