This is an old revision of the document!


Smart Locker

Author: Mihai-Ionuț Păunescu 332CD

Introduction

The project consists of developing a smart locker system controlled by an ATmega328P-XMINI microcontroller.

The locker can be unlocked using:

  • an RFID card
  • a PIN code entered through a keypad

The system controls an electromagnetic locking mechanism and provides user feedback using LEDs, a buzzer and a display.

The idea for this project started from observing the locker systems commonly used in gyms, where access is usually protected only by a PIN code.

In many situations, it is relatively easy for a malicious person to observe the PIN entered by another user. Because of this, the project introduces an additional layer of security by combining PIN authentication with RFID card verification.

The goal is to create a smarter and more secure locker system using multiple authentication methods.

The project aims to improve the security and reliability of traditional locker systems by using two different authentication methods instead of relying only on a PIN code.

General Description

The system is built around the ATmega328P-XMINI microcontroller which coordinates all hardware modules.

Main modules:

  • RFID reader module
  • keypad for PIN input
  • electronic solenoid lock
  • display module
  • LEDs and buzzer for feedback

System flow:

  • the display continuously shows a welcome message while the system waits for user interaction
  • the user first scans the RFID card
  • if the RFID authentication is successful:
    • the display asks the user to enter the PIN code
    • the green and red LEDs start blinking alternately
  • if the RFID authentication fails:
    • an error message is displayed
    • the user is asked to scan the card again
  • after entering the PIN:
    • if the PIN is correct:
      • the green LED remains turned on for a few seconds
      • the buzzer emits a success confirmation sound
      • the electromagnetic lock opens
      • the display shows a confirmation message indicating that the locker has been unlocked
    • if the PIN is incorrect:
      • the display shows an error message
      • the red LED turns on
      • the buzzer emits a failure sound
      • the locker remains locked
  • if the user enters the wrong PIN three consecutive times:
    • the buzzer emits a louder warning sound to alert nearby people that unauthorized access may be attempted

Block Diagram

 Block Diagram

Hardware Design

Components List

Component Purpose
ATmega328P-XMINI Main microcontroller
RFID RC522 Module RFID card reading
Keypad PIN input
Electromagnetic Lock Locking mechanism
MOSFET E-Switch Module Controls the electromagnetic lock using an external power supply
Breadboard Circuit prototyping
Jumper wires Electrical connections
OLED Display User interface
Green and Red LEDs Status indication
Buzzer Audio feedback
External Power Supply Power supply for the electromagnetic lock

Pin Usage and Hardware Connections

The smart locker system is built around the ATmega328P-XMINI microcontroller. Each external component is connected to a specific set of microcontroller pins depending on its role and communication requirements. Components that only need simple ON/OFF control are connected to general-purpose digital pins, while communication-based modules use the dedicated hardware interfaces of the microcontroller.

Component ATmega328P Pin Direction / Interface Purpose
Green LED PD2 Digital output Indicates successful access or a positive system state
Red LED PD3 Digital output Indicates errors, denied access or warning states
Buzzer PD4 Digital output Generates audio feedback
Electromagnetic lock driver PD6 Digital output Controls the MOSFET driver for the lock
OLED Display SDA PC4 / SDA I2C data line Transfers data to the OLED display
OLED Display SCL PC5 / SCL I2C clock line Provides the clock signal for I2C communication
Keypad columns PC0, PC1, PC2, PC3 Digital inputs with internal pull-up resistors Reads the pressed keypad column
Keypad rows PB0, PB1, PD5, PD7 Digital outputs Selects the active keypad row
UART PD1 / TXD Serial output Sends debug information to the computer
RFID RC522 SDA / SS PB2 / SS SPI chip select Selects the RFID module during SPI communication
RFID RC522 MOSI PB3 / MOSI SPI data output Sends data from the microcontroller to the RFID module
RFID RC522 MISO PB4 / MISO SPI data input Receives data from the RFID module
RFID RC522 SCK PB5 / SCK SPI clock Provides the SPI clock signal
RFID RC522 RST PD0 Digital output Resets or enables the RFID module
RFID RC522 IRQ Not connected Optional interrupt pin Not used in this project

