LockBox (Smart Locker)

by avaalizadeh in Circuits > Raspberry Pi

37 Views, 2 Favorites, 0 Comments

LockBox (Smart Locker)

20240617_112453.jpg

I am a Multimedia & Creative Technology student at HOWEST, and I have decided to make a smart locker as my project. This smart locker can be found in public places such as libraries or facilities such as schools. It is easy to use, with users getting a random locker assigned to their name, allowing them to temporarily store their supplies. 


To check the status of the locker door, I use a light intensity sensor. If the light intensity is high, it means that the door is open, and vice versa. Additionally, there is a weight sensor with a maximum weight limit of 10 kg, which measures the weight of the stored materials in the locker. The weight sensor also helps determine whether a locker is available, indicated by a total weight of 0.

Supplies

Components

- 1x Green LED lamp

- 1x Red LED lamp

- 1x Toggle Button

- 1x LDR sensor

- 1x HX711 Load cell

- 1x LCD display 16x2

- 1x Servomotor

- 1x RFID reader

- 3x Resistors of 470 ohms

- 1x Resistor of 10k ohms

- 1x PCF8574AN

- 1x MCP3008

- 1x Potentiometer

- 2x Breadboards

- 1x Raspberry Pi 4B

- 1x Power supply

- 1x Power supply for the Raspberry Pi

- 1x Network cable

- A lot of wires


Housing

- 1x Slide lock

- 8x MDF plates with a thickness of 3mm and a size of 60cm x 40cm

- 1x Metal wire of 1.2mm

- Montage glue

- Wood glue

- Hot glue

- 1x Piano hinge

Connect the Components

You will need to start connecting all the components based on the schematics above. Note that there are a few changes regarding the GPIO pins, which won’t match the assigned GPIO pins in my code.

Databasestructure

Schermafbeelding 2024-06-17 103119.png

warningType Table

- **warningTypeId (INT)**: A unique identifier for each type of warning.

- **title (VARCHAR(45))**: The title or name of the warning type.

- **description (VARCHAR(255))**: A detailed description of the warning type.


warning Table

- **warningId (INT)**: A unique identifier for each warning record.

- **registrationId (INT)**: A foreign key that links the warning to a specific registration.

- **warningTypeId (INT)**: A foreign key that links the warning to a specific type of warning (warningType).

- **time (DATETIME)**: The date and time when the warning was issued.


device Table

- **deviceId (INT)**: A unique identifier for each device.

- **name (VARCHAR(45))**: The name of the device.

- **unit (VARCHAR(45))**: The unit of measurement for the device's readings.

- **description (VARCHAR(255))**: A detailed description of the device.


history Table

- **historyId (INT)**: A unique identifier for each history record.

- **deviceId (INT)**: A foreign key that links the history record to a specific device.

- **time (DATETIME)**: The date and time when the historical data was recorded.

- **value (FLOAT)**: The recorded value of the device at the specified time.


user Table

- **userId (INT)**: A unique identifier for each user.

- **firstName (VARCHAR(45))**: The first name of the user.

- **lastName (VARCHAR(45))**: The last name of the user.

- **dateOfBirth (VARCHAR(45))**: The date of birth of the user.

- **badgeNumber (VARCHAR(12))**: A unique badge number assigned to the user.

- **email (VARCHAR(255))**: The email address of the user.

- **password (VARCHAR(255))**: The password of the user for authentication purposes.


registration Table

- **registrationId (INT)**: A unique identifier for each registration.

- **userId (INT)**: A foreign key that links the registration to a specific user.

- **lockerNumber (INT)**: The number assigned to a specific locker in the registration.

- **time (DATETIME)**: The date and time of the registration.

- **lightIntensity (INT)**: The light intensity level recorded at the time of registration.

- **weight (INT)**: The weight recorded at the time of registration.


locker Table

- **lockerId (INT)**: A unique identifier for each locker.

- **status (VARCHAR(15))**: The current status of the locker (e.g., available, occupied).

- **location (VARCHAR(225))**: The physical location of the locker.

- **maximumWeight (FLOAT)**: The maximum weight capacity of the locker.


Each table and column is designed to capture specific information and establish relationships between different entities in the database, ensuring a well-structured and organized data management system.

Setup

Before we start coding, we need to make some preparations.


Repository

First, make sure to clone a repository from GitHub or any other source you prefer.


Virtual Environment

Create a new virtual environment by following these steps:


1. Open a Python file (optional, but can be helpful).

2. Go to the console and execute the following command:


On Windows:

  py -m venv venv_fswd


