Blog
Light Sensor: A Simple Arduino Tutorial
Definition of light sensor
A light sensor is an electronic device that can detect the brightness of the surrounding environment and output signals. Its main function is to convert optical signals into electrical signals, which are then recognized and processed by a controller for controlling other electronic components. It can be used in various scenarios requiring light detection.
What does a light sensor do?
Light sensors are widely used in various fields, such as consumer electronics, smart homes and the Internet of Things (IoT), industry and agriculture, scientific research, and art projects. For instance, when using a mobile phone, the automatic brightness adjustment function regulates the screen brightness based on the values detected by the light sensor; it also enables the phone to turn off the screen automatically in dark environments to prevent accidental touches. In smart homes, light sensors can adjust the opening and closing of curtains according to the room brightness and preset modes. Additionally, a light bulb with motion sensor—a common smart home device that combines light-sensing and motion-detection functions—also relies on light sensors: it can automatically turn on at low ambient brightness when motion is detected and stay off in sufficient light, achieving energy-saving and intelligent lighting control. Overall, light sensors have a relatively wide range of application fields and scopes.
Light sensor types
Classified by working principle, light sensors can be divided into four types: ① Light-Dependent Resistor (LDR), ② Photodiode, ③ Phototransistor, and ④ Integrated Ambient Light Sensor.
Light sensor circuit diagram
The four types of light sensors operate on distinct working principles, and their detailed operational mechanisms are as follows:
① Light-Dependent Resistor (LDR): It works based on the internal photoelectric effect. When the photosensitive material is exposed to light, the electrons inside it are excited, resulting in a decrease in resistance. Light intensity data can be derived from the resistance value—the stronger the light, the lower the resistance.
② Photodiode: It relies on the external photoelectric effect. When its PN junction is illuminated, it generates a current proportional to the light intensity. The light intensity data can be obtained by measuring the magnitude of this current.
③ Phototransistor: It functions like a transistor where light replaces the base current. Light exposure is equivalent to providing current to the base, which in turn controls the conduction and amplification of the current between the collector and the emitter.
④ Integrated Ambient Light Sensor: It is usually based on a photodiode or phototransistor, but integrates the sensor, amplifier, Analog-to-Digital Converter (ADC), and digital interface all into a single chip.
Light Sensor Schematic Diagram
① Light-Dependent Resistor (LDR) Schematic Diagram:
② Photodiode Schematic Diagram:
③ Phototransistor Schematic Diagram:
④ Integrated Ambient Light Sensor Schematic Diagram:
Light Sensor Functions
Several Commonly Used Small Light Sensors
What is the BH1750 (GY-302) sensor?
TEMT6000 Light sensor
OPT101 Light Sensor
Electrical Parameters
BH1750 (GY-302) Electrical Parameters
| Parameter | Value |
|---|---|
| Supply Voltage | DC 3~5V |
| Supply Current | 200uA |
| Operating Temperature | -40~+85°C |
| Resolution | 0~65535 Ix |
| Interface | I2C |
| Error Variation | ±20% |
TEMT6000 Electrical Parameters
| Parameter | Value |
|---|---|
| Operating Voltage | 3.3~5.5V |
| Operating Temperature | -40~85°C |
| Illuminance Range | 1 – 1000Lux |
| Output Signal | Analog voltage, 0 – 5V range at 5V operating voltage |
OPT101 Electrical Parameters
| Parameter | Value |
|---|---|
| Supply Voltage | 2.7V to 5.5V |
| Operating Temperature Range | -40℃ to +85℃ |
| Photodiode Area | Approx. 1mm² |
| Transimpedance Gain | 10⁵ Ω (Typical) |
| Output Current Range | 0μA to 2mA |
| Bandwidth | 30kHz (Typical) |
Light Sensor Datasheet
Light Sensor Pinout
BH1750(GY-302) Pinout
①VCC:2.4V-3.6V ②GND:Ground ③SCL:Serial Clock ④SDA:Serial Data ⑤ADDR: I²C Address Select
TEMT6000 Pinout
①OUT:AOUT(ADC) ②VCC:3.3V-5.5V ③GND:Ground
OPT101 Pinout
①VCC: +2.7V – 36V ②GND: Ground ③1M: 1MΩ Resistor ④OUT: ADC ⑤-V: Ground or Vcc- ⑥COM:Ground
How to check if a light sensor is working?
For this demonstration, we will use an Arduino Uno and a BH1750. Alternatively, any microcontroller and light sensor capable of data interaction can be used.
Open the Arduino IDE on your computer, connect the Arduino Uno to your PC, and select the correct serial port, as shown in the figure.
Next, connect the SCL and SDA pins of the BH1750 to the corresponding interfaces on the Arduino Uno. Enter the following code on your computer, download the BH1750 library, and upload the code.
#include
#include
BH1750 lightSensor;
void setup() {
Serial.begin(9600);
Wire.begin();
if (lightSensor.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
Serial.println("BH1750 initialized successfully");
} else {
Serial.println("Error initializing BH1750");
while (1); // STOP
}
}
void loop() {
float lux = lightSensor.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);
}
Once the upload is complete, open the Serial Monitor, and you will see the current data. This data will change with the light intensity. If the data changes normally, the device is ready for use.
A simple application example of a light sensor
FAQ
Can you put a sensor on an existing light?
Certainly, it’s not difficult to install a light sensor on an existing lamp. You need to determine the voltage used by your lamp, step down the voltage to power the light sensor, and then the light sensor can be directly connected to a MOSFET to control the on/off of the lamp. This setup will allow you to achieve the desired functionality.
What triggers a sensor light?
The ways to trigger a light sensor vary depending on its characteristics. However, in general, any method that affects light brightness will trigger the light sensor. For example, actions such as blocking or illuminating the sensor will trigger it and change its output value.
What is the max value of BH1750?
According to the datasheet, the maximum value of the BH1750 light sensor is 65,535 lux.
What is the sensitivity of the TEMT6000?
The sensitivity of the TEMT6000 is not fixed; instead, it refers to the slope of its characteristic curve. Under a standard illuminance of 100 lux, the typical collector current is 10μA.