LEDs

The system uses two LEDs for visual feedback: a green LED and a red LED.

The green LED is connected to pin PD2 of the ATmega328P. This pin is configured as a digital output. When the microcontroller sets this pin to HIGH, current flows through the LED and the LED turns on. When the pin is set to LOW, the LED turns off.

The red LED is connected to pin PD3, also configured as a digital output. It works in the same way as the green LED, but it is used for negative system states, such as invalid authentication, denied access or warning conditions.

PD2 and PD3 were chosen because the LEDs do not require any special hardware interface. They only need simple digital control, so general-purpose I/O pins are suitable. Each LED must be connected in series with a current-limiting resistor in order to protect both the LED and the microcontroller pin.

Buzzer

The buzzer is connected to pin PD4, configured as a digital output.

The buzzer is controlled by switching the PD4 pin between HIGH and LOW. This creates a signal that produces sound. By changing the delay between the HIGH and LOW states, different sound frequencies can be generated.

PD4 was chosen because the buzzer only requires a digital control signal. It does not need a dedicated communication interface such as I2C or SPI. This makes a general-purpose digital pin appropriate for this component.

The buzzer provides audio feedback for different events, such as successful authentication, failed authentication or warning states.

Electromagnetic Lock and MOSFET Driver

The electromagnetic lock is controlled through pin PD6 of the ATmega328P. This pin is configured as a digital output.

The electromagnetic lock is not connected directly to the microcontroller pin, because it requires a higher current than the ATmega328P can safely provide. Instead, PD6 is connected to the input of a MOSFET E-Switch module. The MOSFET module acts as an electronic switch between the external power supply and the electromagnetic lock.

When PD6 is set to HIGH, the MOSFET driver is activated and current flows through the electromagnetic lock. This unlocks the mechanism. When PD6 is set to LOW, the MOSFET driver is deactivated and the lock returns to its inactive state.

This separation is important because the microcontroller only provides the control signal, while the external power supply provides the power required by the lock. The ground of the external power supply and the ground of the ATmega328P-XMINI are connected together, so both circuits share the same reference voltage.

PD6 was selected because the lock driver only needs a simple digital ON/OFF control signal.

OLED Display

The OLED display is connected using the I2C communication interface.

On the ATmega328P, the dedicated I2C pins are:

  • PC4 for SDA
  • PC5 for SCL

The SDA line is used for transferring data between the microcontroller and the OLED display. The SCL line is used as the clock signal, which synchronizes the communication between the two devices.

These pins were chosen because PC4 and PC5 are the hardware I2C pins of the ATmega328P. Using the dedicated I2C pins allows the display to communicate with the microcontroller using only two signal wires.

The OLED display is also connected to power and ground.

Keypad

The keypad is a 4×4 matrix keypad, meaning that it has 4 row lines and 4 column lines. Because of this structure, it requires 8 microcontroller pins.

The keypad rows are connected to:

  • PB0
  • PB1
  • PD5
  • PD7

These pins are configured as digital outputs.

The keypad columns are connected to:

  • PC0
  • PC1
  • PC2
  • PC3

These pins are configured as digital inputs with the internal pull-up resistors enabled.

The row pins are outputs because the microcontroller activates one row at a time during the scanning process. The column pins are inputs because the microcontroller reads them to determine which key was pressed.

The scanning process works as follows:

  1. all rows are initially kept HIGH
  2. one row is set to LOW
  3. the column inputs are read
  4. if a column is also LOW, the pressed key is found at the intersection between the active row and that column
  5. the process is repeated for all rows

The internal pull-up resistors are used so that each column normally reads HIGH when no key is pressed. When a key is pressed, it connects the active LOW row to one of the columns, causing that column to read LOW.