On macOS

  python3 -m venv venv_fswd


3. Close the current terminal and open a new one to ensure it uses the new virtual environment.


Install the Necessary Packages

To install the required packages, run the following command:


On Windows:

pip install -r ./requirements.txt

On macOS:

pip install -r requirements.txt


Now, you're ready to start coding!

Activate Bus 0 & Bus 1

Activating SPI on Raspberry Pi


SPI (Serial Peripheral Interface) allows communication with external devices using a synchronous serial protocol. Follow these steps to activate SPI on your Raspberry Pi:


1. Access Raspberry Pi Configuration:

  - Open a terminal on your Raspberry Pi or connect to it via SSH.


2. Launch Raspberry Pi Configuration Tool:

  - Enter the following command to open the Raspberry Pi Configuration tool:

   sudo raspi-config


3. Navigate to Interface Options:

  - Use the arrow keys to navigate to `Interfacing Options` and press `Enter`.


4. Select SPI:

  - In the Interfacing Options menu, scroll down to `SPI` and press `Enter`.


5. Enable SPI:

  - Select `Yes` when asked if you want to enable SPI, then press `Enter` to confirm.


6. Finish and Reboot:

  - After enabling SPI, you will see a message that SPI is enabled. Press `Enter` to return to the main menu of raspi-config.

  - Select `Finish` and confirm to reboot your Raspberry Pi.


To activate SPI bus 1 on your Raspberry Pi and configure it properly, you need to add a line to the `config.txt` file. Here’s how you can do it:


1. Access the config.txt file:

  - Open a terminal on your Raspberry Pi or connect to it via SSH.


2. Edit the config.txt file:

  - Use a text editor like `nano` or `vi` to edit the `config.txt` file. For example:

   sudo nano /boot/config.txt


3. Add the line to activate SPI bus 1:

  - Scroll to the end of the file and add the following line to enable SPI bus 1:

   dtoverlay=spi1-1cs


  - This line enables SPI bus 1 with 1 chip select (CS) line. If you need more chip selects, you can specify them accordingly (e.g., `spi1-2cs` for 2 chip selects).


4. Save and exit the editor:

  - Press `Ctrl + X` to exit nano, then `Y` to confirm the changes, and `Enter` to save the file.


5. Reboot your Raspberry Pi:

  - After saving the changes to `config.txt`, reboot your Raspberry Pi to apply the configuration:

   sudo reboot now


Verify SPI Activation:

  - After the Raspberry Pi reboots, open a terminal window and enter the following command to check if SPI is enabled:

   ls /dev/spi*


  - You should see `/dev/spidev1.0` and `/dev/spidev1.1` (or more, depending on the number of chip selects specified) listed if SPI bus 1 is correctly enabled.


By following these steps, you activate and configure SPI bus 1 on your Raspberry Pi via the `config.txt` file. Adjustments may be required based on your specific Raspberry Pi model and setup.

Make an Connection for the Database

Schermafbeelding 2024-06-17 093406.png
Schermafbeelding 2024-06-17 093524.png

To set up your database and connect it with the Raspberry Pi using MySQL Workbench, follow these steps:


1. Open MySQL Workbench: Launch MySQL Workbench on your computer.


2. Create a New Connection:

  - Click on the plus (+) icon next to "MySQL Connections" to create a new connection.


3. Configure the Connection:

  - **Connection Name**: Enter a name for your connection.

  - **Hostname**: Enter the IP address of your Raspberry Pi.

  - **Port**: Enter the port number.

  - **Username**: Enter your MySQL username.

  - **Password**: Click on "Store in Vault..." to securely store your password.


4. Test the Connection:

  - Click on the "Test Connection" button to ensure that the connection settings are correct.

  - If the connection is successful, you will see a confirmation message. If not, check your settings and ensure that your Raspberry Pi is configured to allow remote connections.


5. Save and Connect:

  - Once the connection is successful, click "OK" to save the connection.

  - Double-click on the new connection to connect to your MySQL database on the Raspberry Pi.


Now you can use MySQL Workbench to manage your database on the Raspberry Pi.

Establish a Connection Between Database & Backend

Schermafbeelding 2024-06-17 104455.png
Schermafbeelding 2024-06-17 104517.png

To set up your configuration file for secure database connection, follow these steps:


1. Locate the File:

  - In your GitHub repository, navigate to the `backend` folder.

  - Find the file named `example_config.py`.


2. Edit the File:

  - Open `example_config.py` in a text editor.

  - Update the following lines according to the image provided (replace the placeholders with your actual database connection details):


