ZMPT101B Arduino: Measure AC Mains Voltage (RMS) Safely
ZMPT101B Arduino: measure 230 V AC through an isolating transformer, RMS formula, trimmer calibration, Uno, ESP32 and Pico code, power with ACS712, safety.
The ZMPT101B with Arduino is the most common way to measure the 220–240 V AC voltage at a wall socket. The ZMPT101B is a tiny voltage transformer that turns the mains voltage into a small current and passes that current to an electrically isolated secondary winding. The op-amp on the module amplifies this signal into a small sine wave swinging around 2.5 V, and the Arduino samples that sine quickly and calculates its RMS value. In the end you read the same "229 V" a multimeter shows, in your own circuit.
In this guide you'll see step by step how the module works, why a plain analogRead() value doesn't give you the voltage, and the RMS formula. We'll also cover setting the gain with the trimmer, software calibration with a multimeter, code for the Arduino Uno, ESP32 and Raspberry Pi Pico, and measuring watts, VA and power factor together with the ACS712 current sensor. But first the most important topic: safety.
What is the ZMPT101B and how does it work?
Inside the ZMPT101B is a small transformer with 1000:1000 turns that transfers current, not voltage. The series resistor on the module drops 230 V to a current of a few milliamps, and this current flows through the primary winding. The same current appears in the secondary winding, flows through a burden resistor and becomes a small AC voltage. The LM358 op-amp amplifies this voltage by a ratio set with the trimmer and centres it at half the supply voltage (2.5 V at 5 V). That way the Arduino's ADC, which can only read 0–5 V, sees the sine swinging in the negative direction too without any problem. The real benefit of the transformer is galvanic isolation: the Arduino side isn't electrically connected to the mains. The 230 V you read at the socket is an RMS (effective) value: it equals the DC voltage that produces the same heat. For a pure sine the peak is √2 times the RMS, so 230 V RMS means 325 V peak and 650 V peak to peak. When the Arduino reads one instant value it sees just that point of the sine; to find the voltage you need hundreds of samples across the period and take the square root of the mean of their squares. The second table below shows the mains values of some countries and the peak values to expect in code.
| Feature | Value | Explanation |
|---|---|---|
| Measuring range (module) | 0–250 V AC | Set by the module's series resistor |
| Transformer ratio | 2 mA : 2 mA (1000:1000 turns) | Current-type voltage transformer |
| Isolation voltage | 4000 V (datasheet) | The board layout doesn't guarantee this |
| Frequency | 50–60 Hz | Europe 50 Hz, the Americas mostly 60 Hz |
| Supply | 5 V | At 3.3 V the op-amp output clips |
| Output | Analog sine around VCC/2 | About 2.5 V midpoint at 5 V supply |
| Adjustment | Multi-turn trimmer | Changes the op-amp gain |
| Country / region | Nominal RMS | Peak | Frequency |
|---|---|---|---|
| Turkey, European Union, United Kingdom | 230 V | ~325 V | 50 Hz |
| Argentina, Chile | 220 V | ~311 V | 50 Hz |
| Mexico | 127 V | ~180 V | 60 Hz |
| USA, Canada | 120 V | ~170 V | 60 Hz |
| Japan | 100 V | ~141 V | 50 / 60 Hz |
ZMPT101B wiring and pin table
The module has two sides. The high-voltage side with the screw terminal is connected in parallel with the live (L) and neutral (N) lines, i.e. across the two contacts of the socket you want to measure. The low-voltage side with pins goes to the microcontroller through VCC, GND and OUT. The Arduino Uno runs at 5 V, so OUT goes straight to A0. The ADCs of the ESP32 and Pico accept at most 3.3 V; still power the module from 5 V, but scale its output by 2/3 with a voltage divider made of 10 kΩ (top) and 20 kΩ (bottom) resistors. You can check the divider values with the voltage divider calculator.
| Connection | Arduino Uno | ESP32 | Raspberry Pi Pico |
|---|---|---|---|
| ZMPT101B VCC | 5V | 5V (VIN) | VBUS (5 V) |
| ZMPT101B GND | GND | GND | GND |
| ZMPT101B OUT | A0 (direct) | GPIO34 (10k/20k divider) | GP26 / ADC0 (10k/20k divider) |
| ACS712 VCC / GND | 5V / GND | 5V / GND | VBUS / GND |
| ACS712 OUT | A1 (direct) | GPIO35 (10k/20k divider) | GP27 / ADC1 (10k/20k divider) |
| ZMPT101B L / N terminal | Live and neutral, after the fuse | Same | Same |
Setting the gain with the trimmer (potentiometer calibration)
- Upload the waveform sketch below and, before plugging in, open the Serial Plotter (Tools menu) at 115200 baud; you should see a flat line around 512.
- With the plug still out, set the trimmer to its middle position, close the box and plug the circuit in.
- You should now see a sine swinging around 512 in the Serial Plotter. If the top or bottom of the wave is cut off flat, the gain is too high.
- Unplug, turn the trimmer a little and try again. The goal is a clean, uncut sine of about 400 counts peak to peak (about 2 V).
- If the wave is very small (under 100 counts peak to peak) the resolution drops; raise the gain a little.
- Once you're done, don't touch the trimmer again; if you turn it you'll have to redo the software calibration.
1// ZMPT101B dalga şekli: trimpot ayarı için Seri Çizici (Serial Plotter) görünümü
2// ZMPT101B waveform: Serial Plotter view for adjusting the trimmer
3const int ZMPT_PIN = A0;
4const int SAMPLES = 100;
5int buf[SAMPLES];
6
7void setup() {
8 Serial.begin(115200);
9}
10
11void loop() {
12 // ~500 µs arayla 100 örnek = ~50 ms (50 Hz'de 2,5 periyot) / 100 samples ~500 µs apart = ~50 ms
13 for (int i = 0; i < SAMPLES; i++) {
14 buf[i] = analogRead(ZMPT_PIN);
15 delayMicroseconds(380); // analogRead ~112 µs + 380 µs bekleme / ~112 µs read + 380 µs wait
16 }
17 for (int i = 0; i < SAMPLES; i++) {
18 // Alt ve Ust sabit çizgileri ekseni sabitler / fixed lines keep the axis steady
19 Serial.print(F("Alt:0,Ust:1023,ZMPT:"));
20 Serial.println(buf[i]);
21 }
22 delay(200);
23}Why 2 V peak to peak? At a 5 V supply the LM358 op-amp can only drive its output up to about 3.5 V. Because the midpoint is 2.5 V, if the sine's upward amplitude goes beyond 1 V the peaks flatten and the RMS value reads lower than it really is. A 2 V peak-to-peak sine stays below that limit and gives about 145 counts RMS on the Uno's 10-bit ADC, which is enough resolution with each count worth around 1.6 V.
Sampling and the RMS calculation
The RMS calculation has three steps: find the midpoint (the DC offset), subtract it from each sample and square the result, then take the square root of the mean of the squares. The code uses a 200 ms window because 200 ms is exactly 10 periods at 50 Hz and exactly 12 at 60 Hz; a window that ends half way through a period makes the reading jump. Sampling every 250 µs means 4000 samples per second, 80 samples per 50 Hz period; the Uno's analogRead(), which takes about 112 µs, keeps up with this easily.
| Quantity | Formula | Note |
|---|---|---|
| Midpoint (DC offset) | offset = mean(x) | ~512 at 5 V supply (10-bit) |
| Instant AC value | a = x − offset | Takes positive and negative values |
| RMS (ADC counts) | √( mean(a²) ) | Square, mean, root |
| Voltage (V) | V = RMS × K | K: calibration factor (V/count) |
| Peak | Vpeak = Vrms × √2 | 230 V → 325 V |
| Samples per period | fs ÷ f | 4000 ÷ 50 = 80 |
| Window | Whole number of periods | 200 ms = 10 × 20 ms = 12 × 16.7 ms |
Arduino code to measure AC voltage
1// ZMPT101B ile AC gerilim (RMS) ölçümü - Arduino Uno / Nano
2// AC mains voltage (RMS) with ZMPT101B - Arduino Uno / Nano
3const int ZMPT_PIN = A0;
4const float CAL_FACTOR = 1.59; // V / ADC birimi, multimetreyle bul / V per ADC count, find with a multimeter
5const unsigned long WINDOW_US = 200000; // 200 ms: 50 Hz'de 10, 60 Hz'de 12 tam periyot / 10 cycles at 50 Hz, 12 at 60 Hz
6const unsigned long SAMPLE_US = 250; // 4 kHz örnekleme / 4 kHz sampling
7const float NOISE_FLOOR_V = 10.0; // bunun altını 0 göster / show 0 below this
8
9int offsetGuess = 512; // orta nokta tahmini, her pencerede güncellenir / midpoint guess, updated every window
10
11float readRmsCounts() {
12 long sum = 0; // (x - offsetGuess) toplamı / sum of (x - offsetGuess)
13 long sumSq = 0; // karelerin toplamı / sum of squares
14 unsigned int n = 0;
15 unsigned long start = micros();
16 unsigned long next = start;
17 while (micros() - start < WINDOW_US) {
18 if ((long)(micros() - next) >= 0) { // eşit aralıklı örnek / evenly spaced samples
19 next += SAMPLE_US;
20 int x = analogRead(ZMPT_PIN) - offsetGuess;
21 sum += x;
22 sumSq += (long)x * x;
23 n++;
24 }
25 }
26 float mean = (float)sum / n; // kalan DC kayma / remaining DC offset
27 offsetGuess += (int)round(mean); // sonraki pencere için / for the next window
28 float variance = (float)sumSq / n - mean * mean; // AC bileşenin karesinin ortalaması / mean square of the AC part
29 return variance > 0 ? sqrt(variance) : 0;
30}
31
32void setup() {
33 Serial.begin(115200);
34 Serial.println(F("ZMPT101B RMS olcer / RMS meter"));
35}
36
37void loop() {
38 float counts = readRmsCounts();
39 float volts = counts * CAL_FACTOR;
40 if (volts < NOISE_FLOOR_V) volts = 0; // şebeke yokken gürültüyü gizle / hide noise without mains
41 Serial.print(F("Ham RMS / Raw RMS: "));
42 Serial.print(counts, 2);
43 Serial.print(F(" Gerilim / Voltage: "));
44 Serial.print(volts, 1);
45 Serial.println(F(" V"));
46 delay(300);
47}To save memory, readRmsCounts() doesn't store the samples in an array; it adds each one to the sums as soon as it arrives. Because it can't know the midpoint in advance it starts with a guess of 512, then at the end of the window it finds the small remaining offset from the mean and corrects the guess for the next window. The formula variance = mean(a²) − mean(a)² gives the right result even when the guess isn't exact. The sums are of type long: a value of ±512 squared is 262,144, and with 800 samples the total reaches about 210 million, comfortably below the long limit of 2.1 billion. NOISE_FLOOR_V shows the few volts of noise you see with the plug pulled as zero.
Software calibration: finding the factor with a multimeter
Once the trimmer is set, you need to find CAL_FACTOR. Open the Serial Monitor and note the "Raw RMS" value, for example 144.6. At the same time measure the voltage at the same socket with a multimeter on its AC voltage range, for example 229.4 V. The factor is 229.4 ÷ 144.6 = 1.586; write CAL_FACTOR = 1.586 in the code and upload again. Repeating the measurement a few times at different times of day and averaging improves the factor, because the mains voltage moves a few volts during the day. A well-calibrated ZMPT101B circuit measures within ±1–2%; for better than that your multimeter also needs to be "true RMS". If you're new to multimeters, see how to use a multimeter.
Using the ZMPT101B with the ESP32
There are three differences on the ESP32. First the 3.3 V limit: the module is powered from 5 V, the output is scaled with the 10k/20k divider, so the 2.5 V midpoint becomes about 1.67 V at the pin and the LM358's 3.5 V ceiling drops to 2.33 V. Second the choice of ADC: ADC2 pins can't be used while Wi-Fi is on, so pick an ADC1 pin between GPIO32 and 39. Third linearity: the ESP32's ADC isn't linear near the ends of its range; analogReadMilliVolts() returns a millivolt value corrected with the chip's calibration data, so it gives a more accurate RMS than the raw value. If you want to send the reading to the cloud, you can add the method from the ESP32 ThingSpeak or ESP32 MQTT Home Assistant guides to this code.
1// ZMPT101B + ESP32: OUT -> 10k/20k gerilim bölücü -> GPIO34 (ADC1)
2// ZMPT101B + ESP32: OUT -> 10k/20k voltage divider -> GPIO34 (ADC1)
3const int ZMPT_PIN = 34; // yalnız giriş, ADC1 / input only, ADC1
4const float CAL_FACTOR = 0.49; // şebeke V / pin mV (RMS), kalibrasyonla bul / mains V per pin mV (RMS)
5const unsigned long WINDOW_US = 200000; // 200 ms pencere / 200 ms window
6const unsigned long SAMPLE_US = 250; // 4 kHz
7const float NOISE_FLOOR_V = 10.0;
8
9int offsetGuess = 1667; // orta nokta tahmini: 2,5 V x 2/3 = ~1667 mV / midpoint guess in mV
10
11float readRmsMilliVolts() {
12 int64_t sum = 0;
13 int64_t sumSq = 0;
14 uint32_t n = 0;
15 unsigned long start = micros();
16 unsigned long next = start;
17 while (micros() - start < WINDOW_US) {
18 if ((long)(micros() - next) >= 0) {
19 next += SAMPLE_US;
20 // analogReadMilliVolts kalibre edilmiş mV verir (varsayılan 11 dB) / calibrated mV (default 11 dB)
21 int x = (int)analogReadMilliVolts(ZMPT_PIN) - offsetGuess;
22 sum += x;
23 sumSq += (int64_t)x * x;
24 n++;
25 }
26 }
27 float mean = (float)sum / n;
28 offsetGuess += (int)roundf(mean);
29 float variance = (float)sumSq / n - mean * mean;
30 return variance > 0 ? sqrtf(variance) : 0;
31}
32
33void setup() {
34 Serial.begin(115200);
35 analogReadResolution(12);
36 Serial.println(F("ESP32 ZMPT101B hazir / ready"));
37}
38
39void loop() {
40 float mv = readRmsMilliVolts();
41 float volts = mv * CAL_FACTOR;
42 if (volts < NOISE_FLOOR_V) volts = 0;
43 Serial.printf("Pin RMS: %.1f mV Gerilim / Voltage: %.1f V\n", mv, volts);
44 delay(500);
45}Measuring with the Raspberry Pi Pico and MicroPython
The Pico's ADC is 12-bit, but read_u16() in MicroPython scales the value to 0–65535. The wiring is the same as on the ESP32: the module gets 5 V from VBUS and its output goes to GP26 through the 10k/20k divider. MicroPython integers don't overflow, so there's no type worry for the sums; even though the loop is interpreted, 4 kHz is easy to hold on the Pico's 125 MHz processor. Keeping the sample timing with time.ticks_us() and ticks_diff() works correctly even when the counter wraps around.
1# ZMPT101B + Raspberry Pi Pico (MicroPython): OUT -> 10k/20k bölücü -> GP26 (ADC0)
2# ZMPT101B + Raspberry Pi Pico (MicroPython): OUT -> 10k/20k divider -> GP26 (ADC0)
3from machine import ADC
4import time
5import math
6
7adc = ADC(26) # GP26 = ADC0
8CAL_FACTOR = 0.0246 # V / ADC birimi (read_u16 0-65535), kalibrasyonla bul / V per count, calibrate
9WINDOW_US = 200000 # 200 ms pencere / 200 ms window
10SAMPLE_US = 250 # 4 kHz
11NOISE_FLOOR_V = 10
12
13offset = 33100 # orta nokta tahmini (~1,67 V) / midpoint guess (~1.67 V)
14
15
16def rms_counts():
17 global offset
18 s = 0
19 s2 = 0
20 n = 0
21 start = time.ticks_us()
22 nxt = start
23 while time.ticks_diff(time.ticks_us(), start) < WINDOW_US:
24 if time.ticks_diff(time.ticks_us(), nxt) >= 0:
25 nxt = time.ticks_add(nxt, SAMPLE_US)
26 x = adc.read_u16() - offset
27 s += x
28 s2 += x * x
29 n += 1
30 mean = s / n
31 offset += int(mean) # sonraki pencere için / for the next window
32 var = s2 / n - mean * mean
33 return math.sqrt(var) if var > 0 else 0
34
35
36while True:
37 c = rms_counts()
38 v = c * CAL_FACTOR
39 if v < NOISE_FLOOR_V:
40 v = 0
41 print("Ham RMS / Raw RMS: {:.1f} Gerilim / Voltage: {:.1f} V".format(c, v))
42 time.sleep_ms(300)Power measurement with the ACS712: watts, VA and power factor

