Arduino People Counter: Bidirectional IR Counter with LCD and Web
Build an Arduino people counter: two IR sensors tell entries from exits, track how many are inside, warn when full, with LCD/OLED and an ESP32 web counter.
An Arduino people counter counts the people walking through a door, shows how many are inside and warns you when a limit is passed. The trick is using two sensors: with two infrared sensors placed a few centimetres apart on the outer and inner side of the door, the Arduino checks which one is blocked first and knows whether someone is coming in or going out. One sensor only counts passes; two sensors count entries and exits, and therefore how many people are inside.
In this guide you'll first see the logic of direction detection in a table, then pick sensors, wire everything up and build an Arduino sketch with an LCD and a capacity warning. After that you'll move the counter to an OLED display, turn it into an ESP32 web counter you can watch from your phone with a daily total, and write a MicroPython version for the Raspberry Pi Pico. The logic is the same for a shop, a classroom, a library or an event entrance.
How does a people counter work? Direction detection with two sensors
Let's call the sensors A (outer side) and B (inner side). Someone coming in blocks A first and B a few hundred milliseconds later; someone leaving does the exact opposite. The program follows this order with a state machine: it remembers which sensor fired first, waits for the second one, and after counting it won't start a new count until both sensors are clear. That way someone who lingers in the doorway or turns back isn't counted by mistake.
| Step | What happens | State | Result |
|---|---|---|---|
| 1 | A blocked, B clear | IDLE → OUT_FIRST | Someone is coming from outside |
| 2 | B also blocked while in OUT_FIRST | OUT_FIRST → WAIT_CLEAR | Entry: inside +1 |
| 3 | B blocked, A clear | IDLE → IN_FIRST | Someone is coming from inside |
| 4 | A also blocked while in IN_FIRST | IN_FIRST → WAIT_CLEAR | Exit: inside −1 (never below 0) |
| 5 | The second sensor didn't fire within 1.5 s | → WAIT_CLEAR | Turned back: no count |
| 6 | A and B blocked at the same moment from idle | IDLE → WAIT_CLEAR | Ambiguous: no count |
| 7 | Both sensors clear for 300 ms | WAIT_CLEAR → IDLE | Ready for the next person |
Which sensor should you use?
Door width, ambient light and budget decide. For a narrow room door, two cheap FC-51 infrared obstacle sensors are enough: the output goes LOW when something is in front, and a small potentiometer on the board sets the range. For wide entrances, an E18-D80NK with up to 80 cm of range or a laser and LDR light barrier spanning the doorway is more reliable. You'll find the other options in detail in the distance sensor comparison.
| Sensor | Range | Output | Pros | Cons |
|---|---|---|---|---|
| FC-51 IR obstacle sensor | 2–30 cm (adjustable) | Digital, LOW = blocked | Very cheap, easy | Sunlight and dark clothes affect it |
| E18-D80NK | 3–80 cm | Digital NPN, needs a pull-up | Wide doors, rugged housing | Pricier, needs 5 V |
| Laser + LDR light barrier | Several metres | Analog (LDR) | Wide entrances, fast response | Needs alignment; never aim at eyes |
| 2 × HC-SR04 ultrasonic | 2–400 cm | Pulse width | Not affected by colour | Slow, the two sensors can interfere |
| VL53L0X laser ToF | About 2 m | I2C | Accurate and fast | With two sensors you must change an I2C address |

