ESP8266 Door Access Control System
Loading...
Searching...
No Matches
ESP3 - Door Actuator

Classes

struct  BuzzerPattern
 Describes a buzzer sound pattern. More...

Macros

#define POT_PIN   A0
 Analog pin for potentiometer (admin servo control).

Enumerations

enum class  AccessResult : uint8_t { AccessResult::Denied , AccessResult::Granted , AccessResult::Denied , AccessResult::Granted }
 Access result enumeration. More...
enum  BuzzerState { BUZZER_IDLE , BUZZER_ON , BUZZER_OFF }
 Buzzer state enumeration. More...

Functions

void playPattern (const unsigned int *timings, uint8_t length)
 Starts playing a buzzer pattern.
void updateBuzzer ()
 Advances the buzzer state machine.
void stopBuzzer ()
 Immediately stops any active buzzer sound.
void playLockSound ()
 Plays lock sound pattern.
void playUnlockSound ()
 Plays unlock sound pattern.
void playDeniedSound ()
 Plays denied-access sound pattern.
void playTapSound ()
 Plays keypad tap sound.
static void forceLock ()
 Forces the system into a locked idle state.
void callback (char *topic, byte *payload, unsigned int length)
 MQTT message callback handler.
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 RED_PIN = 4
 GPIO pin assignments.
constexpr uint8_t GREEN_PIN = 0
constexpr uint8_t BUZZER_PIN = 14
constexpr uint8_t SERVO_PIN = 13
constexpr uint32_t UNLOCK_TIME_MS = 5000
 Door unlock duration (ms).
uint32_t unlockUntil = 0
 Timestamp (ms) until which the door remains unlocked.
bool unlocked = false
 Indicates whether the door is currently unlocked.
AccessResult accessGranted
 Result of keypad PIN verification.
bool rfidAccess = false
 Indicates whether RFID access was granted.
Servo lock_servo
 Servo instance controlling the lock mechanism.
bool servoOpen = false
 Indicates whether the servo is currently in the open position.
uint8_t servoAngle
 Current servo angle (derived from potentiometer in admin mode).
bool adminServoControl = false
 Enables direct servo control via potentiometer (admin mode).
const unsigned int deniedTimings []
 Denied access: single long beep. Extra long to scare.
const unsigned int lockTimings []
 Lock sound: long-long-long pattern.
const unsigned int unlockTimings []
 Unlock sound: short-short pattern.
const unsigned int beepTimings []
 Keypad tap sound: short beep.
const unsigned int * BuzzerPattern::timings
uint8_t BuzzerPattern::length
BuzzerState buzzerState = BUZZER_IDLE
 Current buzzer state.
BuzzerPattern currentPattern = {nullptr, 0}
 Currently active buzzer pattern.
uint8_t stepIndex = 0
 Index into the timing array.
unsigned long lastChange = 0
 Timestamp of last buzzer state change.

Detailed Description

This firmware runs on an ESP-based Arduino-compatible board and implements the final actuator stage of the access control system.

Hardware components:

  • Servo motor for door locking mechanism
  • Status LEDs (red / green)
  • Piezo buzzer

Functional responsibilities:

  • Locks and unlocks the door based on MQTT access decisions
  • Provides audible and visual feedback for access events
  • Automatically relocks the door after a configurable timeout
  • Supports an administrative servo override mode via MQTT

This node does not make access decisions itself; it only reacts to authenticated results produced by the RFID and keypad nodes.

Macro Definition Documentation

◆ POT_PIN

#define POT_PIN   A0

Analog pin for potentiometer (admin servo control).

Definition at line 70 of file esp3.ino.

Enumeration Type Documentation

◆ AccessResult

enum class AccessResult : uint8_t
strong

Access result enumeration.

Enumerator
Denied 

Access denied

Granted 

Access granted

Denied 

Access denied

Granted 

Access granted

Definition at line 92 of file esp3.ino.

◆ BuzzerState

Buzzer state enumeration.

Enumerator
BUZZER_IDLE 

No sound playing

BUZZER_ON 

Buzzer currently active

BUZZER_OFF 

Silent gap between beeps

Definition at line 151 of file esp3.ino.

Function Documentation

◆ callback()

void callback ( char * topic,
byte * payload,
unsigned int length )

MQTT message callback handler.

Handles:

  • Keypad access responses (unlock / deny)
  • RFID access denials
  • Keypad tap beep feedback
  • Admin servo control enable/disable
Parameters
topicMQTT topic string.
payloadRaw payload bytes.
lengthPayload length.

Definition at line 308 of file esp3.ino.

Here is the call graph for this function:

◆ forceLock()

void forceLock ( )
static

Forces the system into a locked idle state.

  • Resets access state
  • Sets LEDs to "locked"
  • Moves servo to closed position if needed

Definition at line 278 of file esp3.ino.

Here is the caller graph for this function:

◆ loop()

void loop ( )

Arduino main loop.

Handles:

  • MQTT processing
  • Buzzer state machine updates
  • Servo admin override mode
  • Automatic relocking after timeout

Definition at line 474 of file esp3.ino.

Here is the call graph for this function:

◆ playDeniedSound()

void playDeniedSound ( )

Plays denied-access sound pattern.

Definition at line 254 of file esp3.ino.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ playLockSound()

void playLockSound ( )

Plays lock sound pattern.

Definition at line 240 of file esp3.ino.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ playPattern()

void playPattern ( const unsigned int * timings,
uint8_t length )

Starts playing a buzzer pattern.

Parameters
timingsPointer to timing array.
lengthNumber of elements in the timing array.

Definition at line 183 of file esp3.ino.

Here is the caller graph for this function:

◆ playTapSound()

