Turn On a Device from 13 mile 21km Away – The Ultimate Off-Grid LoRa Project with WiFi LoRa 32!

Video thumbnail for Heltec WiFi LoRa 32 V3 - Controlling Relay over LoRa from 21km or 13 m

Turn On a Device from 13 mile 21km Away – The Ultimate Off-Grid LoRa Project with WiFi LoRa 32!

Imagine being able to switch a fan, heater, door lock, or remote system from up to 21 kilometers (13 miles) away—completely off-grid, without Wi-Fi, and without a SIM card. In this tutorial, you’ll learn how to build a secure long-range wireless relay controller using Heltec WiFi LoRa 32 V3 modules and the Robojax_HeltecLoRa32 library. This project enables encrypted LoRa communication to safely trigger relays over great distances.

Project Overview

This system consists of two LoRa32 boards:

  • Transmitter (TX): A push button triggers an encrypted command ("ON" or "OFF") over LoRa.

  • Receiver (RX): Listens for and decrypts the command, then controls a relay module connected to GPIO4 accordingly.

You have two transmitter code versions:

  • Simple: Sends ON when the button is held down, OFF when released.

  • Toggle: Alternates the state with each press.


Required Library

You must install the Robojax_HeltecLoRa32 library. Download it from the link below this article.

Install this ZIP library via Arduino IDE before uploading any code.

Wiring Instructions

Transmitter Wiring:

  • User button connected to GPIO0

  • Optional: OLED display uses default pins (SCL/SDA)

Receiver Wiring:

  • Relay (or buzzer) control pin connected to GPIO4

  • 5V Relay module powered via board's 5V and GND

Control a load using LoRa
Wiring diagram showing LoRa32 receiver with relay and load.


Helte_Wifi_LoRA_ buzzer
Wiring diagram showing LoRa32 buzzer.


Secure TX Code Explanation

In both TX sketches, encryption is enabled using the setSecurityKey() method from the Robojax library. For example:

const char *userKey = "hyhT676#h~_876s";
robojaxDevice.setSecurityKey(userKey);

In Relay_Secure_TX_Simple.ino, a HIGH signal on GPIO0 sends "ON", while a LOW sends "OFF":

if(digitalRead(0) == HIGH){
  robojaxDevice.sendSecureMessage("ON");
} else {
  robojaxDevice.sendSecureMessage("OFF");
}

In Relay_Secure_TX_Toggle.ino, each button press toggles between ON and OFF:

if(buttonPressed){
  status = !status;
  String message = status ? "ON" : "OFF";
  robojaxDevice.sendSecureMessage(message);
}

Secure RX Code Explanation

The receiver sketch uses the same encryption key and listens for secure messages:

robojaxDevice.setSecurityKey("hyhT676#h~_876s");
String message = robojaxDevice.receiveSecureMessage();

Then controls GPIO4 accordingly:

if(message == "ON"){
  digitalWrite(RELAY_CONTROL_PIN, HIGH);
} else if(message == "OFF"){
  digitalWrite(RELAY_CONTROL_PIN, LOW);
}

The OLED display shows the received state and "RX" label.

📚 Chapter Index

  1. [00:00] Project Introduction and Range Demonstration

  2. [00:08] Use Cases: Fan, Heater, Gate, Light

  3. [00:20] Hardware Used

  4. [00:40] Wiring Overview

  5. [01:00] Installing Robojax Library

  6. [01:20] TX Code (Simple Version)

  7. [01:40] TX Code (Toggle Version)

  8. [02:00] RX Code Explanation

  9. [02:20] Live Demonstration

This tutorial provides a robust and secure way to wirelessly control devices over long distances. All code and the required library are available below this article. Watch the full video to follow along!

Downloads

Comments will be displayed here.