A laser and LDR light barrier for wide entrances
If the door is wider than 80 cm, or the sensor faces a sunny shop window, a laser light barrier is more stable. Two laser modules go on one side of the doorway and two LDRs at the same height on the other; each LDR forms a voltage divider with a 10 kΩ resistor, and the midpoint goes to an analog pin. While the laser hits the LDR the reading is high, and it drops sharply when someone breaks the beam. The rest of the code stays the same; only the blocked() function compares against a threshold instead of doing a digital read. To find the threshold, first read both values in the Serial Monitor: with the beam on and with your hand blocking it. If you see 850 and 200, for example, pick 500 in between. Never mount the lasers at eye level or point the beam at anyone's eyes; waist height is ideal both for safety and for accurate counting.
1// Lazer + LDR bariyeri: LDR 5V ile A0/A1 arasında, 10 kΩ A0/A1 ile GND arasında
2// Laser + LDR barrier: LDR between 5V and A0/A1, 10 kΩ between A0/A1 and GND
3const int BEAM_OUT = A0; // dış ışın (A), SENSOR_OUT yerine / outer beam (A), replaces SENSOR_OUT
4const int BEAM_IN = A1; // iç ışın (B), SENSOR_IN yerine / inner beam (B), replaces SENSOR_IN
5const int THRESHOLD = 500; // ışın açık ~850, kesilince ~200 / beam on ~850, broken ~200
6
7bool blocked(int pin) {
8 return analogRead(pin) < THRESHOLD; // ışın kesildi / the beam is broken
9}Parts list and wiring
- Arduino Uno or Nano (ESP32 for the web counter, Raspberry Pi Pico for MicroPython)
- 2 × FC-51 infrared obstacle sensors
- 16x2 I2C LCD or a 0.96-inch OLED
- Passive buzzer, red and green LED, 2 × 220 Ω resistors
- Breadboard and jumper wires
| Connection | Arduino Uno | ESP32 | Raspberry Pi Pico |
|---|---|---|---|
| Outer sensor (A) OUT | D2 | GPIO 26 | GP14 |
| Inner sensor (B) OUT | D3 | GPIO 27 | GP15 |
| Sensor VCC | 5V | 3V3 | 3V3 |
| LCD / OLED SDA | A4 | GPIO 21 (optional) | GP4 (optional) |
| LCD / OLED SCL | A5 | GPIO 22 (optional) | GP5 (optional) |
| Buzzer + | D8 | - | - |
| Red / green LED (via 220 Ω) | D9 / D10 | - | GP25 onboard LED (full warning) |
Step-by-step setup
- Wire the sensors as in the table and fix the boards to the door frame at waist height, 10–15 cm apart, facing across the doorway.
- Turn each FC-51's potentiometer to find a range that ignores the opposite wall but always sees a person walking past; the LED on the sensor lights up when it detects something.
- Check the LCD's I2C address (usually 0x27, sometimes 0x3F) and install the LiquidCrystal_I2C library.
- Upload the code, set MAX_PEOPLE to the room's capacity and test by walking in and out a few times. If the count goes the wrong way, swap the A and B wires.
- For the first few days, also keep a manual tally for an hour and compare it with the device. If the gap is big, adjust the mounting height and sensor spacing first, then TIMEOUT_MS and CLEAR_MS.
Arduino code: entry/exit counter with LCD and capacity warning
The sketch doesn't use delay(); it measures time with millis(), so the sensors are read all the time and quick passes aren't missed. The LCD's top line shows how many people are inside and the limit, the bottom line the total number of entries since power-up. When the count reaches the limit, the green LED goes off and the red one lights up; once the limit is exceeded, the buzzer sounds for half a second on every new entry.
1#include <Wire.h>
2#include <LiquidCrystal_I2C.h>
3
4const int SENSOR_OUT = 2; // A: kapının dış tarafı / outer side of the door
5const int SENSOR_IN = 3; // B: kapının iç tarafı / inner side of the door
6const int BUZZER_PIN = 8;
7const int RED_LED = 9;
8const int GREEN_LED = 10;
9const int MAX_PEOPLE = 10; // içeride izin verilen kişi / capacity limit
10const unsigned long TIMEOUT_MS = 1500; // ikinci sensörü bekleme süresi / wait for the second sensor
11const unsigned long CLEAR_MS = 300; // sensörler bu kadar boş kalmalı / both must stay clear this long
12
13LiquidCrystal_I2C lcd(0x27, 16, 2); // adres 0x27 ya da 0x3F / address 0x27 or 0x3F
14
15enum State { IDLE, OUT_FIRST, IN_FIRST, WAIT_CLEAR };
16State state = IDLE;
17unsigned long stateTime = 0;
18int inside = 0; // içerideki kişi / people inside
19unsigned long totalIn = 0; // toplam giriş / total entries
20
21bool blocked(int pin) {
22 return digitalRead(pin) == LOW; // FC-51 engel görünce LOW verir / FC-51 outputs LOW when blocked
23}
24
25void setState(State next) {
26 state = next;
27 stateTime = millis();
28}
29
30void showCount() {
31 lcd.clear();
32 lcd.setCursor(0, 0);
33 lcd.print("Inside: ");
34 lcd.print(inside);
35 lcd.print("/");
36 lcd.print(MAX_PEOPLE);
37 lcd.setCursor(0, 1);
38 lcd.print("Total in: ");
39 lcd.print(totalIn);
40 bool full = inside >= MAX_PEOPLE;
41 digitalWrite(RED_LED, full ? HIGH : LOW);
42 digitalWrite(GREEN_LED, full ? LOW : HIGH);
43}
44
45void setup() {
46 pinMode(SENSOR_OUT, INPUT);
47 pinMode(SENSOR_IN, INPUT);
48 pinMode(RED_LED, OUTPUT);
49 pinMode(GREEN_LED, OUTPUT);
50 lcd.init();
51 lcd.backlight();
52 showCount();
53}
54
55void loop() {
56 bool a = blocked(SENSOR_OUT);
57 bool b = blocked(SENSOR_IN);
58 unsigned long elapsed = millis() - stateTime;
59
60 switch (state) {
61 case IDLE:
62 if (a && !b) setState(OUT_FIRST); // dışarıdan biri geliyor / someone coming in
63 else if (b && !a) setState(IN_FIRST); // içeriden biri geliyor / someone going out
64 else if (a && b) setState(WAIT_CLEAR); // ikisi birden: belirsiz / both at once: ambiguous
65 break;
66
67 case OUT_FIRST:
68 if (b) { // A'dan sonra B: giriş / A then B: entry
69 inside++;
70 totalIn++;
71 showCount();
72 if (inside > MAX_PEOPLE) tone(BUZZER_PIN, 2000, 500); // sınır aşıldı / limit exceeded
73 setState(WAIT_CLEAR);
74 } else if (elapsed > TIMEOUT_MS) {
75 setState(WAIT_CLEAR); // geri döndü, sayma / turned back, no count
76 }
77 break;
78
79 case IN_FIRST:
80 if (a) { // B'den sonra A: çıkış / B then A: exit
81 if (inside > 0) inside--;
82 showCount();
83 setState(WAIT_CLEAR);
84 } else if (elapsed > TIMEOUT_MS) {
85 setState(WAIT_CLEAR);
86 }
87 break;
88
89 case WAIT_CLEAR:
90 if (a || b) setState(WAIT_CLEAR); // hâlâ biri var, süreyi yenile / still someone, restart timer
91 else if (elapsed > CLEAR_MS) setState(IDLE); // kapı boş / doorway is clear
92 break;
93 }
94}The heart of the sketch is the four states inside the switch. OUT_FIRST and IN_FIRST remember which sensor fired first; if the second one doesn't follow within 1.5 seconds, the person is treated as having stopped in the doorway or turned back. WAIT_CLEAR waits after each count until both sensors have been clear for at least 300 ms, which stops the same person being counted twice because of an arm or a bag. For fast-moving crowds you can lower TIMEOUT_MS to 1000 ms, and for slow passages raise it to 2500 ms.