Now that you know the voltage, you can go one step further and measure the power a device draws. For that you cut the live wire and run it through the ACS712's IP+ and IP− terminals, in series with the load. Apparent power S = Vrms × Irms is simply a product; but in devices with motors or adapters the current doesn't peak at the same moment as the voltage, so the real power P that shows up on your bill is smaller. To find real power you take voltage and current samples at the same time and average their product: P = mean(v × i). Power factor is then PF = P ÷ S; it's close to 1 for resistive loads like heaters and incandescent bulbs, and between 0.5 and 0.8 for motors and cheap adapters. For details on the ACS712, see the ACS712 current sensor guide.
| ACS712 version | Sensitivity | I_CAL (Uno, 5 V) | Value of one ADC count |
|---|---|---|---|
| ACS712-5A | 185 mV/A | 0.0264 | ~26 mA (~6 W at 230 V) |
| ACS712-20A | 100 mV/A | 0.0488 | ~49 mA (~11 W) |
| ACS712-30A | 66 mV/A | 0.0740 | ~74 mA (~17 W) |
1// ZMPT101B (A0) + ACS712-5A (A1): Vrms, Irms, gerçek güç, görünür güç, güç faktörü
2// ZMPT101B (A0) + ACS712-5A (A1): Vrms, Irms, real power, apparent power, power factor
3const int V_PIN = A0;
4const int I_PIN = A1;
5const float V_CAL = 1.59; // V / ADC birimi (gerilim kalibrasyonu) / V per count (voltage calibration)
6const float I_CAL = 0.0264; // A / ADC birimi: (5 V / 1024) / 0,185 V/A (ACS712-5A) / A per count
7const unsigned long WINDOW_US = 200000;
8const unsigned long SAMPLE_US = 300; // iki analogRead için yeterli süre / enough time for two reads
9const float I_NOISE_A = 0.08; // bunun altını 0 say / treat below this as 0
10
11int vOff = 512, iOff = 512;
12
13void setup() {
14 Serial.begin(115200);
15 Serial.println(F("ZMPT101B + ACS712 guc olcer / power meter"));
16}
17
18void loop() {
19 long sV = 0, sI = 0, sVV = 0, sII = 0, sVI = 0;
20 unsigned int n = 0;
21 unsigned long start = micros(), next = start;
22 while (micros() - start < WINDOW_US) {
23 if ((long)(micros() - next) >= 0) {
24 next += SAMPLE_US;
25 int v = analogRead(V_PIN) - vOff; // gerilim örneği / voltage sample
26 int i = analogRead(I_PIN) - iOff; // akım örneği (~112 µs sonra) / current sample (~112 µs later)
27 sV += v; sI += i;
28 sVV += (long)v * v;
29 sII += (long)i * i;
30 sVI += (long)v * i;
31 n++;
32 }
33 }
34 float mV = (float)sV / n, mI = (float)sI / n;
35 vOff += (int)round(mV);
36 iOff += (int)round(mI);
37
38 float vVar = (float)sVV / n - mV * mV;
39 float iVar = (float)sII / n - mI * mI;
40 float vrms = (vVar > 0 ? sqrt(vVar) : 0) * V_CAL;
41 float irms = (iVar > 0 ? sqrt(iVar) : 0) * I_CAL;
42 float realP = ((float)sVI / n - mV * mI) * V_CAL * I_CAL; // P = ortalama(v*i) / mean(v*i)
43
44 if (irms < I_NOISE_A) { irms = 0; realP = 0; }
45 float apparentS = vrms * irms; // S = Vrms * Irms
46 float pf = apparentS > 1.0 ? realP / apparentS : 0; // PF = P / S
47
48 Serial.print(F("V: ")); Serial.print(vrms, 1);
49 Serial.print(F(" V I: ")); Serial.print(irms, 3);
50 Serial.print(F(" A P: ")); Serial.print(realP, 1);
51 Serial.print(F(" W S: ")); Serial.print(apparentS, 1);
52 Serial.print(F(" VA PF: ")); Serial.println(pf, 2);
53 delay(500);
54}Because the code does two analogRead() calls in a row, the current sample is taken about 112 µs after the voltage sample; at 50 Hz that's a phase shift of about 2 degrees, which changes the power factor by less than a thousandth. As the table shows, even the ACS712-5A gives a resolution of about 26 mA per ADC count on the Uno; the 0.04 A drawn by a 10 W LED bulb sits right at the noise floor. This sensor suits loads of 100 W and up. If you want a ready, calibrated solution, the PZEM-004T energy meter, which measures voltage, current, power and energy in one module, is a more practical choice.
ZMPT101B project ideas
- Mains monitor display: show the voltage on a 16x2 LCD and warn when it drops below 200 V (I2C LCD display).
- Power cut logger: write the time to an SD card when the voltage drops to zero (SD card module).
- Over- and under-voltage protection: cut a device off with a relay when the voltage leaves 190–250 V (relay module).
- Smart plug: measure both voltage and power with an ESP32 and watch them on your phone (ESP32 smart plug).
- A school experiment that draws the sine in the Serial Plotter to show the difference between AC and DC (AC vs DC current).
Common mistakes and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| 0 V or a few volts even when plugged in | Gain too low or OUT on the wrong pin | Check the sine in the Serial Plotter, raise the trimmer |
| Reading really low, top of the sine flat | Op-amp output saturated (clipping) | Lower the gain with the trimmer, aim for ~2 V peak to peak |
| Readings jump by ±10 V | Window not a whole number of periods or uneven sampling | Use the 200 ms window and fixed-interval sampling |
| 5–8 V shown with the plug pulled | ADC noise | Use the NOISE_FLOOR_V threshold, shorten the wires |
| Values not linear on the ESP32 | Raw analogRead and no divider | Add the divider, use analogReadMilliVolts() |
| Power factor above 1 or negative | ACS712 connected backwards or wrong calibration | Swap IP+ and IP−, check V_CAL and I_CAL |
| Reading drifts after turning the trimmer | The gain has changed | Find CAL_FACTOR again with the multimeter |
| Nonsense value like 100 V or 400 V | Wrong calibration factor | Recalibrate on the same extension lead as the multimeter; 215–240 V is normal on a 230 V supply |
If you'd like to try the basics of analog reading and showing values on an LCD at safe low voltage first, the digital voltmeter with LCD, I2C LCD and 220 V bulb with a relay projects in the BlueGrays app walk you through every step with a circuit diagram and ready-made code; adding ZMPT101B measurement on top of that foundation is much easier.
Frequently asked questions
What is the ZMPT101B used for?
The ZMPT101B is a small current-type voltage transformer used to measure AC voltages such as the mains. As a module, it turns 230 V into an isolated sine between 0 and 5 V that an Arduino can read. The code then calculates the RMS voltage from that sine.
What voltage can the ZMPT101B measure?
Common ZMPT101B modules are designed to measure up to 250 V AC, which covers 220–240 V and 110–127 V mains. The transformer itself can work at higher voltages with a suitable series resistor, but the ready-made module's resistor is chosen for this range.
How do you calibrate the ZMPT101B?
First you use the trimmer to get a clean, uncut sine of about 2 V peak to peak. Then you measure the voltage at the same socket with a multimeter and divide it by the raw RMS value from the code; the result is your calibration factor. You have to repeat this every time the trimmer is turned.
Can the ZMPT101B be used with an ESP32?
Yes. Power the module from 5 V and bring its output under the 3.3 V limit with a divider of 10 kΩ and 20 kΩ resistors. Use an ADC1 pin such as GPIO34 so it doesn't clash with Wi-Fi, and read it with analogReadMilliVolts().
Can the ZMPT101B measure DC voltage?
No. The ZMPT101B is a transformer and only passes a changing voltage; with DC you only see the midpoint at its output. To measure DC voltage use a voltage divider or a sensor such as the INA219.
How do you measure home power consumption with Arduino?
You can use a ZMPT101B for voltage and an ACS712 for current, then multiply simultaneous samples to calculate real power. An easier, pre-calibrated route is the PZEM-004T module, which reports voltage, current, power and kWh over serial. Either way, the mains side must be in an insulated enclosure.
Projects to build after reading this
See all projects
Digital Voltmeter with LCD Display
Find out how much voltage a battery or power adapter gives with a meter you built yourself.

