
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


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
[00:00] Project Introduction and Range Demonstration
[00:08] Use Cases: Fan, Heater, Gate, Light
[00:20] Hardware Used
[00:40] Wiring Overview
[01:00] Installing Robojax Library
[01:20] TX Code (Simple Version)
[01:40] TX Code (Toggle Version)
[02:00] RX Code Explanation
[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!
Related Tutorials in This Series:
WiFi LoRa 32 Tutorials
Related Links
- Purchase a WiFi LoRa 32 from Amazon USA
- Purchase a WiFi LoRa 32 shell from Amazon USA
- Purchase a WiFi LoRa 32 from Amazon Canada
- Purchase a WiFi LoRa 32 from Amazon Europe
- Purchase Wi-Fi LoRa 32 from Meshnology
- Purchase WiFi LoRa 32 V3 with N32 Case and 3000mA Battery
- AO7801 Dual P-Channel Enhancement Mode Field Effect Transistor Datasheet This is the datasheet for AO7801 Dual P-Channel Enhancement Mode Field Effect Transistor
Downloads
- Download
-
Robojax Heltec LoRa 32 V3 Library 1.0 - 2025-05-20 0.09 MB This is library for Heltec WiFi LoRa 32 V3. It contains the example codes for projects. Please watch video for instructions on how to install it.Download
Comments will be displayed here.