Skip to content
Intermediate 3 hours

ESP8266 WiFi Visitor Counter with OLED Display

By Amit1379
July 13, 2026

This visitor counter uses two IR break-beam sensors positioned in a doorway (one at entry, one at exit, ~15 cm apart). By detecting which sensor is broken first, the system determines the direction of travel — counting people entering and leaving separately. The net count (in minus out) gives current occupancy. WiFi logging pushes counts to a Google Sheet every 5 minutes.

What You’ll Need

  • NodeMCU ESP8266
  • 2 × IR break-beam sensor pairs (emitter + receiver, 5 V)
  • SSD1306 0.96″ OLED (I2C)
  • Micro-USB power supply
  • Cable clips and wire to mount sensors in doorway

Step-by-Step Instructions

  1. Wire sensors: Each receiver output to D5 and D6 on the NodeMCU (INPUT_PULLUP mode). IR emitters powered from 3.3 V. Sensor outputs go LOW when beam is broken.
  2. Wire OLED: SDA → D2, SCL → D1, VCC → 3.3 V.
  3. Direction detection logic: Mount sensors A and B in doorway 20 cm apart. Use interrupts on both pins. If A triggers first then B: entry (+1). If B triggers first then A: exit (-1). Debounce with a 500 ms lockout after each transition to ignore swinging doors.
  4. Display: OLED shows: “IN: XX OUT: XX” on top line, “NOW: XX people” on second line.
  5. WiFi logging: Every 5 minutes, connect to WiFi and POST totals to a Google Apps Script web app (same method as the temperature logger project). The Sheet records timestamp, in count, out count, and current occupancy.
  6. Mount: Use cable clips to route sensor wires neatly. Sensors face each other across the doorway at ~waist height. Secure the NodeMCU in a small project box near the door frame.

Safety Notes

  • IR break-beam emitters produce invisible infrared light — not a hazard at these low power levels.
  • Route wiring along wall edges, secure with clips, to prevent trip hazard.

Tips & Troubleshooting

  • Direct sunlight can saturate the IR receiver — choose sensor models with modulated carrier (38 kHz) for better immunity to ambient light.
  • If counts are off by one, adjust the 20 cm separation or increase the debounce time.
  • For narrow doorways less than 40 cm, use a single sensor and an ultrasonic distance sensor to determine direction instead.

Leave a Comment

Your email address will not be published. Required fields are marked *