BH1750 Arduino Light Sensor: Measure Lux with I2C (Full Guide)
BH1750 Arduino lux sensor guide: I2C wiring, measurement modes, BH1750 vs LDR, an auto night light and classroom light meter, with Uno, ESP32 and Pico code.
The BH1750 is a 16-bit digital light sensor that measures ambient light directly in lux (lx) and talks over I2C. Wiring a BH1750 to Arduino takes just four wires, and instead of a raw voltage the sensor gives you a factory-calibrated, meaningful lux value. So when you want to truly measure light rather than just tell "dark or bright", for example to check whether a classroom is bright enough or how much light a plant gets during the day, it's the go-to module.
It's usually sold as the GY-302, a small board with a 3.3 V regulator and I2C pull-up resistors. In this post you'll learn how the sensor works, what lux means in everyday life, how it differs from an LDR, the measurement modes, and how to wire it to an Arduino Uno, ESP32 and Raspberry Pi Pico. Then we'll build two real applications: an automatic night light protected against flickering on and off, and a classroom light meter that grades the lighting against standard values.
What is the BH1750 and how does it work?
The BH1750 is an ambient light sensor made by ROHM. Inside it has a photodiode, an amplifier that turns the photodiode current into a voltage, a 16-bit analog-to-digital converter (ADC) and an I2C interface. The photodiode's spectral response is close to the human eye, peaking at about 560 nm in the green-yellow region; it largely ignores infrared light, so the value it reads resembles the brightness your eye perceives. The sensor is also designed to reject 50/60 Hz mains flicker, so readings don't jump under fluorescent or LED lamps. By default the 16-bit raw number is divided by 1.2 to get lux: for example, a raw value of 600 means 600 / 1.2 = 500 lux. The library does this calculation for you.
| Feature | Value |
|---|---|
| Chip | ROHM BH1750FVI |
| Measurement range | About 1–54,600 lx by default (raw 0–65,535); 0.11–100,000 lx with the MTreg setting |
| Resolution | 0.5 lx, 1 lx or 4 lx (depends on mode) |
| ADC | 16-bit |
| Accuracy | Typically ±20% |
| Measurement time | About 120 ms (high resolution), 16 ms (low resolution) |
| Supply | Chip 2.4–3.6 V; GY-302 module 3–5 V |
| Current | About 120 µA while measuring, about 0.01 µA asleep |
| Interface | I2C, up to 400 kHz |
| I2C address | 0x23 (ADDR low or floating), 0x5C (ADDR high) |
| Pins | VCC, GND, SCL, SDA, ADDR |
What is lux? Everyday values
Lux is the unit of light falling on a surface: 1 lux is 1 lumen of luminous flux per square metre (1 lx = 1 lm/m²). The key point is that lux describes the light reaching the surface you measure, not the lamp itself. The same lamp can give 500 lux on a desk and 120 lux on a wall two metres away, because the light from a point source falls off with the square of the distance. Our eyes also work logarithmically: going from 50 to 100 lux feels far more noticeable than going from 1000 to 1050 lux. The table below helps you interpret the numbers you read from the sensor.
| Environment | Approximate illuminance |
|---|---|
| Full moon on a clear night | 0.1–0.3 lx |
| Night light, dim hallway | 5–50 lx |
| Under a street lamp | 10–20 lx |
| Living room at home | 50–200 lx |
| Office, classroom | 300–500 lx |
| Outdoors on an overcast day | 1000–10,000 lx |
| Shade on a sunny day | 10,000–25,000 lx |
| Direct sunlight | 32,000–100,000 lx |
BH1750 vs LDR: what's the difference?
An LDR (photoresistor) is a simple component whose resistance drops as light increases. You connect it to an analog pin with a voltage divider and get a number from 0 to 1023; that number depends on the LDR type, the series resistor value, the supply voltage and the temperature. So two different LDRs can show different values in the same room, and you have to calibrate each one separately to convert the value to lux. The BH1750, on the other hand, is factory-calibrated and gives lux directly: two modules give close results in the same light. In return, an LDR is very cheap, works with any board that has an analog pin, and is still enough for simple projects that only need to detect darkness. Another downside of an LDR is that it's slow: when going from light to dark, its resistance can take hundreds of milliseconds or even seconds to settle.
| Feature | BH1750 | LDR |
|---|---|---|
| Output | Digital, directly in lux | Analog, resistance change |
| Calibration | Not needed | Needed for lux |
| Connection | I2C (SDA, SCL) | Analog pin and series resistor |
| Range | 1–54,600 lx (default) | Relative, not linear |
| Spectral response | Close to the human eye | Varies by type |
| Several on the same bus | 2 (0x23 and 0x5C) | A separate analog pin for each |
| Suitable project | Measuring, logging, lighting control | Simple dark/bright detection |
BH1750 wiring: Arduino Uno, ESP32 and Pico
| BH1750 pin | Arduino Uno | ESP32 | Raspberry Pi Pico |
|---|---|---|---|
| VCC | 5V or 3.3V | 3V3 | 3V3(OUT) (pin 36) |
| GND | GND | GND | GND (pin 38) |
| SCL | A5 | GPIO 22 | GP5 (pin 7) |
| SDA | A4 | GPIO 21 | GP4 (pin 6) |
| ADDR | Floating or GND (0x23) | Floating or GND (0x23) | Floating or GND (0x23) |
| Night light LED (with 220 Ω) | D9 | GPIO 25 | GP15 (pin 20) |
| Classroom meter LEDs (red, yellow, green) | D5, D6, D7 | - | - |
Measurement modes: which one should you choose?
| Mode (library name) | Command | Resolution | Measurement time | When to use |
|---|---|---|---|---|
| CONTINUOUS_HIGH_RES_MODE | 0x10 | 1 lx | ~120 ms | General use, default |
| CONTINUOUS_HIGH_RES_MODE_2 | 0x11 | 0.5 lx | ~120 ms | Dim environments, night measurements |
| CONTINUOUS_LOW_RES_MODE | 0x13 | 4 lx | ~16 ms | Fast-changing light, sudden flashes |
| ONE_TIME_HIGH_RES_MODE | 0x20 | 1 lx | ~120 ms | Battery projects, sleeps after measuring |
| ONE_TIME_HIGH_RES_MODE_2 | 0x21 | 0.5 lx | ~120 ms | Battery-powered, dim-light measuring |
| ONE_TIME_LOW_RES_MODE | 0x23 | 4 lx | ~16 ms | Fast measurement at the lowest energy |
In continuous modes the sensor keeps measuring on its own and you read the latest result whenever you like. In one-time modes the sensor takes one measurement and then goes into power-down mode; because its sleep current drops far below 1 µA, it's ideal for battery-powered projects, for example ones that wake every 10 minutes with ESP32 deep sleep. If you want to change the sensitivity further, you can use the measurement time register (MTreg). The default is 69; raising it to 254 increases sensitivity about 3.7 times and lets you go down to 0.11 lux in H2 mode. Lowering it to 31 widens the range beyond 100,000 lux and fixes the problem of the value getting stuck at the ceiling in direct sunlight. In the library you do this with setMTreg(value); the higher the MTreg, the longer the measurement takes, about 440 ms at 254.
Step by step: your first lux measurement with Arduino
- Open the Library Manager in the Arduino IDE, type BH1750 and install the "BH1750" library by Christopher Laws. If you get stuck during installation, see adding Arduino libraries.
- Connect the module's VCC to 5V, GND to GND, SCL to A5 and SDA to A4; leave the ADDR pin floating. The SDA and SCL pins next to AREF on the Uno are the same lines as A4 and A5.
- Upload the code below and open the Serial Monitor at 9600 baud.
- Cover the sensor with your hand, then hold it up to your phone's flashlight: you should see the value jump from a few lux to thousands of lux.
- If the Serial Monitor says "not found", check the wires and the address, and make sure the I2C scanner shows the sensor at 0x23.
1#include <Wire.h>
2#include <BH1750.h>
3
4BH1750 lightMeter; // BH1750 nesnesi / BH1750 object
5
6void setup() {
7 Serial.begin(9600);
8 Wire.begin(); // I2C hattını başlat / start the I2C bus
9 if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE, 0x23)) { // ADDR boş ya da GND / ADDR floating or GND
10 Serial.println(F("BH1750 hazir / ready"));
11 } else {
12 Serial.println(F("BH1750 bulunamadi / not found"));
13 while (true) {} // burada dur / stop here
14 }
15}
16
17void loop() {
18 float lux = lightMeter.readLightLevel(); // lüks cinsinden ölçüm / reading in lux
19 if (lux < 0) { // negatif değer = hata / negative value = error
20 Serial.println(F("Okuma hatasi / Read error"));
21 } else {
22 Serial.print(F("Isik / Light: "));
23 Serial.print(lux, 1);
24 Serial.println(F(" lx"));
25 }
26 delay(500);
27}Wire.begin() starts the I2C bus, and lightMeter.begin() powers up the sensor, sets the mode you chose and returns true on success. readLightLevel() returns the latest measurement in lux as a float; if the value is negative (-1 or -2), the read failed, so it's a good habit to check it before using the value in calculations. In continuous high-resolution mode a new result is ready roughly every 120 ms, so running the loop faster only makes you read the same value again. If you're curious how I2C works, take a look at What is I2C.
Example 1: automatic night light with the BH1750
The most common mistake with a night light is using a single threshold. If you choose a threshold of 15 lux, when the surroundings sit around 14–16 lux, such as at dusk, the lamp switches on and off several times a second. The fix is hysteresis, meaning two separate thresholds: the lamp turns on when the light falls below 10 lux, but only turns off when it rises above 25 lux. In the 15-lux zone in between, the lamp keeps its current state. In the code below we use an LED connected to D9 through a 220 Ω resistor; for a real lamp you can connect a relay module instead of the LED. If you use an LED of a different colour, find the right resistor with the LED resistor calculator.
1#include <Wire.h>
2#include <BH1750.h>
3
4BH1750 lightMeter;
5const int LED_PIN = 9; // LED + 220 ohm direnç / LED + 220 ohm resistor
6const float ON_LUX = 10.0; // bunun altında yak / turn on below this
7const float OFF_LUX = 25.0; // bunun üstünde söndür / turn off above this
8bool lampOn = false;
9
10void setup() {
11 Serial.begin(9600);
12 pinMode(LED_PIN, OUTPUT);
13 Wire.begin();
14 lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE, 0x23);
15}
16
17void loop() {
18 float lux = lightMeter.readLightLevel();
19 if (lux < 0) { // okuma hatası / read error
20 Serial.println(F("Sensor hatasi / Sensor error"));
21 delay(1000);
22 return;
23 }
24 if (!lampOn && lux < ON_LUX) { // karanlık oldu / it got dark
25 lampOn = true;
26 } else if (lampOn && lux > OFF_LUX) { // yeterince aydınlık / bright enough
27 lampOn = false;
28 }
29 digitalWrite(LED_PIN, lampOn ? HIGH : LOW);
30 Serial.print(lux, 1);
31 Serial.print(F(" lx lamba / lamp: "));
32 Serial.println(lampOn ? F("ACIK / ON") : F("KAPALI / OFF"));
33 delay(500);
34}Example 2: classroom lighting measurement
In schools and offices, whether the lighting is adequate is found out by measuring, not guessing. The indoor lighting standard TS EN 12464-1, also used in Turkey (and based on the European EN 12464-1), recommends an average of at least 300 lux on the work surface for general classrooms, and 500 lux for evening classes, adult education and the whiteboard. For an accurate measurement, place the sensor flat on a desk at about 75–80 cm height with its light-sensitive face pointing at the ceiling, and don't cast your own shadow on it. Divide the classroom into an imaginary grid; measure separately at the front, middle, back, and at the desks on the window and corridor sides, then note the average and the lowest value. Because daylight changes the values a lot, repeat the measurement once at noon with the curtains open and once with the curtains closed and only the lamps on. This is also a strong data-collection project for a science fair or a competition.
| Area | Recommended average illuminance (TS EN 12464-1) |
|---|---|
| Corridor | 100 lx |
| General classroom (primary and secondary) | 300 lx |
| Computer room | 300 lx |
| Gym | 300 lx |
| Evening classes and adult education | 500 lx |
| Whiteboard | 500 lx |
| Laboratory | 500 lx |
| Library reading area | 500 lx |
| Technical drawing room | 750 lx |
1#include <Wire.h>
2#include <BH1750.h>
3
4BH1750 lightMeter;
5const int RED_PIN = 5; // yetersiz / too dark
6const int YELLOW_PIN = 6; // sınırda / borderline
7const int GREEN_PIN = 7; // uygun / good
8
9float averageLux(int samples) {
10 float sum = 0;
11 int count = 0;
12 for (int i = 0; i < samples; i++) {
13 float lux = lightMeter.readLightLevel();
14 if (lux >= 0) { // hatalı okumaları atla / skip failed readings
15 sum += lux;
16 count++;
17 }
18 delay(150); // yeni ölçüm ~120 ms'de hazır / a new reading is ready every ~120 ms
19 }
20 if (count == 0) return -1;
21 return sum / count;
22}
23
24void setLeds(bool r, bool y, bool g) {
25 digitalWrite(RED_PIN, r ? HIGH : LOW);
26 digitalWrite(YELLOW_PIN, y ? HIGH : LOW);
27 digitalWrite(GREEN_PIN, g ? HIGH : LOW);
28}
29
30void setup() {
31 Serial.begin(9600);
32 pinMode(RED_PIN, OUTPUT);
33 pinMode(YELLOW_PIN, OUTPUT);
34 pinMode(GREEN_PIN, OUTPUT);
35 Wire.begin();
36 if (!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE_2, 0x23)) { // 0,5 lx çözünürlük / 0.5 lx resolution
37 Serial.println(F("BH1750 bulunamadi / not found"));
38 while (true) {}
39 }
40}
41
42void loop() {
43 float lux = averageLux(20); // yaklaşık 3 sn ortalama / about 3 s average
44 if (lux < 0) {
45 setLeds(false, false, false);
46 Serial.println(F("Okuma hatasi / Read error"));
47 return;
48 }
49 Serial.print(F("Ortalama / Average: "));
50 Serial.print(lux, 1);
51 Serial.print(F(" lx -> "));
52 if (lux < 200) {
53 setLeds(true, false, false);
54 Serial.println(F("Yetersiz / Too dark"));
55 } else if (lux < 300) {
56 setLeds(false, true, false);
57 Serial.println(F("Sinirda / Borderline"));
58 } else if (lux < 500) {
59 setLeds(false, false, true);
60 Serial.println(F("Sinif icin uygun / OK for classroom"));
61 } else {
62 setLeds(false, false, true);
63 Serial.println(F("Tahta ve aksam dersi icin de uygun / OK for board and evening classes"));
64 }
65}BH1750 with the ESP32: an LED that dims with the surroundings
The same BH1750 library works on the ESP32; the only difference is that you specify the I2C pins explicitly with Wire.begin(21, 22). In this example, instead of switching the lamp on and off, we adjust the LED's brightness smoothly according to ambient light: at 0 lux the LED is fully bright, at 200 lux and above it's completely off, and in between it dims linearly. On the ESP32 the PWM signal is generated by the LEDC unit, and this unit's functions changed with Arduino core 3.x; the code is split with an ESP_ARDUINO_VERSION_MAJOR check so it compiles on both versions. You can find the logic of PWM in What is PWM. Thanks to the ESP32's Wi-Fi, you can also send the same measurement to Home Assistant over MQTT and use it in smart home automations.
1#include <Wire.h>
2#include <BH1750.h>
3#include <esp_arduino_version.h>
4
5BH1750 lightMeter;
6const int LED_PIN = 25; // LED + 220 ohm direnç / LED + 220 ohm resistor
7const int PWM_FREQ = 5000; // 5 kHz PWM
8const int PWM_RES = 8; // 8 bit: 0-255
9const float FULL_DARK_LUX = 200.0; // bu değerde LED tamamen söner / LED fully off at this value
10#if ESP_ARDUINO_VERSION_MAJOR < 3
11const int PWM_CHANNEL = 0; // core 2.x için LEDC kanalı / LEDC channel for core 2.x
12#endif
13
14void setupPwm() {
15#if ESP_ARDUINO_VERSION_MAJOR >= 3
16 ledcAttach(LED_PIN, PWM_FREQ, PWM_RES);
17#else
18 ledcSetup(PWM_CHANNEL, PWM_FREQ, PWM_RES);
19 ledcAttachPin(LED_PIN, PWM_CHANNEL);
20#endif
21}
22
23void writePwm(int duty) {
24#if ESP_ARDUINO_VERSION_MAJOR >= 3
25 ledcWrite(LED_PIN, duty);
26#else
27 ledcWrite(PWM_CHANNEL, duty);
28#endif
29}
30
31void setup() {
32 Serial.begin(115200);
33 Wire.begin(21, 22); // SDA, SCL
34 if (!lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE, 0x23, &Wire)) {
35 Serial.println("BH1750 bulunamadi / not found");
36 }
37 setupPwm();
38}
39
40void loop() {
41 float lux = lightMeter.readLightLevel();
42 if (lux >= 0) {
43 float limited = constrain(lux, 0.0f, FULL_DARK_LUX);
44 int duty = (int)(255.0f * (1.0f - limited / FULL_DARK_LUX)); // karanlıkta parlak / bright in the dark
45 writePwm(duty);
46 Serial.printf("%.1f lx -> PWM %d\n", lux, duty);
47 } else {
48 Serial.println("Okuma hatasi / Read error");
49 }
50 delay(200);
51}BH1750 with Raspberry Pi Pico and MicroPython
On the Raspberry Pi Pico you don't even need an extra library to use the BH1750 with MicroPython; the sensor's commands are so simple that you can talk to it directly over I2C. First we send 0x01 (power on), then 0x10 (continuous high resolution). Then on each reading we take 2 bytes from the sensor, combine them into a single 16-bit number and divide by 1.2. In the i2c.scan() output you should see the number 35, which is the decimal equivalent of hexadecimal 0x23; if ADDR is high you'll see 92, which is 0x5C. The code implements the Arduino example's night light with hysteresis using an LED on GP15. If you're new to MicroPython, first take a look at What is the Raspberry Pi Pico.
1from machine import Pin, I2C
2import time
3
4BH1750_ADDR = 0x23 # ADDR boş ya da GND / ADDR floating or GND
5POWER_ON = 0x01 # güç aç komutu / power on command
6CONT_H_RES = 0x10 # sürekli yüksek çözünürlük / continuous high resolution
7
8i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
9print(i2c.scan()) # [35] görmelisin (0x23) / you should see [35] (0x23)
10
11led = Pin(15, Pin.OUT) # LED + 220 ohm direnç / LED + 220 ohm resistor
12
13i2c.writeto(BH1750_ADDR, bytes([POWER_ON]))
14i2c.writeto(BH1750_ADDR, bytes([CONT_H_RES]))
15time.sleep_ms(180) # ilk ölçümü bekle / wait for the first measurement
16
17def read_lux():
18 data = i2c.readfrom(BH1750_ADDR, 2) # 2 bayt oku / read 2 bytes
19 raw = (data[0] << 8) | data[1] # 16 bit ham değer / 16-bit raw value
20 return raw / 1.2 # lükse çevir / convert to lux
21
22lamp_on = False
23while True:
24 lux = read_lux()
25 if not lamp_on and lux < 10: # karanlık oldu / it got dark
26 lamp_on = True
27 elif lamp_on and lux > 25: # yeterince aydınlık / bright enough
28 lamp_on = False
29 led.value(1 if lamp_on else 0)
30 print("{:.1f} lx".format(lux))
31 time.sleep_ms(500)BH1750 project ideas
- Smart curtain: Open and close a curtain or blind automatically with a servo motor based on the lux value.
- Greenhouse light tracking: Measure the light plants get through the day; if light falls short in your smart greenhouse project, switch on the grow lamp.
- Solar tracker: Use two BH1750s at addresses 0x23 and 0x5C to find the direction the light comes from and turn the panel of your solar tracker that way.
- Automatic screen brightness: Adjust the brightness of an OLED display to the ambient light, like on phones.
- Photography light meter: Calculate the exposure value for ISO 100 with the formula EV = log2(lux / 2.5) and show it on a display.
- Classroom light map: Log the measurements to Google Sheets and draw a lighting map of the classroom; it makes a strong data set for a science competition project.
Common mistakes and how to fix them
| Symptom | Likely cause | Fix |
|---|---|---|
| "BH1750 not found", begin() returns false | SDA and SCL swapped, wrong address, or Wire.begin() forgotten | Check the wires, run the I2C scanner, set the address to 0x23 or 0x5C |
| Value stuck around 54,612 | Saturation in direct sunlight (65,535 / 1.2) | Widen the range with setMTreg(31) |
| Value is -1 or -2 | I2C read error or sensor not configured | Check the return of begin(), shorten the wires |
| Value never changes after the first reading | Sensor went to sleep in one-time mode | Use continuous mode or call configure() before each read |
| Readings keep fluctuating | Shadow, hand, sensor held at an angle | Take an average, mount the sensor flat and steady |
| Night light flickers on and off | Single threshold or the sensor sees the lamp | Add hysteresis, move the sensor away from the lamp |
| ESP32 or Pico hangs, I2C error | Module powered from 5 V or wires too long | Power the module from 3V3, keep wires under 30 cm |
The BH1750 easily replaces the LDR in any project where you want to measure light rather than guess it: four wires, one library and lux directly. If simple dark detection is enough, the LDR is still the cheapest solution; but if you need measuring, logging or comparison with a standard, choose the BH1750. In the BlueGrays app you'll find light-related projects such as reading light intensity with an LDR and a night light, ESP32 smart lighting and smart stair lighting, step by step with circuit diagrams and code, and you can easily adapt this post's BH1750 examples to them.
Frequently asked questions
How many lux can the BH1750 measure?
By default the BH1750 measures roughly 1 to 54,600 lux with 1 lux resolution; this comes from dividing the 16-bit raw value (65,535) by 1.2. If you lower MTreg to 31, the range goes beyond 100,000 lux so it can measure direct sunlight. If you raise MTreg to 254 and use H2 mode, you can tell dim light apart down to 0.11 lux.
What is the BH1750 I2C address?
The address is 0x23 when the ADDR pin is left floating or connected to GND, and 0x5C when it's connected to 3.3 V. This lets you put two BH1750s on the same I2C bus. If you need more sensors, you'll need an I2C multiplexer such as the TCA9548A.
Which is better, BH1750 or LDR?
For real measurement the BH1750 is much better; it gives lux directly, needs no calibration and responds similarly to the human eye. An LDR is cheaper and only good enough for simple night lights that just need to detect when darkness begins. If you'll log values or compare them with a standard, choose the BH1750.
Does the BH1750 work at 5 V?
The BH1750 chip runs on 2.4–3.6 V, but modules like the GY-302 have a 3.3 V regulator, so the module can be powered from 3–5 V and connected straight to an Arduino Uno. On the ESP32 and Raspberry Pi Pico you should power the module from the 3V3 pin, so the I2C lines stay at 3.3 V too.
Can the BH1750 be used in sunlight and outdoors?
Yes, but by default in direct sunlight the value gets stuck at about 54,600 lux; you can get past this with setMTreg(31). Use a transparent cover to protect the sensor from rain, but remember the cover absorbs some of the light and adjust results with a correction factor. It's also important not to enclose the board in a black box where it would heat up directly.
Why does my BH1750 reading differ from a lux meter?
The sensor's typical accuracy is ±20%, and the angle of the incoming light and the lamp's colour spectrum also affect the result. Place the sensor at the same spot and angle as the lux meter, compare them under a few different lights, then add the ratio between them to your code as a correction factor. Also make sure your own shadow doesn't fall on the sensor while measuring.
Projects to build after reading this
See all projects
Measuring Light Intensity with an LDR
Want to see how bright your room is as a number? The LDR, a small part that reacts to light, measures the light around it, and the Arduino writes the value to your computer screen every half second.