[connector_python]
user = 'your_username'
host = 127.0.0.1
port = 3306
password = 'your_password'
database = smart-locker

[application_config]
driver = 'SQL Server'


3. Rename the File:

  - Save your changes.

  - Rename `example_config.py` to `config.py`.


4. Ensure `config.py` is Ignored by GitHub:

  - Check that `config.py` is listed in your `.gitignore` file to prevent it from being pushed to GitHub.

  - If not, open or create a `.gitignore` file in the root of your repository and add the following line:


   backend/config.py


By following these steps, your configuration details will be used by your application but will not be exposed in your GitHub repository, keeping them secure.

Lasercutting of the Housing

1. Gather Materials:

  - Ensure you have a MDF plank with the dimensions 60cm x 40cm and a thickness of 3mm.


2. Prepare the Files:

  - Obtain the laser cutting files provided. These files should be in a format compatible with your laser cutter, such as .dxf, .svg, or similar.


3. Load the Files:

  - Open the laser cutting software and load the provided files.


4. Configure the Laser Cutter:

  - Set up your laser cutter according to the specifications of the MDF plank.

  - Configure the laser cutter settings to cut 3mm thick MDF. These settings include the speed, power, and frequency of the laser, which will vary depending on your specific laser cutter model.


5. Position the MDF Plank:

  - Place the MDF plank on the laser cutter bed, ensuring it is properly aligned and secured.


6. Execute the Cut:

  - Start the laser cutting process. Monitor the cutting to ensure it is proceeding correctly and safely.


7. Assemble the Housing:

  - Once all pieces are cut, carefully remove them from the laser cutter.

  - Follow any provided assembly instructions to construct the housing from the cut pieces.


By following these steps, you can successfully laser cut and assemble the housing using the provided files and materials.

Assembling of Housing

20240610_170847.jpg
20240610_171216.jpg
20240610_171851.jpg
20240610_171822.jpg
20240611_020647.jpg

1. Prepare the Pieces:

  - Ensure you have the bottom, back, left, and right side pieces cut and ready.

  - Gather wood glue and a small brush or applicator for precise glue application.


2. Assemble the Bottom and Back:

  - Apply Glue: Put glue on the protruding puzzle pieces of the bottom piece.

  - Attach the Back: Align the back piece with the glued puzzle pieces of the bottom piece.

  - Hold in Place: Keep the back piece upright and straight by placing it between two objects while the glue dries.

  - Reinforce the Glue: Once the glue has partially dried, add an extra layer of glue to the connection between the bottom and back pieces for added strength.


3. Attach the Right and Left Sides:

  - Repeat the process for the right and left side pieces.

  - Apply Glue: Put glue on the protruding puzzle pieces of the bottom piece and the previously attached back piece.

  - Attach the Sides: Align and attach the right and left side pieces with the glued puzzle pieces.

  - Hold in Place: Ensure the sides are held upright and straight while the glue dries.


4. Check Alignment:

  - Use a set square to verify that the bottom, back, and side pieces are glued at right angles to each other.

  - Adjust as necessary to ensure everything is square and aligned.


5. Allow Glue to Dry:

  - Let the glue dry completely according to the manufacturer’s instructions before moving on to the next steps of the assembly.

Adjusting the Housing for the Components

20240613_182602.jpg
20240613_184753.jpg
20240613_184808.jpg
20240613_190102.jpg
20240613_223432.jpg
20240613_232306.jpg
20240613_232316.jpg
d3e97636-136a-4bf6-8b4e-cc8f5b40d20c.jpg

Prepare Holes:

  • Drill two M5-sized holes at the bottom of the housing.
  • Drill two M4-sized holes at the bottom inside of the storage locker.


Install Weight Sensor:

  • Securely attach the weight sensor between the bottom of the housing and the bottom of the storage locker, aligning with the drilled holes.


Attach Piano Hinge:

  • Use montage glue to adhere the piano hinge to the designated location.
  • Allow the glue to dry completely.


Assemble Components:

  • Apply montage glue to the back of the housing to affix components and the slide lock securely.
  • Similarly, glue the divider into place.


Secure Wires:

  • Use hot glue to secure wires in place, ensuring they are neatly organized and do not interfere with the circuit.


Final Check:

  • Ensure all glued components are securely attached and allow sufficient time for the glues to set completely before proceeding further.


Note:

Do not immediately glue the front panel. Test all components thoroughly first to ensure everything functions without any issues. If all tests are successful, proceed to glue the front panel in place. Avoid gluing the top to maintain access to the circuitry as needed.