Search Code

Remote Door Alert System from 13 mile 21 km Away With LoRa – Off the Grid! (Heltec WiFi LoRa 32 V3)

This lesson is part of: Introduction to WiFi LoRa

Remote Door Alert System from 13 mile 21 km Away With LoRa – Off the Grid! (Heltec WiFi LoRa 32 V3)

Imagine being able to monitor the front door of a remote cabin, the gate to a farm, or the entrance to a storage unit from over 13 miles (21 km) away—without a Wi-Fi connection, a cellular SIM card, or any monthly fees. This isn't a futuristic concept; it's a practical reality using LoRa (Long Range) technology. In this project, we'll build a long-range door monitoring system using the Heltec Wi-Fi LoRa 32 V3 module, neatly packaged in a Meshnology N32 case with a 3000 mAh battery for long-lasting, off-grid performance.

This project uses a Hall effect sensor to detect whether a door is open or closed and transmits that status over the LoRa band. It's a perfect solution for cabins, barns, storage units, or any location where you need reliable remote monitoring without relying on existing infrastructure. You can even add a buzzer or relay to the receiver to create a local alarm system.

Here are some practical ways you can use this project:

  • Monitor a remote greenhouse door to ensure it's closed for temperature control.
  • Check if a barn or stable door has been left open after you've left the property.
  • Create a long-range security alarm for a shed or workshop.
  • Get notified when a mailbox or gate is opened.
  • Monitor access to a fenced-off area or construction site.

This guide is the fourth in a series on the Wi-Fi LoRa 32 V3. Previous videos covered sending temperature data, reading up to 150V DC, and controlling a relay remotely—all over LoRa. This project builds on those concepts to create a complete, practical monitoring system.

Hardware Required

To build this project, you will need the following components:

  • 2x Heltec Wi-Fi LoRa 32 V3 modules
  • 2x Meshnology N32 cases (or similar enclosures)
  • 2x 3000 mAh 3.7V LiPo batteries
  • 1x Hall Effect sensor module (with digital output)
  • 1x Small magnet (for the door)
  • 1x Buzzer (5V works with 3.3V) or a 5V relay module
  • 1x 2N2222 NPN transistor (for buzzer circuit)
  • 1x 1kΩ resistor
  • Connecting wires and a soldering iron

The Meshnology N32 case is a great option for this build. It's designed to house the Heltec module and a 3000 mAh battery, providing a clean, professional finish. You can also use a simple breadboard or a custom 3D-printed enclosure to get started.

Wiring Guide

There are two main circuits to build: the transmitter and the receiver. The transmitter is connected to the Hall Effect sensor, while the receiver can be connected to a buzzer or relay module for alarms.

Transmitter Wiring:

This setup is very straightforward. The Hall Effect sensor has four pins: VCC, GND, DO (Digital Out), and AO (Analog Out). For this project, we only need the digital output.

  • VCC on the sensor connects to the 3.3V pin on the Heltec board.
  • GND on the sensor connects to a GND pin on the Heltec board.
  • DO on the sensor connects to GPIO 4 on the Heltec board.
  • The AO pin is left unconnected.

Receiver Wiring (Buzzer):

To drive a buzzer, a transistor is used as a switch because the buzzer can draw more current than the microcontroller's GPIO pin can safely supply. The circuit is simple:

  • The positive lead of the buzzer connects to the 3.3V pin.
  • The negative lead of the buzzer connects to the collector of the 2N2222 transistor.
  • The emitter of the transistor connects to GND.
  • The base of the transistor connects to GPIO 4 on the receiver's Heltec board through a 1kΩ resistor.

Receiver Wiring (Relay):

If you want to control a load like a light or a siren, you can use a relay module. The wiring is even simpler:

  • VCC on the relay module connects to the 3.3V pin (or 5V if using a boost converter).
  • GND on the relay module connects to GND.
  • IN on the relay module connects to GPIO 4 on the Heltec board.

You can then connect your AC or DC load to the relay's output terminals. The relay acts as an electromagnetic switch, closing the circuit when the door is opened.

For the buzzer circuit, the 2N2222 transistor is used to amplify the current from the GPIO pin. A 1kΩ resistor is placed between the GPIO pin and the base to limit the current into the transistor. The buzzer is connected between 3.3V and the collector, so when the transistor is turned on, it completes the circuit and the buzzer sounds.

Setting Up the Software