Using an OLED display instead of the LCD
If you want the number big enough to read from across the room, use a 0.96-inch SSD1306 OLED. It connects to the same I2C pins; just remove the LCD lines from the sketch above, replace showCount() with the version below and start the display in setup(). The bar at the bottom shows how much of the capacity is used.
1#include <Adafruit_GFX.h>
2#include <Adafruit_SSD1306.h>
3
4Adafruit_SSD1306 display(128, 64, &Wire, -1);
5// setup() içinde / in setup(): display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
6
7void showCount() {
8 display.clearDisplay();
9 display.setTextColor(SSD1306_WHITE);
10 display.setTextSize(1);
11 display.setCursor(0, 0);
12 display.print(F("INSIDE"));
13 display.setCursor(80, 0);
14 display.print(F("MAX "));
15 display.print(MAX_PEOPLE);
16 display.setTextSize(4); // büyük rakam / big digits
17 display.setCursor(0, 16);
18 display.print(inside);
19 int bar = min(inside, MAX_PEOPLE) * 128 / MAX_PEOPLE; // doluluk çubuğu / occupancy bar
20 display.drawRect(0, 56, 128, 8, SSD1306_WHITE);
21 display.fillRect(0, 56, bar, 8, SSD1306_WHITE);
22 display.display();
23}Live web counter and daily total with the ESP32
The ESP32 takes the same counter to a web page: open the ESP32's IP address on a phone or computer on the same Wi-Fi and the number of people inside updates every second, with the page background turning red when the room is full. The page reads JSON from /api, which you can also hook into another system. Because the ESP32 gets the time from the internet (NTP), it resets the daily total and the inside count by itself at midnight. The basics are in the ESP32 web server and ESP32 NTP guides.
1#include <WiFi.h>
2#include <WebServer.h>
3#include <time.h>
4
5const char* ssid = "AgAdi"; // Wi-Fi adın / your Wi-Fi name
6const char* password = "Sifre123"; // Wi-Fi şifren / your Wi-Fi password
7const char* TZ_INFO = "CET-1CEST,M3.5.0,M10.5.0/3"; // saat dilimi (ör. Madrid) / time zone (e.g. Madrid)
8
9const int SENSOR_OUT = 26; // dış sensör, 3V3 ile besle / outer sensor, powered from 3V3
10const int SENSOR_IN = 27; // iç sensör / inner sensor
11const int MAX_PEOPLE = 20;
12const unsigned long TIMEOUT_MS = 1500;
13
14WebServer server(80);
15enum State { IDLE, OUT_FIRST, IN_FIRST, WAIT_CLEAR };
16State state = IDLE;
17unsigned long stateTime = 0;
18unsigned long lastClockCheck = 0;
19int inside = 0;
20int todayIn = 0; // bugünkü giriş / entries today
21int lastDay = -1;
22
23void setState(State next) { state = next; stateTime = millis(); }
24
25void handleRoot() {
26 server.send(200, "text/html",
27 "<!DOCTYPE html><html><head><meta charset='utf-8'>"
28 "<meta name='viewport' content='width=device-width,initial-scale=1'><title>People counter</title></head>"
29 "<body style='font-family:sans-serif;text-align:center'>"
30 "<p>Inside</p><h1 id='n' style='font-size:64px'>-</h1><p>Entries today: <b id='t'>-</b></p>"
31 "<script>setInterval(function(){fetch('/api').then(function(r){return r.json();}).then(function(d){"
32 "document.getElementById('n').textContent=d.inside+' / '+d.max;"
33 "document.getElementById('t').textContent=d.today;"
34 "document.body.style.background=d.inside>=d.max?'#fcc':'#cfc';});},1000);</script></body></html>");
35}
36
37void handleApi() {
38 String json = "{\"inside\":" + String(inside) + ",\"max\":" + String(MAX_PEOPLE) +
39 ",\"today\":" + String(todayIn) + "}";
40 server.send(200, "application/json", json);
41}
42
43void checkNewDay() {
44 struct tm now;
45 if (!getLocalTime(&now, 0)) return; // saat henüz alınmadı / time not synced yet
46 if (lastDay != -1 && now.tm_yday != lastDay) {
47 todayIn = 0; // gece yarısı sıfırla / reset at midnight
48 inside = 0;
49 }
50 lastDay = now.tm_yday;
51}
52
53void setup() {
54 Serial.begin(115200);
55 pinMode(SENSOR_OUT, INPUT);
56 pinMode(SENSOR_IN, INPUT);
57 WiFi.begin(ssid, password);
58 while (WiFi.status() != WL_CONNECTED) delay(300);
59 Serial.print("IP: ");
60 Serial.println(WiFi.localIP()); // bu adresi tarayıcıda aç / open this address in a browser
61 configTzTime(TZ_INFO, "pool.ntp.org");
62 server.on("/", handleRoot);
63 server.on("/api", handleApi);
64 server.begin();
65}
66
67void loop() {
68 server.handleClient();
69 if (millis() - lastClockCheck > 1000) { // saniyede bir tarih kontrolü / date check every second
70 lastClockCheck = millis();
71 checkNewDay();
72 }
73
74 bool a = digitalRead(SENSOR_OUT) == LOW;
75 bool b = digitalRead(SENSOR_IN) == LOW;
76 unsigned long elapsed = millis() - stateTime;
77 switch (state) {
78 case IDLE:
79 if (a && !b) setState(OUT_FIRST);
80 else if (b && !a) setState(IN_FIRST);
81 else if (a && b) setState(WAIT_CLEAR);
82 break;
83 case OUT_FIRST:
84 if (b) { inside++; todayIn++; setState(WAIT_CLEAR); } // giriş / entry
85 else if (elapsed > TIMEOUT_MS) setState(WAIT_CLEAR);
86 break;
87 case IN_FIRST:
88 if (a) { if (inside > 0) inside--; setState(WAIT_CLEAR); } // çıkış / exit
89 else if (elapsed > TIMEOUT_MS) setState(WAIT_CLEAR);
90 break;
91 case WAIT_CLEAR:
92 if (a || b) setState(WAIT_CLEAR);
93 else if (elapsed > 300) setState(IDLE);
94 break;
95 }
96}Change the time zone to match your region: COT5 for Colombia, CST6 for Mexico City, GMT0BST,M3.5.0/1,M10.5.0 for the UK and EST5EDT,M3.2.0,M11.1.0 for New York. If you don't want the daily total to vanish after a power cut, store it in flash with the ESP32's Preferences library; writing once a minute rather than on every entry protects the flash memory.
Raspberry Pi Pico (MicroPython) version
The same state machine takes only a few lines in MicroPython. The sensors go to GP14 and GP15 and are powered from 3V3; the counts are printed in Thonny's shell, and the onboard LED lights up when the room is full. Calculating time differences with time.ticks_diff() stays correct even when the tick counter wraps around.
1from machine import Pin
2import time
3
4sensor_out = Pin(14, Pin.IN, Pin.PULL_UP) # dış sensör (A) / outer sensor (A)
5sensor_in = Pin(15, Pin.IN, Pin.PULL_UP) # iç sensör (B) / inner sensor (B)
6led = Pin(25, Pin.OUT) # dolu uyarısı (Pico W'de "LED") / full warning ("LED" on Pico W)
7MAX_PEOPLE = 10
8TIMEOUT_MS = 1500
9
10IDLE, OUT_FIRST, IN_FIRST, WAIT_CLEAR = 0, 1, 2, 3
11state = IDLE
12since = time.ticks_ms()
13inside = 0
14
15
16def set_state(new_state):
17 global state, since
18 state = new_state
19 since = time.ticks_ms()
20
21
22while True:
23 a = sensor_out.value() == 0 # LOW = engel / LOW = blocked
24 b = sensor_in.value() == 0
25 elapsed = time.ticks_diff(time.ticks_ms(), since)
26 if state == IDLE:
27 if a and not b:
28 set_state(OUT_FIRST)
29 elif b and not a:
30 set_state(IN_FIRST)
31 elif a and b:
32 set_state(WAIT_CLEAR)
33 elif state == OUT_FIRST:
34 if b:
35 inside += 1
36 print("Giris / In -> iceride / inside:", inside)
37 set_state(WAIT_CLEAR)
38 elif elapsed > TIMEOUT_MS:
39 set_state(WAIT_CLEAR)
40 elif state == IN_FIRST:
41 if a:
42 inside = max(0, inside - 1)
43 print("Cikis / Out -> iceride / inside:", inside)
44 set_state(WAIT_CLEAR)
45 elif elapsed > TIMEOUT_MS:
46 set_state(WAIT_CLEAR)
47 elif state == WAIT_CLEAR:
48 if a or b:
49 set_state(WAIT_CLEAR) # hâlâ biri var / someone is still there
50 elif elapsed > 300:
51 set_state(IDLE)
52 led.value(1 if inside >= MAX_PEOPLE else 0)
53 time.sleep_ms(5)Improving accuracy: common problems and fixes
| Symptom | Cause | Fix |
|---|---|---|
| One person counted twice | Sensors too low, legs seen separately | Move up to waist height, raise CLEAR_MS |
| Two people side by side count as one | The sensor only sees one object | Narrow the entrance to one person, or use ToF / a camera |
| Random counts in daylight | Infrared in sunlight fools the FC-51 | Shade the sensor, reduce the range or switch to a laser barrier |
| People in dark clothes aren't counted | Black fabric absorbs infrared | Raise the range with the trimmer or use a light barrier |
| Entries are counted as exits | A and B are swapped | Swap the wires or the pin definitions |
| The ESP32 page won't open | Phone on another network or 5 GHz Wi-Fi | Join the same 2.4 GHz network, read the IP from the Serial Monitor |
Project ideas built on a people counter
- Automatic room light: when nobody is left inside, a relay switches the light off and turns it back on when the first person walks in.
- Capacity traffic light: a big LED panel at a shop entrance where green means “come in” and red means “please wait”.
- Visitor statistics: the ESP32 logs entries per hour and shows the busiest time of day in a chart.
- Classroom attendance helper: shows how many students are in the room at the start of class; add an RFID reader to turn it into a named register.
- Car park occupancy display: the same logic works for cars; put two HC-SR04 sensors on the entry/exit lane and show how many spaces are left.
A people counter looks like a small project, but it brings sensor reading, timing, a state machine, a display and a web server together in one real job. In the BlueGrays app you'll find the projects that make up its building blocks, such as HC-SR04 distance measuring, a laser security system, a 7-segment counter and an ESP32 WebSocket counter, each with a step-by-step wiring diagram and code.
Frequently asked questions
How does an Arduino people counter work?
Two sensors are mounted a few centimetres apart across the doorway. The Arduino checks which one is blocked first: outer then inner counts as an entry, the reverse as an exit, and the difference between the two gives the number of people inside.
What is the best sensor for counting people?
For narrow doors and first builds, the FC-51 infrared obstacle sensor is the cheapest and easiest choice. For wide entrances, an E18-D80NK or a laser and LDR light barrier is more reliable. If you need to separate people walking side by side, you'll need ToF sensors or a camera-based system.
How does it know whether someone is entering or leaving?
A single sensor can't tell direction; it comes from the order in which the two sensors fire. Outer first and inner second is an entry; inner first is an exit. If the second sensor doesn't follow within a set time, the person is assumed to have turned back and nothing is counted.
Can it count two people walking through together?
Infrared obstacle sensors usually see two people side by side as one. To reduce this, narrow the entrance to the width of one person or fit a separate pair of sensors on each side of the door. Where exact counts are required, ToF arrays or camera-based counters are used.
Can I see the number of people inside on my phone?
Yes. Build the counter with an ESP32 and it runs a small web server; open the ESP32's IP address on a phone on the same Wi-Fi and you'll see the live inside count and daily total. For access over the internet, send the data to MQTT or a cloud dashboard.
How accurate is an infrared people counter?
A well-tuned two-sensor counter can be more than 95% accurate at doors where people pass one at a time. Errors mostly come from side-by-side passing, sunlight, dark clothing and the wrong mounting height. Resetting the count at the end of each day stops small errors from piling up.
Projects to build after reading this
See all projects
HC-SR04 Distance Measurement (Serial Display)
The HC-SR04 sensor works just like a bat finding its way in the dark: it sends out a sound you cannot hear, listens for the echo and measures how far away the object in front of it is.

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…

