Photoresistor Module

../_images/07_photoresistor_module.png

Introduction

A photoresistor module is a device that can detect the intensity of light in the environment. It can be used for various purposes, such as adjusting the brightness of a device, detecting day and night, or activating a light switch.

An important component of the photoresistor module is the photoresistor. A photoresistor is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it exhibits photo conductivity.

A photoresistor can be applied in light-sensitive detector circuits and light-activated and dark-activated switching circuits acting as a resistance semiconductor. In the dark, a photoresistor can have a resistance as high as several megaohms (MΩ), while in the light, a photoresistor can have a resistance as low as a few hundred ohms.

Here is the electronic symbol of photoresistor.

../_images/07_photoresistor_symbol_2.png

Principle

The photoresistor module works on the principle of changing resistance in response to different light intensities. The sensor has a built-in potentiometer that adjusts the sensor’s digital output (D0) threshold. When the intensity of light exceeds a certain threshold, the resistance of the sensor changes. This change in resistance is then converted to an electrical signal that can be read by the Arduino board.

Usage

Hardware components

  • Arduino Uno R4 or R3 board * 1

  • Photoresistor Module * 1

  • Jumper Wires

Circuit Assembly

../_images/07_photoresistor_module_circuit.png

Code



Code explanation

  1. This line of code defines the pin number to which the photoresistance sensor is connected on the Arduino board.

    const int sensorPin = 7;
    
  2. The setup() function is a special function in Arduino that is executed only once when the Arduino is powered on or reset. In this project, the sensorPin is set as INPUT because we are reading values from it. The Serial.begin(9600) command initiates serial communication at a baud rate of 9600.

    void setup() {
      pinMode(sensorPin, INPUT);
      Serial.begin(9600);
    }
    
  3. The loop() function is the main function where the program runs repeatedly. In this function, the digitalRead function reads the digital value from the photoresistor sensor and prints it to the serial monitor using Serial.println. The delay(50) command makes the program wait for 50 milliseconds before taking the next reading.

    void loop() {
      Serial.println(digitalRead(sensorPin));
      delay(50);
    }
    

Additional Ideas

  • Use the sensor to turn on/off an LED or relay.

  • Plot the analog output instead of just digital HIGH/LOW. Use AO pin.

More Projects