askvity

How does Arduino measure light intensity?

Published in Light Measurement 5 mins read

Arduino measures light intensity by using a light-sensitive component, typically a Light Dependent Resistor (LDR), in conjunction with a simple circuit called a voltage divider. This setup converts the changing light levels into a measurable voltage signal that the Arduino's analog input pins can read.

The Role of the LDR

A Light Dependent Resistor (LDR), also known as a photoresistor, is a component whose resistance changes significantly with the amount of light falling on it.

  • High Light: Resistance is low.
  • Low Light (Dark): Resistance is high.

Since Arduino can directly read voltage, not resistance, a way is needed to translate the LDR's varying resistance into a varying voltage.

The Voltage Divider Circuit

To convert the LDR's resistance change into a voltage signal, a voltage divider circuit is used. This circuit typically consists of two resistors in series, connected between a voltage source (like Arduino's 5V or 3.3V pin) and ground (GND). One of these resistors is the LDR, and the other is a fixed-value resistor (often called a pull-down or pull-up resistor).

According to the reference, one common wiring method involves connecting the LDR directly to an analog pin and ground:

Connect one terminal of the LDR to an analog pin on the Arduino (e.g., A0) and the other terminal to the ground (GND) pin. By creating a voltage divider circuit with a resistor, the varying resistance of the LDR can be converted into an analog voltage reading that the Arduino can process.

In this specific setup described, the fixed resistor would be connected between the Arduino's 5V (or 3.3V) output and the same analog pin (e.g., A0) where the LDR is connected. The analog pin then reads the voltage at the junction between the fixed resistor and the LDR.

Let's visualize this specific setup:

[Arduino 5V/3.3V] ---- [Fixed Resistor] ----+---- [Arduino Analog Pin (e.g., A0)]
                                            |
                                            +---- [LDR Terminal 1]
                                                  |
                                            [LDR Terminal 2]
                                                  |
                                            [Arduino GND]

In this configuration, as light increases, the LDR's resistance decreases. This causes the voltage at the analog pin (A0) to increase. Conversely, as light decreases, the LDR's resistance increases, causing the voltage at the analog pin to decrease.

Reading the Voltage with Arduino

The Arduino's analog pins (like A0-A5 on many boards) have an Analog-to-Digital Converter (ADC). The ADC measures the voltage at the pin and converts it into a digital value.

  • For a standard 5V Arduino board, the analog input range is 0V to 5V.
  • The ADC typically provides a 10-bit resolution, meaning it maps the 0-5V range to digital values from 0 to 1023.
  • analogRead(A0) function in Arduino code reads this digital value.

So, a reading of 0 corresponds to 0V, and a reading of 1023 corresponds to 5V.

Interpreting the Reading

The value read by analogRead() directly corresponds to the voltage at the analog pin, which in turn relates to the light intensity striking the LDR.

  • If the analog reading is close to 1023 (or 5V), it indicates a high voltage, resulting from low LDR resistance (high light).
  • If the analog reading is close to 0 (or 0V), it indicates a low voltage, resulting from high LDR resistance (low light/darkness).

Note: The relationship between the analog reading and light intensity depends on the specific LDR used and the value of the fixed resistor in the voltage divider.

Steps to Measure Light Intensity

Here's a simplified overview of the process:

  1. Hardware Setup:
    • Wire the LDR and a fixed resistor into a voltage divider circuit.
    • Connect one terminal of the LDR to an analog pin (e.g., A0) and the other terminal to the ground (GND) pin, forming a voltage divider with a resistor connected to 5V/3.3V on the same analog pin.
  2. Software:
    • Use the analogRead() function in the Arduino sketch to read the voltage value from the chosen analog pin (e.g., int lightValue = analogRead(A0);).
  3. Interpretation:
    • Process the resulting digital value (0-1023) to understand the light level. Higher values mean more light in the typical configuration described.
    • You can map this value to a more human-readable scale or use it to trigger actions (like turning on a light in darkness).

By utilizing the LDR's resistance change in a voltage divider and reading the resulting voltage with its ADC, the Arduino effectively measures and quantifies light intensity.

Related Articles