As third year students at Unilasalle Amiens Engineering School, we had to realize an IOT (Internet Of Things) project. This project's main goal was to use LoRa technology and have a useful project to present.
Have you ever wondered how people could access private locations with such disconcerting ease ? In most cases, it's either because someone lend these people a badge to access the building, or because the badge in question has been stoled. Our solution to this recurrent problem is to set up a double authentification access to your sensitive areas, or even your working places.
Secu² is a lock requiring a two-factor authentification to be opened, first of all, you'll have to scan your RFID badge, then if you're allowed to access the local, you'll receive a code on your nomative dashboard on our website. The code will be asked; if it's the correct one, you'll have the complete access to the area.
We'll see firstly the physical assembly of the project, then the software and the codes, and we'll finished with the possible upgrades and the encountered problems and a conclusion.
Physical assemblyThe first step of the physical assembly was to set up the Arduino MKR 1310 with the RFID reader, the Lock, the Keypad and the alimentation.
Above, the first wiring of the system which permitted us to test our project's basics. This first model can scan an RFID badge, it allows us to use the Keypad and it can supply voltage to our Lock. It helped us check that the main components were working properly together. At this stage, we could already simulate the full process: badge scanning, code entry, and lock activation. It was also useful to detect early problems with wiring or power management.
Then, to have a good looking project, we wanted to put it inside a box to make it more compact and presentable. We originally planned to 3D print a custom case, and we even designed it on Tinkercad. Unfortunately, due to a lack of time, we couldn’t print it before the deadline. So instead, we used a cardboard box to hold all the components and keep the system stable for the demonstration. Even if it’s not perfect, it gave a cleaner look to the final setup.
Software and codeIt's a must for our project to use different coding languages, we'll see here the different coding parts of the Lock.
All the programs presented here will be attached below if you want to access or to run them.
Arduino
The Arduino code manages the entire logic of the system. It starts by initializing the RFID reader (RC522), the Keypad, the LoRa modem (MKR WAN 1310), and the lock relay. Once the setup is complete, the system waits for a badge to be scanned. When a badge is detected, its unique ID is formatted as a string and sent via LoRa to the TTN (The Things Network) server. After sending the badge ID, the Arduino waits for a downlink response that should contain the correct PIN code for that badge.
Once the code is received, the system enters a loop where the user has to enter the code using the keypad. The '#' key is used to confirm the input, and the '*' key resets the entered code. If the code is correct, the lock (connected to a relay) opens for a few seconds, then closes again. If the code is wrong, the system denies access and waits for a new attempt. All actions and debug messages are printed on the Serial Monitor, which helps for testing and troubleshooting.
Python/HTML
The Python code is the core of the Flask server that manages the web application logic and communication with The Things Network (TTN). It starts with the necessary imports, including Flash, SQLite, Requests and "paho.mqtt.client" for MQTT, as well as modules for security and multithreading. After initializing the Flask app, it sets up TTN access using an API key and MQTT credentials.
A function send_dowlink() is defined to send a code to the remote device (Arduino) via a TTN downlink message encoded in base64. Another function handles the connection to the SQLite database (badges.db). Then, an MQTT callback on_message() processes incoming MQTT messages: when a badge is scanned, its ID is decoded and checked in the database. If the badge has access rights, a random PIN code is generated, stored, and sent back as a downlink. If not authorized, the timestamp is updated without sending a code.
The script also includes routes for user authentication (login, signup), session management, and pages for admin and user dashboards, with role-based access control. A background thread continuously cleans expired codes from the database, and another thread listens to MQTT messages indefinitely. Overall, this code integrates secure user management, badge validation, and real-time communication with the hardware through TTN.
The HTML page is the dashboard for the user. It shows the user’s name and information about their badge. The badge details include the name, badge ID, rights, code, and the time of the last update. These details come from the server and are inserted using Flask template tags like {{badge['nom']}}.
The page has basic styles to make it easy to read. Also, there is a small script that reloads the page every 10 seconds to update the information automatically. This way, the user always sees the latest badge data in a clear and simple way.
SQL
The Python code uses SQLite to manage the database for users and badges. For example, it uses a SELECT query to check if a user exists during login by searching for a user with the given username. If the user is found, the password is then verified. Another example is the UPDATE query, which updates the badge code and timestamp when a new code is generated. This query modifies the code and timestamp fields for a specific badge ID. These SQL commands allow the program to securely retrieve and update data needed to control access and manage badges efficiently.
Possible upgradesThe first possible upgrade would be to add an LCD display to our system, its objective would be to display what the user is typing on the Keypad and in addition, it could tell if the given code either is right or false.
Another possible upgrade is to set up a PostgreSQL database to replace the existing local SQLite database (donner les avantages)
In addition, to have a domain name to access the web page from a phone would be way more comfortable for the user.
To go further, we could develop a mobile app, that would be to most effective and comfortable method for the user, no need to access any website, everything could be on his phone.
Encountered problemsWe encountered a few problems during the realization of our project, we will present them here.
We wanted to 3D print the box that contains the project, we realized the 3D model on Tinkercad (it's attached below). But we ran out of time at the end of the project and that's why we used a cardboard box to present the project.
Finally we had a major problem, every time we typed a code, the lock would unlock and then the RFID reader would shut down, so we had to unplug the arduino board and plug it back in, or even upload the code again. There is a good chance that this comes from insufficient resistance in my opinion.
ConclusionTo conclude, this project asked us many skills from different areas, we had to use LoRa technologies, espacially LoRawan with the TTN Console. In addition, we had to reinforce our development skills, mainly Python Flask and Arduino. And then, it was a must to consolidate our electronic skills for the physical functioning of our project
Finally, this project permitted us to apply our knowledge on a concrete case, and to work as a team on a complete system mixing electronics, coding and network. It helped us understand better how an IOT project works from A to Z, and made us improve in many different areas.
Even if we had some difficulties, especially with the power supply and the 3D case, we managed to build a working prototype that proves our idea works. This experience was really instructive and gave us more confidence for future engineering projects.











_t9PF3orMPd.png?auto=compress%2Cformat&w=40&h=40&fit=fillmax&bg=fff&dpr=2)








Comments