Projects / Gate visitor logbook with keypad

Gate visitor logbook with keypad

Intermediate2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. UNOHello20X4

    Test the keypad

    Print keys on the LCD.

  2. UNOHello20X4

    Add the clock

    Show the time on the LCD.

  3. UNOMICROS

    Test the SD card

    Create and read a file.

  4. UNO

    Make the flat list

    One flat per line in FLATS.TXT.

  5. UNO

    Validate and log

    Write a line per visit.

  6. UNO

    Add the beeps

    Different tones for accept and reject.

  7. UNO

    Add the trigger

    Pulse through an optocoupler.

In short

How do you build a gate visitor logbook with keypad?

Visitors enter a flat number on a keypad at the society gate, and the entry is logged with time and a photo trigger signal. You need Arduino Uno R3, 4x4 matrix keypad (membrane), 20x4 LCD with I2C backpack, DS3231 RTC module, MicroSD Card Module, Active buzzer 5 V and Resistor 1 kΩ. It takes 7 steps and about 120 minutes.

Level
Intermediate
Time
About 120 min
Parts
7

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Keypad rowsUno D2, D3, D4, D5Row scan
Keypad columnsUno D6, D7, D8, D9Column scan
LCD SDA and SCLUno A4 and A5I2C display
DS3231 SDA and SCLUno A4 and A5Shares the I2C bus
SD module CSUno D10Chip select
SD module MOSI, MISO, SCKUno D11, D12, D13SPI
SD module VCC and GNDUno 5V and GNDPower (use a module with a level shifter)
Buzzer +Uno A0Confirmation beep
Trigger outputUno A1 through a 1 kΩ resistor to an optocoupler or relay inputNever wire it directly to a camera

Code

The visitor enters a 3 or 4 digit flat number and presses #; the sketch checks it against FLATS.TXT on the SD card, logs the date, time and number to LOG.CSV, and gives a short pulse that an optocoupler or relay input can use to trigger a camera snapshot. Never connect the Arduino pin directly to a camera or other equipment; use an optocoupler or a relay module with its own supply. A logbook of visitors is personal data: put up a clear notice, keep the file only as long as you need it, protect the card, and follow your society's and your country's data rules. This build does not open any gate or door. If you later add a gate release, a qualified person must wire it, and it must fail safe so that people can always leave. The sketch accepts any number if no list is present on the card, which is handy for testing. Arduino IDE, board "Arduino Uno".

Runs on a virtual Arduino Uno 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).

// Visitor logbook. Libraries: Keypad, LiquidCrystal_I2C, RTClib, SD. Board: Arduino Uno.
// SD card files: FLATS.TXT (one flat number per line, for example 101) and LOG.CSV (created by the sketch).
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <SPI.h>
#include <SD.h>

const byte ROWS = 4, COLS = 4;
char keys[ROWS][COLS] = {{'1','2','3','A'},{'4','5','6','B'},{'7','8','9','C'},{'*','0','#','D'}};
byte rowPins[ROWS] = {2, 3, 4, 5}, colPins[COLS] = {6, 7, 8, 9};
Keypad pad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 20, 4);
RTC_DS3231 rtc;
const int SD_CS = 10, BUZZ = A0, TRIG = A1;
String entry = "";

bool flatExists(const String& n) {
  File f = SD.open("FLATS.TXT");
  if (!f) return true;                          // no list on the card: accept any number
  bool found = false;
  while (f.available()) { String line = f.readStringUntil('\n'); line.trim(); if (line == n) { found = true; break; } }
  f.close();
  return found;
}

void prompt() { lcd.clear(); lcd.print("Enter flat number"); lcd.setCursor(0, 1); lcd.print("then press #"); lcd.setCursor(0, 2); lcd.print("> "); lcd.print(entry); }

void logVisit(const String& flat) {
  DateTime t = rtc.now();
  File f = SD.open("LOG.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(t.hour()); f.print(":"); if (t.minute() < 10) f.print("0"); f.print(t.minute());
    f.print(","); f.println(flat); f.close();
  }
  digitalWrite(TRIG, HIGH); delay(200); digitalWrite(TRIG, LOW);    // short pulse for an optocoupler or relay input
}

void setup() {
  pinMode(BUZZ, OUTPUT); pinMode(TRIG, OUTPUT);
  lcd.init(); lcd.backlight();
  rtc.begin();
  SD.begin(SD_CS);
  prompt();
}

void loop() {
  char k = pad.getKey();
  if (!k) return;
  tone(BUZZ, 2000, 40);
  if (k >= '0' && k <= '9' && entry.length() < 4) entry += k;
  else if (k == '*') entry = "";
  else if (k == '#') {
    if (entry.length() >= 3 && flatExists(entry)) {
      logVisit(entry); lcd.clear(); lcd.print("Thank you"); lcd.setCursor(0, 1); lcd.print("Flat "); lcd.print(entry); tone(BUZZ, 1500, 400);
    } else { lcd.clear(); lcd.print("Flat not found"); tone(BUZZ, 400, 600); }
    delay(2000); entry = "";
  }
  prompt();
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Enter a listed flat and #Thank you, entry in LOG.CSV
Enter an unknown flatFlat not found, low beep
Press *Clears the entry
Unplug and replugLog keeps its earlier lines

If it does not work

SD does not start

Format FAT32 and check the CS pin and the level shifter.

Time wrong

Set the RTC and replace the coin cell.

No flat accepted

Check FLATS.TXT has one number per line with no spaces.

LCD blank

Check the I2C address 0x27 or 0x3F.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the gate visitor logbook with keypad?

Arduino Uno R3, 4x4 matrix keypad (membrane), 20x4 LCD with I2C backpack, DS3231 RTC module, MicroSD Card Module, Active buzzer 5 V and Resistor 1 kΩ.

How long does the gate visitor logbook with keypad take to build?

About 120 minutes for a intermediate maker, in 7 steps.

How do I know the gate visitor logbook with keypad works?

Enter a listed flat and #: Thank you, entry in LOG.CSV. Enter an unknown flat: Flat not found, low beep. Press *: Clears the entry.

SD does not start: what should I check?

Format FAT32 and check the CS pin and the level shifter.

Time wrong: what should I check?

Set the RTC and replace the coin cell.

No flat accepted: what should I check?

Check FLATS.TXT has one number per line with no spaces.

LCD blank: what should I check?

Check the I2C address 0x27 or 0x3F.