Smart Bike Lock - MCT Howest

by Noor Sissau in Outside > Bikes

96 Views, 0 Favorites, 0 Comments

Smart Bike Lock - MCT Howest

Flyer project one.png
WhatsApp Image 2025-06-18 at 21.01.59 (2).jpeg

Hello, I am Noor Sissau. I am a student at Howest Kortrijk. I study MCT (Multimedia and Creative Technologies). For my first project for school I have created a smart bike lock that enhances the security of your bicycle by using advanced technology. This lock can be controlled remotely and sends real-time status updates to a connected website. It detects when someone tries to tamper with it and alerts you immediately.

The lock also features automatic locking and unlocking using RFID technology, allowing you to unlock it simply by presenting your RFID tag, making it convenient to use without needing keys.

In this Instructable, I will guide you through the process of building this smart bike lock. If you need any help, you can find all the code and design files on my GitHub page linked below or you can contact me here on instructables.

Supplies

Sensors:

  1. GPS sensor: To determine your location.
  2. RFID sensor: To identify you and save your data to your account.
  3. Accelerosensor: To measure the movement of the lock


Actuators:

  1. Servo motor: To open en close the lock.
  2. LCD display: Shows ip adress.
  3. Potentiometer: To control the brightness of the LCD screen
  4. RGB led: To provide feedback to the user about whether the bike is locked or unlocked


Regulators

  1. MCP 3008: To read your LDR

Controller

  1. RPi5: To run everything on
  2. esp32: To communicate wirelessly with the Raspberry Pi via Bluetooth and send all sensor data.


Extra parts:

  1. Breadboards: For easy connection of unsolderable wires and devices.
  2. Breadboard powersupply 3V3/5V: To power the LCD
  3. Jumperkabels: To connect everything
  4. GPIO extension: To place your devices easier on your RPi
  5. Micro sd card: to place your img on for the RPi
  6. RPi5 powersupply: To power RPi5
  7. USB to Micro-USB cable: To write code on the esp32
  8. Powerbank: To power the esp32

If you are interested in where you can buy all of this and how much it costs, take a look at my bill of materials. The cost lies around €280.

Make the Circuit

Screenshot 2025-06-19 161607.png
Screenshot 2025-06-19 161642.png
WhatsApp Image 2025-06-19 at 16.02.14 (2).jpeg
WhatsApp Image 2025-06-19 at 16.02.14 (1).jpeg
WhatsApp Image 2025-06-19 at 16.02.14.jpeg

To build the circuit for the Smart Bike Lock, simply follow the Fritzing diagram I created. You can find it available as a PDF.


Fritzing Wire Color Code

The color coding used in the Fritzing diagrams is as follows:

  1. Red: 5V
  2. Black: GND
  3. Orange: 3.3V
  4. Other colors: Wires connected to components



What do you need:

  1. GPS sensor
  2. Accelerosensor
  3. RFID sensor
  4. 2x breadbord
  5. Jumperkabels
  6. Servo motor
  7. LCD display
  8. Potentiometer
  9. MCP 3008
  10. RPi
  11. esp32
  12. Breadboard power supply
  13. USB to Micro-USB cable

Preparing the Raspberry Pi

After you have created the circuit, we can begin the next part: setting up the RPi.

What you need:

RPi Micro SD card

Step 1:

Open Raspberry Pi Imager. Insert the micro SD card into your PC.

Step 2:

Choose your Raspberry Pi model and operating system. I recommend RPi OS Lite 64-bit. Then select your storage device and continue.

Step 3:

Personalize the settings and continue.

Step 4:

Insert the SD card into your RPi. Connect your Raspberry Pi to your PC using a LAN cable. Connect through SSH.

If you can't connect, try to troubleshoot.

Creating Database

database_nu.png

Now connect to MySQL trough ssh and create this database according to my schema.

If you have problems or can't create the database, use my file safevelo.sql.

You can find that on my GitHub page following this path: Database -> safevelo.sql.


Coding the Project

Screenshot 2025-06-19 161943.png
Screenshot 2025-06-19 at 08-54-48 Safe Velo.png
Screenshot 2025-06-19 at 08-55-06 Safe Velo.png
Screenshot 2025-06-19 at 08-55-42 Safe Vélo login.png

Webdesign


To begin, design your website in Figma. If you don’t want to create the entire design yourself, visit my GitHub page and you can see what i have designed.

After you have created the design, you can begin coding the front end of the page. Start with HTML for all your pages then go to CSS

