Build it step by step
0 of 7 doneTest the PIR
Wave a hand and print the pin.
Add the transistor
Clean 5 V signal.
Set the clock
DS3231 example sketch.
Count visits
Ignore repeats for 3 seconds.
Write the CSV
One line per hour.
Show the totals
OLED hour and day.
Chart the data
Bars per hour in a spreadsheet.
How do you build a visitor counter at the door?
A PIR logs visitors at a shop door by hour and shows a graph. You need Arduino Nano, AM312 mini PIR motion sensor, DS3231 RTC module, MicroSD Card Module, SanDisk microSD card 32 GB (A1, Class 10), SSD1306 OLED Display, BC547 NPN transistor and Resistor 10 kΩ × 2. It takes 7 steps and about 90 minutes.
- Level
- Beginner
- Time
- About 90 min
- Parts
- 8
Parts list
- Development BoardsBuyArduino Nano × 1
- SensorsBuy
- SensorsBuy
- InterfacesBuy
- SBC AccessoriesBuy
- DisplaysBuy
- SemiconductorsBuy
- PassivesBuyResistor 10 kΩ × 2
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| AM312 VCC and GND | Nano 5V and GND | Power |
| AM312 OUT | 10 kΩ to BC547 base | Level translation |
| BC547 emitter | Ground | Ground |
| BC547 collector | Nano D2, with 10 kΩ to 5V | Active-low motion signal |
| RTC and OLED SDA, SCL | Nano A4 and A5 | Shared I2C bus |
| SD module CS | Nano D10 | Chip select |
| SD module MOSI, MISO, SCK | Nano D11, D12, D13 | SPI |
| SD module VCC and GND | Nano 5V and GND | Power |
Code
The AM312's output is only about 3 V, which a 5 V Nano can read unreliably, so a BC547 transistor turns it into a clean 5 V signal that goes low when someone passes. Each hour the sketch appends a line to visits.csv on the SD card, and you can open it in a spreadsheet and draw the daily bar chart there; the OLED shows the current hour and the day's count. One person lingering at the door counts once per three seconds, so treat the numbers as foot traffic, not exact heads. The sensor counts movement and records no images or identities, but if the counter covers a public area, tell visitors in a small notice. Set the DS3231 clock once with the RTClib example. Arduino IDE, board "Arduino Nano" (try the Old Bootloader option if the upload fails).
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Door visitor counter: logs one CSV line per hour. Libraries: RTClib, SD, U8g2 (text-only U8x8 to save RAM).
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <RTClib.h>
#include <U8x8lib.h>
RTC_DS3231 rtc;
U8X8_SSD1306_128X64_NONAME_HW_I2C oled(U8X8_PIN_NONE);
const int PIR = 2, CS = 10;
unsigned int hourCount = 0, dayCount = 0;
int curHour = -1, curDay = -1;
unsigned long lastHit = 0;
void flushHour(DateTime t) { // append "date,hour,count" to the card
File f = SD.open("visits.csv", FILE_WRITE);
if (f) {
f.print(t.year()); f.print("-"); f.print(t.month()); f.print("-"); f.print(t.day()); f.print(",");
f.print(curHour); f.print(","); f.println(hourCount);
f.close();
}
}
void show() {
oled.setCursor(0, 0); oled.print("Hour: "); oled.print(hourCount); oled.print(" ");
oled.setCursor(0, 2); oled.print("Today: "); oled.print(dayCount); oled.print(" ");
}
void setup() {
pinMode(PIR, INPUT);
rtc.begin(); SD.begin(CS);
oled.begin(); oled.setFont(u8x8_font_chroma48medium8_r);
curHour = rtc.now().hour(); curDay = rtc.now().day();
show();
}
void loop() {
DateTime now = rtc.now();
if (now.hour() != curHour) { flushHour(now); hourCount = 0; curHour = now.hour(); }
if (now.day() != curDay) { dayCount = 0; curDay = now.day(); }
if (digitalRead(PIR) == LOW && millis() - lastHit > 3000UL) { // ignore repeats for 3 s
lastHit = millis(); hourCount++; dayCount++; show();
}
delay(50);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Walk past | Count goes up by one |
| Wave for 2 seconds | Counts once |
| Hour changes | New CSV line is written |
| Power cycle | SD file keeps the history |
If it does not work
Never counts
Check the transistor orientation.
Counts constantly
Aim the sensor away from fans and sunlight.
SD fails
Format the card as FAT32.
Wrong hours
Reset the clock.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the visitor counter at the door?
Arduino Nano, AM312 mini PIR motion sensor, DS3231 RTC module, MicroSD Card Module, SanDisk microSD card 32 GB (A1, Class 10), SSD1306 OLED Display, BC547 NPN transistor and Resistor 10 kΩ × 2.
How long does the visitor counter at the door take to build?
About 90 minutes for a beginner maker, in 7 steps.
How do I know the visitor counter at the door works?
Walk past: Count goes up by one. Wave for 2 seconds: Counts once. Hour changes: New CSV line is written.
Never counts: what should I check?
Check the transistor orientation.
Counts constantly: what should I check?
Aim the sensor away from fans and sunlight.
SD fails: what should I check?
Format the card as FAT32.
Wrong hours: what should I check?
Reset the clock.