RFID RC522 Module

The RFID RC522 module communicates with the ATmega328P using the SPI interface. SPI uses separate lines for clock, data sent from the microcontroller, data received by the microcontroller and chip selection.

The RFID RC522 module is connected as follows:

RFID RC522 Pin ATmega328P Pin Interface / Direction Purpose
SDA / SS PB2 / SS SPI chip select Selects the RFID module during SPI communication
MOSI PB3 / MOSI SPI output from microcontroller Sends data from the ATmega328P to the RFID module
MISO PB4 / MISO SPI input to microcontroller Receives data from the RFID module
SCK PB5 / SCK SPI clock Provides the clock signal for SPI communication
RST PD0 Digital output Resets or enables the RFID module
3.3V 3.3V Power supply Powers the RFID module
GND GND Ground Common ground with the microcontroller
IRQ Not connected Interrupt pin Not used in this project

The SDA pin of the RC522 module is used as the SS, or Slave Select, line in SPI communication. It is connected to PB2, which is the hardware SS pin of the ATmega328P. This pin allows the microcontroller to select the RFID module before exchanging data with it.

The MOSI pin is connected to PB3. MOSI stands for Master Out Slave In, meaning that this line is used to send data from the microcontroller to the RFID module.

The MISO pin is connected to PB4. MISO stands for Master In Slave Out, meaning that this line is used by the RFID module to send data back to the microcontroller.

The SCK pin is connected to PB5. This line provides the clock signal generated by the microcontroller, which synchronizes the SPI data transfer.

The RST pin is connected to PD0, configured as a digital output. This pin allows the microcontroller to reset or enable the RFID module when needed.

The IRQ pin is not connected, because interrupt-based card detection is not required. The microcontroller can check the RFID module directly through SPI.

The RC522 module must be powered from 3.3V, and its GND pin must be connected to the same ground as the ATmega328P-XMINI. This common ground is required so that both devices use the same voltage reference during communication.

Pin Selection Justification

The pin selection was made according to the electrical and communication requirements of each module.

The OLED display uses PC4 and PC5 because these are the dedicated I2C pins of the ATmega328P. This allows the display to use the hardware TWI interface and keeps the number of required wires low.

The RFID RC522 module uses the SPI pins PB2-PB5 because SPI communication requires dedicated MOSI, MISO, SCK and SS lines. These pins allow fast communication between the microcontroller and the RFID reader.

The keypad uses PB0-PB3 for rows and PC0-PC3 for columns. This grouping keeps the row lines and column lines organized on separate groups of pins, which simplifies both the hardware wiring and the software scanning logic.

The LEDs, buzzer and electromagnetic lock driver are connected to port D pins because they only require simple digital output control. These components do not need dedicated communication peripherals, so general-purpose digital pins are sufficient.

The electromagnetic lock is controlled through a MOSFET driver instead of being powered directly from the microcontroller. This is necessary because the lock requires more current than a microcontroller pin can provide.

Overall, the pin allocation keeps the design organized:

  • Port B is used for keypad row control and SPI communication
  • Port C is used for keypad column reading and I2C communication
  • Port D is used for LEDs, buzzer, UART debugging and lock control

Electrical Diagram

 Electrical Diagram

Due to the limitations of the TinkerCad platform and the absence of some hardware components, I used several symbolic replacements in the electrical schematic:

  • I used the Arduino Uno board as a replacement for the ATmega328P-XMINI development board
  • I used an ATTINY microcontroller symbol to represent the RFID RC522 module
  • I used a standard LCD display instead of the OLED display that will be used in the real implementation
  • I used a generic NMOS transistor to represent the MOSFET E-Switch module used in the real hardware setup

These replacements were used only for schematic representation purposes.

Software Design

Results

References

pm/prj2026/jan.vaduva/mihai.paunescu1801.1779108592.txt.gz · Last modified: 2026/05/18 15:49 by mihai.paunescu1801
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0