Before you can upload the code, you need to install the necessary software and libraries in your Arduino IDE. First, ensure you have the Arduino IDE installed. Then, follow these steps:

  1. Install ESP32 Board Support: Open the Boards Manager (Tools > Board > Boards Manager), search for "ESP32", and install the package by Espressif Systems.
  2. Add Heltec Board URL: Go to File > Preferences, and in the "Additional Boards Manager URLs" field, paste the JSON URL https://resource.heltec.cn/download/package_heltec_esp32_index.json for the Heltec ESP32 boards. You can find this link on the Heltec documentation page. Then, go back to Boards Manager, search for "Heltec ESP32", and install it.
  3. Install Libraries: Go to Tools > Manage Libraries and install the following:
    • Heltec ESP32 Dev Boards by Heltec Automation
    • Adafruit GFX Library by Adafruit (install all dependencies when prompted)
    • Robojax Heltec LoRa 32 library (download the .zip file from the link in the video description and install it via Sketch > Include Library > Add .ZIP Library).

After installing the libraries, you can select the correct board by going to Tools > Board > Heltec ESP32 Arduino > Heltec Wi-Fi LoRa 32(V3). Make sure the correct port is selected.

Code Explanation

This project uses two separate code files: one for the transmitter and one for the receiver. Both are included in the Robojax Heltec LoRa 32 library under the examples menu. The code is largely pre-written; you only need to adjust a few key variables at the top of each file to configure your network.

Transmitter Code (Door Alarm TX):

Open the transmitter code from File > Examples > Robojax Heltec LoRa 32 > Door Alarm TX. The key settings you need to modify are:

  • Door Sensor Pin: This is the GPIO pin connected to the Hall Effect sensor's digital output. The default is pin 4, but you can change it if you've wired it differently.
  • Text Strings: You can change the text that is displayed and transmitted, such as "Door is OPEN" and "Door is CLOSED". Keep the double quotes as they are strings.
  • Secure Key: This is a secret string that must match between the transmitter and receiver. It prevents other LoRa devices from triggering your alarm. Change this to a unique value.
  • Frequency: This must be set to the correct frequency for your region (e.g., 915 MHz for the US, 868 MHz for Europe). It must match the receiver's frequency.
  • TX Power: This sets the transmission power in dBm. You can set it from 2 to 20. For a short-range test, a low value like 2 is fine. For the long-range 13-mile test, it was set to 20. Higher power will drain the battery faster.

Receiver Code (Door Alarm RX):

Open the receiver code from File > Examples > Robojax Heltec LoRa 32 > Door Alarm RX. The key settings are:

  • Relay Pin: The GPIO pin connected to the relay or buzzer control circuit. The default is pin 4.
  • Alarm Duration: This variable sets how long the relay or buzzer stays active after a "Door Open" signal is received. The default is 1000 milliseconds (1 second). You can increase this to 10,000 or 20,000 ms if you want the alarm to sound longer.
  • Secure Key: This must be identical to the key you set in the transmitter code.
  • Frequency: This must match the transmitter's frequency for your region.

Once you have configured these settings, you can upload the code to each respective board.

Live Project and Demonstration

In the video, the project is demonstrated both on a workbench and in a real-world scenario. In the lab, the transmitter is connected to a Hall Effect sensor, and a magnet is used to simulate the door opening and closing. When the magnet is close to the sensor, the system shows "CLOSED," and when it's removed, it shows "OPEN." This status is transmitted to the receiver, which activates a buzzer or relay.

The real-world test involved mounting the Hall Effect sensor and magnet on a door. When the door was opened, the receiver immediately displayed "OPEN" and triggered the alarm. Closing the door sent the "CLOSED" signal and turned the alarm off.

To prove the long-range capabilities, the transmitter was placed on a tripod by a lake with a clear line of sight. The receiver was then driven to a location over 13 miles (21 km) away. At this distance, the receiver was still able to pick up the signal and display the transmitted data, demonstrating the power and reliability of LoRa for off-grid communication.

For a range test, you can set the TX power to 20 dBm. However, for everyday use in a lab or short distances, setting it to 2 dBm will save battery life. With a 3000 mAh battery, the transmitter can last for several days, depending on the transmission power and frequency of updates.

Chapters

  • [00:00] Introduction to the Remote Door Alert System
  • [01:04] Overview of the LoRa Project Series
  • [02:01] Components and Hardware Overview
  • [05:42] Meshnology N32 Case and Battery Options
  • [07:20] Assembling the Meshnology N32 Case
  • [11:41] Testing the Connectors and Battery Safety
  • [12:22] Wiring the Hall Effect Sensor and Relay
  • [13:51] Wiring the Buzzer with a Transistor
  • [17:48] Final Assembly and Sensor Adjustment
  • [23:20] Installing Software and Libraries
  • [27:42] Configuring and Uploading the Transmitter Code
  • [30:22] Configuring and Uploading the Receiver Code
  • [31:56] Lab Demonstration of the Door Alarm System
  • [33:03] Testing on an Actual Door
  • [34:08] 13-Mile Range Test and Conclusion
No code attached.

Files📁

Arduino Libraries (zip)

Other files