Night Light with Ldr
A little night light that turns on by itself when it gets dark and goes off when morning comes.

Reading Light Intensity with the ESP32 LDR Module
Real-time monitoring of the LDR module's raw ADC value and relative light percentage calculated from dark and light reference values in the Serial Monitor. This percentage is not a lux measurement. Teaches the module’s calibration logic. It is ideal to complete this before Project 10, as it is used to determine the threshold value.

ESP32 Night Light with LDR
Night light where the LED automatically turns on in the dark and off in the light. The D0 (digital out) pin of the LDR Sensor Module is used - the dark threshold is set with the small potentiometer on the module, the module itself generates the HIGH/LOW output. ESP32 just reads this signal with digitalRead(), the code is very simple.

ESP32 Smart Lighting (PIR + LDR + Relay + OLED)
With an ESP32, a PIR motion sensor, an LDR light sensor and a relay module, we turn your hallway, bathroom or pantry into smart lighting. If the room is already bright, the light stays off even when there is motion, so it never wastes energy during the day. The light stays on for 30 seconds, and the time extends automatically while motion continues.

Smart Stair and Corridor Lighting
Step onto the stairs or into the hallway and the lights come on one step at a time in the direction you are walking.

Using LCD Screen with I2C
Give your Arduino its own screen and make it write its first message. The two-line LCD screen hooks up with just a few wires; a greeting appears on the top line, then a second message on the bottom…

Raspberry Pi Pico PWM LED Fade (Breathing Effect)
The LED doesn't just blink anymore, it breathes! With the Raspberry Pi Pico's PWM (Pulse Width Modulation), the LED's brightness slowly rises and then slowly fades, a calm "breathing" effect like a sleeping laptop's light. You'll learn the machine.PWM class, the 16-bit brightness value from 0–65535 with duty_u16() and the PWM frequency.
More articles
BlueGrays app
Build this circuit step by step on your phone
Wiring diagram, code and parts list on one screen. 500+ Arduino, ESP32 and Pico projects ready to build.
Scan with your phone
Point your camera at the code and your phone's app store opens.
or open the store