void playTapSound ( )

Plays keypad tap sound.

Definition at line 261 of file esp3.ino.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ playUnlockSound()

void playUnlockSound ( )

Plays unlock sound pattern.

Definition at line 247 of file esp3.ino.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup()

void setup ( )

Arduino setup function.

Initializes GPIOs, servo, WiFi, MQTT client, and topic subscriptions.

Definition at line 413 of file esp3.ino.

Here is the call graph for this function:

◆ stopBuzzer()

void stopBuzzer ( )

Immediately stops any active buzzer sound.

Definition at line 234 of file esp3.ino.

Here is the caller graph for this function:

◆ updateBuzzer()

void updateBuzzer ( )

Advances the buzzer state machine.

Must be called frequently from the main loop.

Definition at line 203 of file esp3.ino.

Here is the caller graph for this function:

Variable Documentation

◆ accessGranted

AccessResult accessGranted

Result of keypad PIN verification.

Definition at line 98 of file esp3.ino.

◆ adminServoControl

bool adminServoControl = false

Enables direct servo control via potentiometer (admin mode).

Definition at line 113 of file esp3.ino.

◆ beepTimings

const unsigned int beepTimings[]
Initial value:
= {
125
}

Keypad tap sound: short beep.

Definition at line 144 of file esp3.ino.

◆ BUZZER_PIN

uint8_t BUZZER_PIN = 14
constexpr

Piezo buzzer

Definition at line 66 of file esp3.ino.

◆ buzzerState

BuzzerState buzzerState = BUZZER_IDLE

Current buzzer state.

Definition at line 166 of file esp3.ino.

◆ currentPattern

BuzzerPattern currentPattern = {nullptr, 0}

Currently active buzzer pattern.

Definition at line 169 of file esp3.ino.

◆ deniedTimings

const unsigned int deniedTimings[]
Initial value:
= {
2000
}

Denied access: single long beep. Extra long to scare.

Definition at line 126 of file esp3.ino.

◆ DEVICE_ID

char DEVICE_ID[] = "door1"
constexpr

Unique device identifier used in MQTT topics.

Definition at line 53 of file esp3.ino.

◆ GREEN_PIN

uint8_t GREEN_PIN = 0
constexpr

Green LED (unlocked)

Definition at line 65 of file esp3.ino.

◆ lastChange

unsigned long lastChange = 0

Timestamp of last buzzer state change.

Definition at line 175 of file esp3.ino.

◆ length

uint8_t BuzzerPattern::length

Number of timing entries

Definition at line 162 of file esp3.ino.

◆ lock_servo

Servo lock_servo

Servo instance controlling the lock mechanism.

Definition at line 104 of file esp3.ino.

◆ lockTimings

const unsigned int lockTimings[]
Initial value:
= {
250, 120,
250, 120,
250
}

Lock sound: long-long-long pattern.

Definition at line 131 of file esp3.ino.

◆ MQTT_HOST

char MQTT_HOST[] = "maqiatto.com"
constexpr

MQTT broker hostname.

Definition at line 44 of file esp3.ino.

◆ MQTT_PASS

char MQTT_PASS[] = "potter"
constexpr

MQTT password.

Definition at line 50 of file esp3.ino.

◆ MQTT_PORT

uint16_t MQTT_PORT = 1883
constexpr

MQTT broker port.

Definition at line 46 of file esp3.ino.

◆ MQTT_USER

char MQTT_USER[] = "hectorfoss@gmail.com"
constexpr

MQTT username.

Definition at line 48 of file esp3.ino.

◆ net

WiFi + MQTT client wrapper.

Definition at line 36 of file esp3.ino.

◆ RED_PIN

uint8_t RED_PIN = 4
constexpr

GPIO pin assignments.

Refer to esp3.fzz for wiring details. Red LED (locked / denied)

Definition at line 64 of file esp3.ino.

◆ rfidAccess

bool rfidAccess = false

Indicates whether RFID access was granted.

Definition at line 101 of file esp3.ino.

◆ SERVO_PIN

uint8_t SERVO_PIN = 13
constexpr

Servo signal pin

Definition at line 67 of file esp3.ino.

◆ servoAngle

uint8_t servoAngle

Current servo angle (derived from potentiometer in admin mode).

Definition at line 110 of file esp3.ino.

◆ servoOpen

bool servoOpen = false

Indicates whether the servo is currently in the open position.

Definition at line 107 of file esp3.ino.

◆ stepIndex

uint8_t stepIndex = 0

Index into the timing array.

Definition at line 172 of file esp3.ino.

◆ timings

const unsigned int* BuzzerPattern::timings

Pointer to timing array

Definition at line 161 of file esp3.ino.

◆ UNLOCK_TIME_MS

uint32_t UNLOCK_TIME_MS = 5000
constexpr

Door unlock duration (ms).

Definition at line 77 of file esp3.ino.

◆ unlocked

bool unlocked = false

Indicates whether the door is currently unlocked.

Definition at line 87 of file esp3.ino.

◆ unlockTimings

const unsigned int unlockTimings[]
Initial value:
= {
125, 120,
125
}

Unlock sound: short-short pattern.

Definition at line 138 of file esp3.ino.

◆ unlockUntil

uint32_t unlockUntil = 0

Timestamp (ms) until which the door remains unlocked.

Definition at line 80 of file esp3.ino.

◆ WIFI_PASS

char WIFI_PASS[] = "mrbombasticcallmefantastic"
constexpr

WiFi password.

Definition at line 41 of file esp3.ino.

◆ WIFI_SSID

char WIFI_SSID[] = "Mathias2.4"
constexpr

WiFi SSID.

Definition at line 39 of file esp3.ino.