ESP8266 Door Access Control System
Loading...
Searching...
No Matches
esp1_rfid_motion.ino File Reference

RFID + PIN based access controller with LCD, motion sensing, and MQTT. More...

#include <Arduino.h>
#include <string.h>
#include <ArduinoJson.h>
#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <WiFiMqttClient.h>
Include dependency graph for esp1_rfid_motion.ino:

Go to the source code of this file.

Enumerations

enum class  AccessResult : uint8_t { AccessResult::Denied , AccessResult::Granted , AccessResult::Denied , AccessResult::Granted }
 Access result enumeration. More...

Functions

MFRC522 mfrc522 (RFID_SS_PIN, RFID_RST_PIN)
 MFRC522 RFID reader instance.
LiquidCrystal_I2C lcd (LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS)
 I2C LCD instance.
void lcdPrintLine (const __FlashStringHelper *msg, uint8_t line)
 Clears an LCD line and prints a flash-resident string.
void lcdPrintLine (const char *msg, uint8_t line)
 Clears an LCD line and prints a RAM-resident string.
static void forceLock ()
 Forces the system back into locked idle state.
void makeEnteredPins (uint8_t pinLength)
 Builds a masked PIN string for LCD display.
void callback (char *topic, byte *payload, unsigned int length)
 MQTT message callback handler.
bool isDisplayActive (uint32_t now)
 Checks whether the LCD backlight should remain active.
void onMotionDetected (uint32_t now)
 Handles motion-detected events.
void onMotionIdle (uint32_t now)
 Handles motion-idle state.
void updateMotionState (uint32_t now)
 Updates motion state based on PIR sensor input.
void uidToHexString (const MFRC522::Uid &uid, char *output, size_t outputSize)
 Converts an RFID UID to a hexadecimal string.
void handleRFID ()
 Handles RFID card detection and request publishing.
void setup ()
 Arduino setup function.
void loop ()
 Arduino main loop.

Variables

WifiMqttClient net
 WiFi + MQTT client wrapper.
constexpr char WIFI_SSID [] = "Mathias2.4"
 WiFi SSID.
constexpr char WIFI_PASS [] = "mrbombasticcallmefantastic"
 WiFi password.
constexpr char MQTT_HOST [] = "maqiatto.com"
 MQTT broker hostname.
constexpr uint16_t MQTT_PORT = 1883
 MQTT broker port.
constexpr char MQTT_USER [] = "hectorfoss@gmail.com"
 MQTT username.
constexpr char MQTT_PASS [] = "potter"
 MQTT password.
constexpr char DEVICE_ID [] = "door1"
 Unique device identifier used in MQTT topics.
constexpr uint8_t RFID_SS_PIN = 15
 RC522 SPI Slave Select pin (D8 / GPIO15).
constexpr uint8_t RFID_RST_PIN = 16
 RC522 Reset pin (D0 / GPIO16).
constexpr uint8_t MOTION_PIN = 0
 Motion sensor pin (D3 / GPIO0).
constexpr uint8_t I2C_SDA_PIN = 4
 I2C SDA pin for LCD (D2 / GPIO4).
constexpr uint8_t I2C_SCL_PIN = 5
 I2C SCL pin for LCD (D1 / GPIO5).
constexpr uint8_t LCD_COLUMNS = 16
 Number of LCD columns.
constexpr uint8_t LCD_ROWS = 2
 Number of LCD rows.
constexpr uint8_t LCD_ADDRESS = 0x27
 I2C address of the LCD module.
constexpr uint32_t DISPLAY_MS = 3000
 Duration (ms) to display text before resetting.
constexpr uint32_t DISPLAY_BACKLIGHT_MS = 5000
 Duration (ms) to keep LCD backlight on after motion.
constexpr uint32_t PIN_TIME_MS = 15000
 Time window (ms) for entering PIN after RFID success.
constexpr uint32_t UNLOCK_TIME_MS = 5000
 Door unlock display duration (ms).
constexpr uint32_t POLL_MS = 30
 Main loop polling delay (ms).
AccessResult rfidAccess
 Result of RFID authentication.
AccessResult accessGranted
 Result of PIN verification.
bool textshown = false
 Indicates whether a status message is currently displayed.
uint32_t showTextUntil = 0
 Timestamp (ms) when the displayed text should expire.
uint32_t showDisplayUntil = 0
 Timestamp (ms) when LCD backlight should turn off.
bool motionActive = false
 Indicates whether motion is currently considered active.
static char enteredPins [5] = " "
 Masked PIN buffer shown on LCD (max 4 digits + null terminator).

Detailed Description

RFID + PIN based access controller with LCD, motion sensing, and MQTT.

Definition in file esp1_rfid_motion.ino.