This shows you the differences between two versions of the page.
|
pm:prj2026:jan.vaduva:mihai.paunescu1801 [2026/05/09 16:30] mihai.paunescu1801 |
pm:prj2026:jan.vaduva:mihai.paunescu1801 [2026/05/22 20:01] (current) mihai.paunescu1801 |
||
|---|---|---|---|
| Line 75: | Line 75: | ||
| | Buzzer | Audio feedback | | | Buzzer | Audio feedback | | ||
| | External Power Supply | Power supply for the electromagnetic lock | | | 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 4x4 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: | ||
| + | |||
| + | - all rows are initially kept HIGH | ||
| + | - one row is set to LOW | ||
| + | - the column inputs are read | ||
| + | - if a column is also LOW, the pressed key is found at the intersection between the active row and that column | ||
| + | - 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. | ||
| + | |||
| + | 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 ==== | ||
| - | {{:pm:prj2026:jan.vaduva:schemă_electrica.png?600| Electrical Diagram}} | + | {{:pm:prj2026:jan.vaduva:schemă_electrica.png?650| Electrical Diagram}} |
| + | |||
| + | The electrical diagram presents the main hardware connections of the smart locker system. The schematic shows how the microcontroller is connected to the input modules, output modules and the external locking circuit. | ||
| + | |||
| + | The ATmega328P-XMINI development board is the central element of the circuit. It reads the keypad input, communicates with the display and RFID module, controls the status LEDs and buzzer, and sends the control signal for the electromagnetic lock. | ||
| + | |||
| + | The keypad is connected as a 4x4 matrix. Four pins are used as row outputs, while four pins are used as column inputs with pull-up resistors. During operation, the microcontroller activates one row at a time and reads the columns in order to detect which key is pressed. | ||
| + | |||
| + | The display is connected through the I2C interface. This requires only two signal lines: SDA for data and SCL for the clock signal. | ||
| + | |||
| + | The RFID reader is connected through the SPI interface. The SPI connection uses separate lines for MOSI, MISO, SCK and SS. These lines allow the microcontroller to exchange data with the RFID module and read the identifier of the scanned card. | ||
| + | |||
| + | The green and red LEDs are connected to digital output pins through resistors. The resistors are required in order to limit the current through the LEDs and protect both the LEDs and the microcontroller pins. | ||
| + | |||
| + | The buzzer is connected to a digital output pin and is used to provide audio feedback. Different sound patterns can be generated by switching the output pin between HIGH and LOW at different time intervals. | ||
| + | |||
| + | The electromagnetic lock is not powered directly from the microcontroller. Instead, it is controlled through a MOSFET-based switching circuit. This is necessary because the lock requires more current than a microcontroller pin can safely provide. The microcontroller only sends a low-current control signal to the MOSFET driver, while the external power supply provides the current required by the lock. | ||
| + | |||
| + | The external power supply is used for the electromagnetic lock circuit. The ground of the external power supply is connected to the ground of the microcontroller circuit. This common ground is required so that the control signal from the microcontroller has the same voltage reference as the MOSFET driver circuit. | ||
| + | |||
| + | 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 | ||
| + | * I used a generic motor symbol to represent the electromagnetic lock, since TinkerCad does not provide a dedicated solenoid lock component | ||
| + | |||
| + | These replacements were used only for schematic representation purposes. The real implementation uses the ATmega328P-XMINI board, an OLED display, an RFID RC522 module and a MOSFET E-Switch module for controlling the electromagnetic lock. | ||
| + | |||
| + | ==== Hardware Assembly and Component Testing ==== | ||
| + | |||
| + | The following images show the assembled hardware prototype of the smart locker system. The components are connected to the ATmega328P-XMINI development board using jumper wires and a breadboard. | ||
| + | |||
| + | The prototype includes the 4x4 keypad, OLED display, status LEDs, buzzer, MOSFET E-Switch module and the electromagnetic lock. The keypad is used for PIN input, while the OLED display shows the current state of the system. The LEDs and buzzer provide visual and audio feedback during the authentication process. | ||
| + | |||
| + | {{:pm:prj2026:jan.vaduva:smart_locker_mesaj_int.jpeg?500|Smart Locker welcome message}} | ||
| + | |||
| + | In the first image, the OLED display shows the initial message of the system: **SMART LOCKER / SCAN CARD**. This means that the system is powered on and is waiting for the RFID card to be scanned before allowing the user to enter the PIN code. | ||
| + | |||
| + | This image confirms that the OLED display is correctly powered and that the microcontroller can communicate with it through the I2C interface. It also shows the main hardware prototype, including the keypad, status LEDs, buzzer and lock control circuit. | ||
| + | |||
| + | {{:pm:prj2026:jan.vaduva:smart_locker_rfid_ok.jpeg?500|Smart Locker after successful RFID authentication}} | ||
| + | |||
| + | In the second image, the OLED display shows the message **RFID OK / ENTER PIN**. This represents the state reached after a successful RFID authentication step. | ||
| + | |||
| + | At this point, the system waits for the user to enter the PIN code. The status LEDs are also active and provide visual feedback during this state. This demonstrates that the microcontroller correctly controls the OLED display and the LED output pins according to the current authentication state. | ||
| + | |||
| + | These hardware tests confirm that: | ||
| + | * the OLED display correctly shows messages generated by the microcontroller | ||
| + | * the microcontroller can change the displayed message depending on the system state | ||
| + | * the status LEDs provide visual feedback | ||
| + | * the keypad, display, LEDs, buzzer and lock control circuit are connected in the same working prototype | ||
| + | * the hardware prototype is suitable for testing the complete smart locker authentication flow | ||
| ===== Software Design ===== | ===== Software Design ===== | ||
| + | |||
| + | The software implementation is currently functional and integrates all the main hardware components of the project. | ||
| + | |||
| + | The implemented features are: | ||
| + | * RFID card detection using the RC522 module | ||
| + | * validation of two authorized RFID cards | ||
| + | * PIN input using a 4x4 matrix keypad | ||
| + | * PIN verification using a 4-digit code | ||
| + | * PIN change functionality using the D key | ||
| + | * PIN storage in EEPROM memory | ||
| + | * OLED display messages for each system state | ||
| + | * visual feedback using green and red LEDs | ||
| + | * audio feedback using a buzzer | ||
| + | * electromagnetic lock control through a MOSFET driver | ||
| + | * warning mechanism after three failed authentication attempts | ||
| + | * UART debug messages for testing and validation | ||
| + | |||
| + | The system starts in the default state where the OLED display shows: | ||
| + | |||
| + | * SMART LOCKER | ||
| + | * SCAN CARD | ||
| + | |||
| + | In this state, the microcontroller continuously checks for an RFID card. If the scanned card is authorized, the system moves to the PIN input state. If the card is not authorized, access is denied and the user is asked to scan again. | ||
| + | |||
| + | After a valid RFID card is detected, the user must enter the correct PIN. If the PIN is correct, the electromagnetic lock is activated for a few seconds, the green LED turns on, the buzzer plays a success sound and the display shows that the locker is unlocked. If the PIN is incorrect, the red LED turns on, the buzzer emits an error sound and the display shows an access denied message. | ||
| + | |||
| + | The software also supports changing the current PIN. This is done by pressing the D key while the system is waiting for an RFID card. The user must scan an authorized RFID card, enter the old PIN, enter the new PIN and confirm it. If both new PIN entries match, the new PIN is saved in EEPROM and will remain stored even after the board is powered off. | ||
| + | |||
| + | ==== Libraries and Low-Level Modules Used ==== | ||
| + | |||
| + | The project was implemented in C using AVR-specific libraries. I chose to use low-level AVR libraries instead of high-level Arduino libraries because they provide direct control over the microcontroller registers and make the project more relevant to the laboratory concepts. | ||
| + | |||
| + | The main libraries used are: | ||
| + | |||
| + | * avr/io.h | ||
| + | * util/delay.h | ||
| + | * stdint.h | ||
| + | * avr/eeprom.h | ||
| + | |||
| + | The avr/io.h library is used for direct access to the microcontroller registers. This allows the program to configure pins as inputs or outputs, enable pull-up resistors, control PORT registers and use hardware peripherals such as SPI, TWI/I2C and UART. | ||
| + | |||
| + | The util/delay.h library is used for generating small delays required by the hardware modules. For example, delays are used for keypad debouncing, buzzer tone generation, RFID reset timing, OLED initialization and keeping the lock open for a fixed time. | ||
| + | |||
| + | The stdint.h library is used for fixed-width integer types such as uint8_t and uint16_t. This is important in embedded systems because the size of each variable must be predictable. | ||
| + | |||
| + | The avr/eeprom.h library is used to store the PIN code in the internal EEPROM memory of the ATmega328P. This allows the PIN to remain saved even after the system is restarted or disconnected from power. | ||
| + | |||
| + | No external Arduino libraries were used for the main components. The RFID, SPI, I2C, OLED, keypad, buzzer and lock control logic were implemented manually. This gives more control over how each peripheral works and demonstrates a better understanding of the microcontroller. | ||
| + | |||
| + | ==== Project Structure ==== | ||
| + | |||
| + | The software was organized into multiple modules in order to make the project easier to understand, maintain and debug. | ||
| + | |||
| + | The main files of the project are: | ||
| + | |||
| + | * main.c - contains the main initialization and the main loop | ||
| + | * config.h - contains pin definitions, RFID register definitions and constants | ||
| + | * app_state.c / app_state.h - contains the global state of the application | ||
| + | * uart.c / uart.h - contains UART debugging functions | ||
| + | * spi.c / spi.h - contains SPI communication functions | ||
| + | * rfid.c / rfid.h - contains the RC522 RFID logic | ||
| + | * twi.c / twi.h - contains I2C/TWI communication functions | ||
| + | * oled.c / oled.h - contains OLED display functions | ||
| + | * keypad.c / keypad.h - contains keypad scanning logic | ||
| + | * buzzer.c / buzzer.h - contains buzzer sound functions | ||
| + | * pin_manager.c / pin_manager.h - contains PIN verification, EEPROM loading/saving and PIN change helpers | ||
| + | * lock_control.c / lock_control.h - contains lock, error and warning feedback functions | ||
| + | * app_logic.c / app_logic.h - contains the higher-level authentication logic | ||
| + | |||
| + | The project is based on a state machine. The main states are: | ||
| + | |||
| + | * STATE_WAIT_RFID | ||
| + | * STATE_WAIT_PIN | ||
| + | * STATE_CHANGE_WAIT_RFID | ||
| + | * STATE_CHANGE_OLD_PIN | ||
| + | * STATE_CHANGE_NEW_PIN | ||
| + | * STATE_CHANGE_CONFIRM_PIN | ||
| + | |||
| + | The state machine makes the program easier to control because each user action is interpreted depending on the current state. | ||
| + | |||
| + | For example: | ||
| + | * in STATE_WAIT_RFID, the system only waits for a valid RFID card | ||
| + | * in STATE_WAIT_PIN, the system accepts PIN digits | ||
| + | * in STATE_CHANGE_OLD_PIN, the system verifies the old PIN | ||
| + | * in STATE_CHANGE_NEW_PIN, the system stores the new PIN temporarily | ||
| + | * in STATE_CHANGE_CONFIRM_PIN, the system checks if the confirmation PIN matches | ||
| + | |||
| + | ==== Novelty Element ==== | ||
| + | |||
| + | The novelty of the project consists of combining two authentication methods in a small locker system: RFID card verification and PIN code verification. | ||
| + | |||
| + | A normal locker usually uses either a physical key or only a PIN code. In this project, access is granted only if both conditions are satisfied: | ||
| + | * the user has an authorized RFID card | ||
| + | * the user knows the correct PIN code | ||
| + | |||
| + | This makes the system more secure than a simple PIN-based locker, because observing the PIN is not enough to unlock the locker without the authorized RFID card. | ||
| + | |||
| + | Another important aspect is that the project behaves like a complete access control system, not only like a simple lock circuit. The system includes: | ||
| + | * OLED messages for each authentication step | ||
| + | * visual feedback using red and green LEDs | ||
| + | * audio feedback using a buzzer | ||
| + | * automatic warning after multiple failed attempts | ||
| + | * PIN change functionality | ||
| + | * permanent PIN storage after restart | ||
| + | |||
| + | Because of this, the project is closer to a real smart locker system, where the user receives clear feedback and the access process is controlled by multiple security checks. | ||
| + | |||
| + | ==== Laboratory Functionalities Used ==== | ||
| + | |||
| + | The project uses several concepts and functionalities studied during the laboratories. | ||
| + | |||
| + | Digital input/output was used for the LEDs, buzzer, keypad and electromagnetic lock control. The LEDs indicate the current authentication state, the buzzer provides audio feedback, and the lock is controlled through a digital output connected to the MOSFET driver. The keypad is also handled using GPIO pins: the rows are configured as outputs, while the columns are configured as inputs with internal pull-up resistors. | ||
| + | |||
| + | UART communication was used during development for debugging and validation. The microcontroller sends messages to the computer, such as pressed keypad keys, scanned RFID UIDs, authentication results and PIN change steps. This made it easier to test each module separately before validating the complete system. | ||
| + | |||
| + | Timing concepts were used for keypad debouncing, buzzer sound generation, LED blinking, RFID reset timing, OLED initialization and the fixed unlock duration of the electromagnetic lock. The buzzer sounds are generated by rapidly switching a digital output pin between HIGH and LOW with different delays. | ||
| + | |||
| + | SPI communication was used for the RFID RC522 module. The ATmega328P acts as the SPI master and communicates with the RFID reader using MOSI, MISO, SCK and SS lines. Through SPI, the microcontroller reads and writes RC522 registers and obtains the UID of the scanned RFID card. | ||
| + | |||
| + | I2C communication was used for the OLED display. The display receives commands and data from the microcontroller through the SDA and SCL lines. It is used to show the current state of the system, such as scanning the card, entering the PIN, access denied, unlocked state and successful PIN change. | ||
| + | |||
| + | ==== Interaction Between Functionalities ==== | ||
| + | |||
| + | The interaction between modules follows the authentication flow of the locker. | ||
| + | |||
| + | First, the main loop continuously scans the keypad and checks the RFID reader when no key is pressed. The RFID module communicates with the microcontroller through SPI. When a card is detected, the UID is read and compared with the authorized UIDs stored in the program. | ||
| + | |||
| + | If the RFID card is valid, the application state changes to PIN input mode. The OLED display is updated using the I2C interface and the buzzer emits a success sound. The green and red LEDs blink alternately while the system waits for the PIN. | ||
| + | |||
| + | The keypad module scans the 4x4 matrix keypad by activating one row at a time and reading the column inputs. Each digit entered by the user is stored in an array. The OLED display shows progress using star characters instead of showing the actual digits, which improves security. | ||
| + | |||
| + | When four digits are entered, the PIN manager compares the entered PIN with the current PIN. If the PIN is correct, the lock control module activates the electromagnetic lock through the MOSFET driver. At the same time, the OLED, LEDs and buzzer provide positive feedback. | ||
| + | |||
| + | If the PIN is incorrect, the error feedback function is called. The red LED turns on, the buzzer plays an error sound and the OLED displays an access denied message. After three failed attempts, the warning function is triggered and a stronger buzzer pattern is used. | ||
| + | |||
| + | The PIN change functionality uses the same modules, but in a different sequence. The user presses D, scans an authorized RFID card, enters the old PIN, enters the new PIN and confirms it. If the confirmation is correct, the new PIN is saved to EEPROM. | ||
| + | |||
| + | ==== Validation and Testing ==== | ||
| + | |||
| + | The project was validated step by step, by testing each component separately and then testing the complete system. | ||
| + | |||
| + | The OLED display was tested by showing different messages such as: | ||
| + | |||
| + | * SMART LOCKER / SCAN CARD | ||
| + | * RFID OK / ENTER PIN | ||
| + | * PIN OK / UNLOCKED | ||
| + | * ACCESS / DENIED | ||
| + | * PIN SAVED / SUCCESS | ||
| + | |||
| + | This confirmed that the I2C communication and OLED control functions work correctly. | ||
| + | |||
| + | The keypad was tested by printing each pressed key over UART. This helped verify that the row-column scanning logic correctly detects all keys. | ||
| + | |||
| + | The RFID module was tested by reading and printing the UID of scanned cards through UART. After that, the UID values of the authorized cards were added in the program and compared with the scanned UID. | ||
| + | |||
| + | The buzzer and LEDs were tested using different feedback patterns: | ||
| + | * success sound and green LED for valid authentication | ||
| + | * error sound and red LED for invalid authentication | ||
| + | * warning sound after multiple failed attempts | ||
| + | |||
| + | The electromagnetic lock was tested by activating the MOSFET driver from the microcontroller. The lock opens only after both authentication steps are passed: valid RFID card and correct PIN. | ||
| + | |||
| + | The complete project was validated by testing the following scenarios: | ||
| + | * valid RFID card and correct PIN | ||
| + | * valid RFID card and wrong PIN | ||
| + | * invalid RFID card | ||
| + | * three consecutive wrong attempts | ||
| + | * PIN change with correct old PIN | ||
| + | * PIN change with wrong old PIN | ||
| + | * PIN confirmation mismatch | ||
| + | * EEPROM PIN persistence after restart | ||
| + | |||
| + | ==== Sensor Calibration ==== | ||
| + | |||
| + | The project does not use analog sensors that require numerical calibration, such as temperature, light or distance sensors. However, the RFID reader and keypad required practical validation and calibration. | ||
| + | |||
| + | For the RFID module, I tested the reading distance and the orientation of the RFID cards. The card was placed at different distances and angles from the RC522 reader in order to determine a position where the UID is read consistently. The final placement of the RFID reader was chosen so that the card can be scanned reliably without requiring physical contact with the module. | ||
| + | |||
| + | The authorized RFID cards were calibrated through an enrollment-like process. Each card was scanned, and its UID was printed through UART. After that, the UID values were added in the program as authorized cards. During operation, every scanned UID is compared with these stored values. | ||
| + | |||
| + | For the keypad, calibration consisted of verifying that each physical key corresponds to the correct character in the software matrix. I used UART debug messages to print every pressed key and checked that the detected values matched the real keypad layout. | ||
| + | |||
| + | The keypad also required debounce handling. A short delay is used after detecting and releasing a key, so that a single physical press is not interpreted as multiple presses. | ||
| + | |||
| + | For the electromagnetic lock, I tested the activation time and selected a duration long enough for the locker to be opened, but short enough to avoid keeping the solenoid powered unnecessarily. | ||
| + | |||
| + | ==== Optimizations ==== | ||
| + | |||
| + | Several optimizations were made in the software and hardware behavior of the project. | ||
| + | |||
| + | The first optimization was using a state machine. Instead of writing the entire logic as a long sequence of conditions without structure, the program uses explicit states. This makes the logic clearer and avoids accepting inputs in the wrong context. | ||
| + | |||
| + | The second optimization was using EEPROM for PIN storage. Without EEPROM, the PIN would reset to the default value every time the system loses power. By storing the PIN in EEPROM, the system behaves more like a real locker, where the changed PIN remains saved. | ||
| + | |||
| + | The third optimization was displaying stars instead of the actual PIN digits. This improves privacy and prevents nearby users from reading the PIN directly from the display. | ||
| + | |||
| + | The fourth optimization was using internal pull-up resistors for the keypad columns. This reduces the number of external components needed and makes the circuit simpler. | ||
| + | |||
| + | The fifth optimization was using SPI for the RFID reader and I2C for the OLED display. These are hardware-supported communication interfaces on the ATmega328P and are more efficient and organized than using many separate GPIO pins. | ||
| + | |||
| + | The sixth optimization was separating the lock power circuit from the microcontroller. The electromagnetic lock is powered through an external supply and controlled through a MOSFET driver. This protects the microcontroller from high current consumption. | ||
| + | |||
| + | Another practical optimization was adding a timeout mechanism to the I2C communication. Because the electromagnetic lock can introduce electrical noise, the OLED communication may occasionally become unstable. A timeout prevents the program from remaining blocked forever inside an I2C waiting loop. | ||
| ===== Results ===== | ===== Results ===== | ||
| + | |||
| + | ==== Final Project Behavior ==== | ||
| + | |||
| + | The final system successfully implements a smart locker with two-step authentication. | ||
| + | |||
| + | The normal authentication flow is: | ||
| + | - the system displays SMART LOCKER / SCAN CARD | ||
| + | - the user scans an RFID card | ||
| + | - if the card is valid, the system displays RFID OK / ENTER PIN | ||
| + | - the user enters the 4-digit PIN | ||
| + | - if the PIN is correct, the lock opens and the display shows PIN OK / UNLOCKED | ||
| + | - after a few seconds, the lock closes again and the system returns to SCAN CARD mode | ||
| + | |||
| + | If the RFID card is invalid, access is denied and the system asks the user to scan again. | ||
| + | |||
| + | If the PIN is wrong, access is denied and the system returns to the initial state. | ||
| + | |||
| + | If the user enters a wrong PIN or scans invalid cards multiple times, the system activates a warning behavior using the buzzer and red LED. | ||
| + | |||
| + | The PIN change flow is: | ||
| + | - the user presses D | ||
| + | - the system asks for an authorized RFID card | ||
| + | - the user enters the old PIN | ||
| + | - the user enters a new 4-digit PIN | ||
| + | - the user confirms the new PIN | ||
| + | - if the confirmation matches, the new PIN is saved in EEPROM | ||
| + | |||
| + | ==== Demo Video ==== | ||
| + | |||
| + | The first demo video presents the main functionality of the Smart Locker system. | ||
| + | |||
| + | In this video, I first demonstrate the normal unlocking flow. The locker starts in the initial state and waits for an RFID card. After scanning an authorized RFID card, the system asks for the PIN code. When the correct PIN is entered, the electromagnetic lock is activated, the green LED turns on, the buzzer gives a success sound and the OLED display shows that the locker is unlocked. | ||
| + | |||
| + | The video also demonstrates the PIN change functionality. This mode is entered by pressing the D key. After that, the system asks for an authorized RFID card, then for the old PIN code. If the old PIN is correct, the user enters a new PIN and then confirms it. If the confirmation matches, the new PIN is saved and the display shows that the PIN was successfully changed. | ||
| + | |||
| + | At the end of the demo, I confirm that the PIN was changed successfully by using the new PIN for authentication. | ||
| + | |||
| + | [[https://drive.google.com/file/d/1yjfFrMsylPaND1jU6PLwlV5uNAcqbV_M/view?usp=sharing|Smart Locker Main Demo]] | ||
| + | |||
| + | The second demo video presents the security warning mechanism. After three consecutive wrong PIN attempts, the system activates the alarm behavior using the buzzer and red LED, then blocks access for a short waiting period. | ||
| + | |||
| + | [[https://drive.google.com/file/d/1yvxkDKo3Rw6DNS0Kf5T5cH0UWKtEfO21/view?usp=sharing|Smart Locker Alarm and Lockout Demo]] | ||
| ===== References ===== | ===== References ===== | ||
| + | |||
| + | * ATmega328P Datasheet - Microchip Technology | ||
| + | * ATmega328P-XMINI User Guide - Microchip Technology | ||
| + | * MFRC522 RFID Reader Datasheet - NXP Semiconductors | ||
| + | * SSD1306 OLED Display Datasheet | ||
| + | * AVR Libc Documentation - avr/io.h, util/delay.h, avr/eeprom.h | ||