top of page

Light Sensitivity Using Photoresistor

The basic concept of using a photoresistor (light-dependent resistor, LDR) with an Arduino to detect light sensitivity involves measuring the resistance of the LDR, which changes based on the light intensity. This data can then be used to control other components, like turning on an LED when it gets dark.

​

How It Works:

A photoresistor is a type of resistor whose resistance decreases as the light intensity increases. In bright light, the resistance is low, and in darkness, the resistance is high.

​

The Arduino reads the changing resistance of the LDR as an analog voltage value through one of its analog input pins. The analog-to-digital converter (ADC) in the Arduino converts this analog signal into a digital value (0 to 1023).

Materials Anchor

Materials

For a basic Light Sensitivity Project using a photoresistor (LDR) with an Arduino, you'll need the following components:

​

1) Arduino Board

  • Arduino Uno, Arduino Nano, or any other compatible Arduino board.

​​

2) Photoresistor (LDR)

  • A light-dependent resistor that changes its resistance based on the amount of light it receives. The resistance decreases as light intensity increases.

​​

3) 10k ohm Resistor

  • 10k ohms (common value for use with an LDR in a voltage divider circuit). Works with the LDR to create a voltage divider, allowing the Arduino to measure the varying resistance of the LDR as a voltage change.

​​

4) LED

  • A light-emitting diode that can be used to indicate the light level. It can turn on or off based on the LDR's readings.

  • Current-Limiting Resistor: 220 ohms (to protect the LED from excess current).

​

5) 220 ohm Resistor

  • Current-Limiting resistor to protect the LED from excess current.

​​

6) Breadboard

  • A breadboard is used for prototyping and connecting all components without soldering.

​​

7) Jumper Wires

  • Used to connect the components on the breadboard and to the Arduino board.

​​

i8) USB Cable (Type-A to Type-B)

  • Connects the Arduino to a computer for programming and power supply.

Setup Anchor

Basic Setup

Breadboard_GREY.png
schematic_GREY_REAL.png

Here’s a basic setup to use an LDR (Light Dependent Resistor) with Arduino to turn on an LED based on light levels.​​

​​

1) LDR (Light Dependent Resistor)

  • Connect one leg of the LDR to 5V on the Arduino.

  • Connect the other leg to an analog input pin on the Arduino (e.g., A0).

  • Connect a 10kΩ resistor between the LDR and ground to create a voltage divider.​

​

2) LED

  • Connect the positive (longer) leg of the LED to a digital pin on the Arduino (e.g., pin 13).

  • Connect the shorter leg of the LED to ground via a current-limiting resistor (e.g., 220Ω).

​

3) Power the Arduino

  • Connect the Arduino to your computer using the USB cable. This will provide power to the Arduino and allow you to upload the code.

Code
code.png

CODE BREAK-DOWN

Code Break Down

Pin Definitions

  • A photoresistor (LDR) is connected to an analog pin to measure light intensity.

  • An LED is connected to a digital pin, which allows the Arduino to turn it on or off programmatically.

​

Light Threshold

  • A threshold value is set to determine when the LED should turn on or off based on the light intensity.

  • If the light reading is below the threshold, it is considered "dark," and the LED turns on.

  • If the reading is equal to or greater than the threshold, it is considered "bright," and the LED turns off.

​

Setup Function

This function runs once when the Arduino starts.

  • The LED pin is configured as an output so the Arduino can control the LED.

  • Serial communication is initialized, enabling the Arduino to send data (such as light readings) to the Serial Monitor on your computer for observation.

​

Loop Function

  • The loop function runs repeatedly, performing the main tasks of the program.

​​

Step 1: Read the LDR Value

  • The Arduino reads the analog value from the LDR pin, which represents the light intensity. This value ranges from 0 (dark) to 1023 (bright).

  • The reading is then sent to the Serial Monitor for real-time observation and debugging.

​

Step 2: Compare the LDR Value with the Threshold

  • If the light intensity is below the threshold, the Arduino considers it dark and turns the LED on.

  • If the light intensity is equal to or above the threshold, the Arduino considers it bright and turns the LED off.

​

Step 3: Add a Delay

  • A short delay is introduced to stabilize the readings and prevent rapid flickering of the LED. This also smoothens the system’s response to changes in light intensity.

bottom of page