ESP32-Based Smart Access Control System with RFID, Keypad, and OLED Display
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This document provides a detailed overview of a circuit design that includes various components such as a membrane matrix keypad, pushbuttons, LEDs, resistors, an RFID module, an ESP32 microcontroller, an SD module, and an OLED display. The circuit is designed to interface with these components to perform various tasks, including reading RFID tags, displaying information on an OLED screen, and logging data to an SD card. The ESP32 microcontroller is programmed to handle these tasks and communicate with the components.
Component List
Membrane Matrix Keypad
- Description: A 4x3 matrix keypad used for user input.
- Pins: Row 1, Row 2, Row 3, Row 4, Column 1, Column 2, Column 3
Pushbutton
- Description: A simple pushbutton used for user input.
- Pins: Pin 1, Pin 2, Pin 3, Pin 4
LED: Two Pin (red)
- Description: A red LED used for visual indication.
- Pins: Anode, Cathode
Resistor
- Description: A resistor with a resistance of 200 Ohms.
- Pins: Pin 1, Pin 2
RFID-RC522
- Description: An RFID module used for reading RFID tags.
- Pins: SDA, SCK, MOSI, MISO, IRQ, GND, RST, 3.3V
ESP32 Devkit V1
- Description: A development board based on the ESP32 microcontroller.
- Pins: 3V3, GND, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, VIN
SD Module
- Description: An SD card module used for data storage.
- Pins: CS, SCK, MOSI, MISO, VCC, GND
OLED Display 2.42"
- Description: A 2.42-inch OLED display used for visual output.
- Pins: GND, VCC, SCK, SDA, RES, DC, CS
Wiring Details
Membrane Matrix Keypad
- Row 1: Connected to ESP32 pin D33
- Row 2: Connected to ESP32 pin D25
- Row 3: Connected to ESP32 pin D26
- Row 4: Connected to ESP32 pin D27
- Column 1: Connected to ESP32 pin D14
- Column 2: Connected to ESP32 pin D12
- Column 3: Connected to ESP32 pin D13
Pushbutton 1
- Pin 1: Connected to ESP32 pin D15
Pushbutton 2
- Pin 1: Connected to ESP32 pin D34
Pushbutton 3
- Pin 1: Connected to ESP32 pin D35
LED: Two Pin (red)
- Anode: Connected to ESP32 pin D32
Resistor 1
- Pin 1: Not specified
- Pin 2: Not specified
Resistor 2
- Pin 1: Not specified
- Pin 2: Not specified
Resistor 3
- Pin 1: Not specified
- Pin 2: Not specified
RFID-RC522
- SDA: Connected to ESP32 pin D21
- SCK: Connected to ESP32 pin D18
- MOSI: Connected to ESP32 pin D23
- MISO: Connected to ESP32 pin D19
- RST: Connected to ESP32 pin D2
ESP32 Devkit V1
- D15: Connected to Pushbutton 1 Pin 1
- D2: Connected to RFID-RC522 RST
- D4: Connected to SD Module CS
- D18: Connected to SD Module SCK and RFID-RC522 SCK
- D19: Connected to SD Module MISO and RFID-RC522 MISO
- D21: Connected to OLED Display SDA and RFID-RC522 SDA
- D22: Connected to OLED Display SCK
- D23: Connected to SD Module MOSI and RFID-RC522 MOSI
- D34: Connected to Pushbutton 2 Pin 1
- D35: Connected to Pushbutton 3 Pin 1
- D32: Connected to LED Anode
- D33: Connected to Membrane Matrix Keypad Row 1
- D25: Connected to Membrane Matrix Keypad Row 2
- D26: Connected to Membrane Matrix Keypad Row 3
- D27: Connected to Membrane Matrix Keypad Row 4
- D14: Connected to Membrane Matrix Keypad Column 1
- D12: Connected to Membrane Matrix Keypad Column 2
- D13: Connected to Membrane Matrix Keypad Column 3
SD Module
- CS: Connected to ESP32 pin D4
- SCK: Connected to ESP32 pin D18
- MOSI: Connected to ESP32 pin D23
- MISO: Connected to ESP32 pin D19
OLED Display 2.42"
- SDA: Connected to ESP32 pin D21
- SCK: Connected to ESP32 pin D22
Documented Code
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <HTTPClient.h>
#include "FS.h"
#include "SD.h"
#include <SPI.h>
#include <MFRC522.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include <time.h>
#include <sntp.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <ArduinoJson.h> // Include the ArduinoJson library
#include <Keypad.h>
// Length of password + 1 for null character
#define Password_Length 8
// Character to hold password input
char Data[Password_Length];
// Password
// Counter for character entries
byte data_count = 0;
// Character to hold key input
char customKey;
// Constants for row and column sizes
const byte ROWS = 4;
const byte COLS = 3;
// Array to represent keys on keypad
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
// Connections to Arduino
byte rowPins[ROWS] = {33, 25, 26, 27}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {14, 12, 13}; //connect to the column pinouts of the keypad
// Create keypad object
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
#define SS_PIN 5 // SDA pin esp32=5
#define RST_PIN 2 // RST pin esp32=22
#define SD_CS 4 // CS pin for SD card
#define Wifi_LED 32
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for SSD1306 display connected using I2C
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
const int buttonPin = 15; // GPIO pin for the push button
int counter = 0; // Counter variable
int lastButtonState = HIGH; // Last button state (HIGH because of pull-up)
int buttonState; // Current button state
unsigned long lastDebounceTime = 0; // Last time the button state changed
unsigned long debounceDelay = 5; // Debounce time in milliseconds
bool incremented = false; // Flag to check if counter has already incremented
// Define pin for the button
const int buttonPin2 = 34;
String URL = "http://103.148.212.44/backend/api/task-log";
// Variables to hold the current and last button state
bool currentButtonState2 = HIGH; // Assuming HIGH means not pressed
bool lastButtonState2 = HIGH;
bool working_status = true; // Initial working status
bool updated_working_status = false;
bool updated_counter = false;
bool data_upload = true;
// Define pins for the buttons
const int buttonPin3 = 35; // Maintenance
bool currentButtonState3 = HIGH; // Assuming HIGH means not pressed
bool lastButtonState3 = HIGH;
unsigned long lastDebounceTime3 = 0;
unsigned long debounceDelay3 =