In this article, we will configure a parking sensor using LoRa (long range) devices. LoRa is a wireless communication technique derived from Chirp Spread Spectrum (CSS) technology.
For this project, the Arduino Nano is connected to an ultrasonic sensor, detecting parking occupancy based on distance measurements. When a vehicle enters or leaves a parking space, the ultrasonic sensor signals the Arduino, which integrates with a LoRa E5 Mini Board as a communication gateway.
When there is a change in parking status, the Arduino is programmed to send data to the LoRa E5. Of course, this information is transmitted wirelessly to the designated gateway via LoRa technology. LoRa's long-range and low-power capabilities make it ideal for monitoring multiple parking spaces. The system provides real-time parking occupancy data, beneficial for smart parking solutions in urban areas and commercial establishments.
The following provides a hardware configuration guide and programming details, highlighting the advantages of LoRa – including its efficient coverage and longer battery life. By leveraging LoRa technology, this smart parking solution contributes to better traffic management and user experience, making it suitable for integration into smart city initiatives.
Abstract
1. How to Upload UART to Lora E5 Mini Board Firmware
2. Firmware for Arduino Nano
3. Circuit diagram and connections
4. Adding a device to ChirpStack
5. LoRa data decoding
6. Program or algorithm flow and explanation
Requirements
1. Make sure LoRa is already installed
2. The STM32Cube programmer must be installed on your PC
3. Seed Studio LoRa E5 Mini Card
4. Original ST-Link V2 Programmer
5. ArduinoNano
6. Ultrasonic Sensor (HC-SR04)
Uploading code to LoRa
This tutorial provides the LoRa E5 Mini Board firmware code to facilitate data transmission to the gateway. When LoRa receives data through universal asynchronous receiver-transmitter (UART) communication, it immediately sends all received information to a specific gateway.
The code is available in two formats: as a project file and as a precompiled hex file. The hexadecimal file can be loaded directly onto the Lora Mini Board, simplifying the process.
To upload the code, users can choose the precompiled hex file or compile the project file using STM32cube IDE.
Here, we will directly upload the provided hex file to the LoRa E5 Mini Board, simplifying the configuration process. This code allows developers to establish seamless communication between LoRa and the gateway, enabling efficient data transfer and IoT applications.
This tutorial is available for both beginners and experienced developers, making it a valuable resource for LoRa-based projects.
1. Locating a genuine ST-Link V2 is necessary for proper updating of the LoRa code, as clone variants of ST-Link are often not compatible. This means that it is essential to recognize the original ST-Link. A reliable method of identification involves examining the hardware components.
After thorough analysis, a genuine ST-Link V2 has an STM chip, indicating authenticity. Clones are typically imported from China and have a slightly different appearance.
This project requires a smooth “flashing process”, which occurs reliably with a genuine ST-Link with STM chip (see image below). Knowing the difference will ensure compatibility and proper programming.
2. Connect five wires – 3V3, SWDIO, SWCLK, RST and GND – to the LoRa E5 Mini Board as shown below.
3. Open the STM32CUBE Programmer and click the “Connect” button.
4. Select the Hex file by clicking the open file tab.
5. Click the “Download” button to upload the code.
6. When a pop-up appears informing you that the file download is complete, everything is fine.
Uploading code to Arduino Nano
1. Open the Arduino Nano code “Parking Detection” in Arduino IDE.
3. Select “Board” and “Port” from the Arduino drop-down menu to upload the code.
4. Load the code into Arduino.
Circuit Diagram
Adding a device to the gateway
1. Add a device profile if you don't already have one. If you do this, there is no need to add a new profile. The same profile can be used for multiple nodes.
2. If you don't already have a profile, open ChirpStack and go to “Device Profiles”.
3. Click “Add Device Profile”.
4. Fill in the general data as shown in the image below and click “Send”.
5. Turn OTAA off because the device will work in ABP mode. Fill in all the data rate details and frequency of the RX3.
6. Activate Class C mode as shown below and click “Submit”.
7. Add the “Application” which contains all the devices for it.
8. Click “Add application”.
9. Fill in the registration details as indicated below.
11. Then click on the “Add Device” button. This must be done every time a new device is added.
12. Fill in the data as shown in the image below. You will notice that there is no EUI device. We will learn how to find it in the next step.
How to find the keys and EUI
1. To find the keys, open the serial port where the Arduino Nano is connected and press the “Reset” button.
LoRa data decoding
Open the LoRa app, which was recently added. Click on the “Events” tab to see the data.
When the parking lot is empty
When the sensor distance is more than 10 cm, it sends the “Empty” message on the LoRa gateway.
Data is represented in a hexadecimal value. You can go to any hex to text conversion website and paste this data.
When the distance is less than 10 cm, it sends the “Empty” message on the LoRa gateway.
The data is again represented in a hexadecimal value. You can go to any hex to text conversion website and paste this data.
Algorithm
Code Explanation
ArduinoNano
1. In this section of code, the ultrasonic sensor emits a sound wave by setting the Trig pin to a high state. The sensor then receives the echo of this sound wave through the echo pin. By measuring the time needed to receive the echo, the code calculates the distance between the sensor and the object that reflects the sound wave.
2. This part of the code detects the condition of the parking area and sends it to the LoRa device.
LoRa E5 Mini Card
1. Open the lora_app.c file, which contains all the code.
2. The CMD_GetChar function reads the characters available on the UART and when it receives '\n' it calls the CMD_process which is sent to LoRa.
3. This function transfers the received characters to the application data buffer. It will not store the '\n' or '\r'. Then it sends it to the LoRa gateway.
Multinode communication
After successfully integrating a parking sensor with LoRa, the same configuration and circuit can be easily replicated to another node. Each node is uniquely identified using the STM32 device ID, ensuring it acts as a different device with its own ID and keys.
This unique identification allows the new node to operate independently and communicate with the gateway as a separate device.
By using the STM32 device ID, developers can avoid conflicts and ensure smooth communication between multiple nodes and the gateway. Each node's unique ID allows for precise tracking and monitoring of individual parking spaces or other applications.
The scalability of this method makes it ideal for configuring multiple nodes in different IoT projects. Whether for smart parking, environmental sensing or asset tracking, you can easily add new nodes to the network, making the entire system work together and collect more data.