Now that you have created the front end, we have a place to show all our data, so we can begin coding the sensors.


ESP32 code


Recommended Approach: Test Components Individually First

My recommendation is to start by mastering each component separately. In my case, I tested the GPS sensor, accelerometer, RFID reader, and servo motor one by one, writing working code for each of them.

Next, I established a stable Bluetooth connection between the Raspberry Pi 5 and the ESP32. Only after that did I begin planning the overall flow of the project.

In the backend code, you’ll find a file called bluetooth_test.py (or something similar), which shows how I started the project. From there, I continued building and refining my code.


Code Structure: Separate Classes for Each Component

To control the components, I use four main libraries/classes:

  1. BluetoothSerial.h → for the Bluetooth connection
  2. Wire.h → for I²C functions used by the MPU (accelerometer)
  3. SPI.h and MFRC522.h → for reading RFID tags


GPS Module Setup

For the GPS module, I initialize serial communication with the following line: Serial2.begin(9600, SERIAL_8N1, 16, 17)

To enable serial communication using RX pin 16 and TX pin 17.



ESP32 Code Location

You can find my ESP32 code on my GitHub, located in the folder named Backend, in the file ESP32-code.ino.



Backend


LCD

To show the text on the LCD, I use my custom class located in the Backend/classes/LCD.py. This class handles communication between the LCD and the Raspberry Pi, and controls the LCD using the PCF8574 I²C I/O expander.


Backend: App.py


The App.py file is the core of the Safe Velo backend, running on the Raspberry Pi. It is responsible for:

  1. Controlling and interacting with connected hardware components (LCD)
  2. Communicating with the ESP32 over Bluetooth:
  3. Sends control commands to the ESP32
  4. Receives sensor data via Bluetooth

It also integrates with a REST API and Socket.IO to keep the web interface continuously updated with the latest data from all sensors. This ensures real-time feedback and synchronization between the physical system and the user interface.


Frontend: App.js

The App.js file powers the Safe Velo web-based user interface. It communicates with the backend to retrieve and display live system data in real time.


Live Data Visualization

  1. Displays current lock status
  2. Shows the live location of the bike using Mapbox
  3. Includes two interactive charts:
  4. Accelerometer sensor data
  5. Bike usage statistics
  6. Displays user information on the profile page
  7. Presents historical data and trends using ApexCharts

Real-Time Updates via Socket.IO

  1. Listens for live events from the backend
  2. Instantly updates the UI when:
  3. The bike’s status changes
  4. An RFID tag is scanned
  5. New accelerometer data is received


Code Comments for Clarity

Throughout my code, I’ve added comments to most steps to make everything as clear and understandable as possible.

Design of Save Vélo

Screenshot 2025-06-20 103708.png
Screenshot 2025-06-20 103648.png
WhatsApp Image 2025-06-07 at 18.30.44 (2).jpeg
WhatsApp Image 2025-06-07 at 18.30.44 (1).jpeg
WhatsApp Image 2025-06-07 at 18.30.44.jpeg
WhatsApp Image 2025-06-07 at 18.30.59.jpeg
WhatsApp Image 2025-06-07 at 18.30.55.jpeg
WhatsApp Image 2025-06-07 at 18.30.46 (1).jpeg

Attached are the laser cut files for both enclosures.

To complete the laser cutting, you will need two 3mm MDF sheets. These files include all the parts needed to assemble both boxes.

I have also included photos of the making process to help illustrate the steps and provide a better understanding of how everything was built.

Additional materials and tools you will need:

  1. Wood glue
  2. Drill
  3. Saw
  4. 4 wing nuts
  5. 4 bolts
  6. Hammer
  7. Hot glue gun
  8. File
  9. Sandpaper


First, assemble the enclosure using wood glue.

Once the glue has dried and the box is sturdy, you can drill all the necessary holes. This includes holes for the electronic components, the lock mechanism, and the mounting points for the bike lock.

After all holes are drilled, you can begin attaching the components inside using a hot glue gun or other suitable methods.


For the servo motor, I designed and 3D printed a custom hook. However, you can also use any other hook-shaped object as long as it can hold the rope securely and allow the rope to pass through.

You can find the 3D print file for this hook included with the other project files.

Get the Github Repository

WhatsApp Image 2025-06-18 at 21.01.59.jpeg
WhatsApp Image 2025-06-20 at 10.52.06.jpeg

You can see the two finished enclosure boxes here.

If you want to build this project yourself, you can find the code on my GitHub here.


Thanks for reading about my project. I hope you have as much fun building it as I did!