Counter with 7-Segment Display and Buttons
A simple counter with three buttons: press one and the digit on the display goes up by one, press another and it goes down by one, and the third sends it back to zero.

Laser Warning System
You set up an invisible beam fence, just like in the movies. A laser shines onto a light sensor on the other side; the moment someone walks through and breaks the beam, the LED lights up and the…

Laser Security System
Just like the laser heist scenes in films: a laser beam shines on a light sensor, and the moment someone steps in and breaks the beam, the red LED lights up and the buzzer starts sounding.

ESP32 WebSocket Counter (2 Buttons + LCD + Real-Time Web)
In this project, two buttons wired to the ESP32 (GPIO 5 counts up, GPIO 4 counts down) change a counter. The value updates instantly both on a 16x2 I2C LCD and, through the WebSocket support of ESPAsyncWebServer, in every connected browser without reloading the page. Instead of HTTP polling a single persistent connection is used, and the ESP32 sends the new value to everyone with ws.textAll().

ESP32 Prayer Rakat Counter (HC-SR04 + SSD1306 OLED + 2 Buttons)
Do you sometimes lose track of which rakat you are on during prayer? This project is a rakat counter that sits next to your prayer mat and counts your prostrations when you bring your hand close. The HC-SR04 ultrasonic distance sensor detects your hand, the SSD1306 OLED display shows the count, and two buttons let you choose 2, 3 or 4 rakats and reset. A 2.5-second debounce and a "hand-away" check make sure no prostration is counted twice.

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).
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