Lighting 220V Bulb with Push Button
As long as you hold the button, a real 220-volt bulb stays lit, and it goes out the moment you let go.

Lighting 220V Bulb with Button (On-Off)
Want to switch a real household bulb on and off with a tiny button? Each time you press the button, the Arduino flips a relay and the bulb lights up; press again and it goes off.

Lighting 220V Bulb with Remote Control
Switch a real light bulb in your home on and off with a TV remote, without getting up from the sofa.

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…

ESP32 I2C LCD Display (16x2)
In this project we connect a 16x2 character LCD to the ESP32 over I2C and display text. With I2C, just 2 data pins (SDA and SCL) control the screen, instead of the 6+ pins a classic parallel connection wastes. The code prints a fixed message on the first line and a counter that goes up every second on the second. At startup an I2C scanner also prints the display's address to the Serial Monitor (usually 0x27 or 0x3F).

ESP32 Wi-Fi STA Connection (with LCD Screen)
In this project, we connect the ESP32 to the home Wi-Fi network in Station (STA) mode in a secure, fault-tolerant manner. We store the SSID and password in a separate secrets.h file to prevent leaking to Git, set up an auto-reconnect mechanism, and display the RSSI signal level and IP address on an I2C LCD screen. The internal LED works as a status indicator. It is a production-grade connection manager.

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.
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, ESP8266, Pico, mBot and micro:bit 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

