Introduction: Build a Real-Time, Long-Range Relay Controller With LoRaWAN
I always wanted a way to remotely control lights or motors from miles away without using Wi-Fi or cellular. So, I built this responsive relay controller using LoRaWAN, a long-range radio network. Unlike my battery-saving sensors that only check for commands occasionally, this device is always listening. When I send a command from my phone or computer, it activates the relay in under a second. In this guide, I'll show you how I built it.
For a complete visual walkthrough, from the wiring to seeing the instant response in action, be sure to watch my full video tutorial on YouTube.
Supplies
To build this project, you only need a few key parts. The brain of the operation is a Heltec LoRa 32 board, which combines an ESP32 microcontroller and a LoRa radio in one unit. You'll also need a two-channel 5V relay module to act as the switch, and a few jumper wires to connect everything.
Having the right parts makes the build process smooth. I've put links for the Heltec LoRa 32 board and the relay module I used down below. These are affiliate links and by using these links, you support my channel at no extra cost to you.
Step 1: Connect the Wires
The hardware setup is very simple and only requires four wires. First, I power the relay module by connecting the 5V pin from my Heltec board to the relay's VCC pin. Then, I connect a GND (ground) pin from the Heltec board to the GND pin on the relay module. This provides power.
To control the relays, I use two of the Heltec board's digital pins. I connect pin 47 to the input for relay channel one, and pin 48 to the input for relay channel two. That's the entire physical setup. For a clear, close-up look at these connections, check the video where I show the wiring in detail.
Step 2: Upload the Arduino Code
Now, it's time to teach the device how to listen. I use the Arduino IDE for this. My code is a modified version of an example provided by Heltec. The most important part is setting the device to Class C mode, which tells it to stay awake and listen constantly for commands.
The code works by waiting for a two-part command from the LoRaWAN network. The first number is the action, like "turn on," and the second number is the relay, like "number one." So, the command "01 01" turns on the first relay. I've included a special command, "03 03," that turns both relays off at once.
You can get the full code here.
Step 3: Register on the Things Network and Test
For the device to receive commands, it needs to be registered on a LoRaWAN network. I use The Things Network (TTN). In the video, I show you exactly how to register your device on TTN and input your unique device keys into the code. This is a crucial step to get right.
Once it's connected, the real magic happens. I go to the TTN console on my computer, type a command like "0101" into the messaging section, and hit send.
You can see in my video how the first relay clicks on almost instantly. I then demonstrate turning on the second relay and using the command to turn both off, all in real-time.
Step 4: Understanding How LoRaWAN Classes Work
You might wonder why this device responds so much faster than a weather sensor. It all comes down to LoRaWAN device classes. A Class A device, like a sensor, is asleep most of the time and only briefly listens after it sends data. This is great for batteries but slow for commands.
My relay controller uses Class C, which means it's always listening. This is why it reacts immediately, but it also uses much more power.
There's also a Class B, which is a middle ground, waking up periodically for commands.
Step 5: Your Turn to Build!
I hope this guide inspires you to create your own long-range remote control projects. You can use this to control garden lights, garage doors, or irrigation pumps from kilometers away. The possibilities are endless.
If you found this guide helpful, please watch the full build video on my YouTube channel. It really helps bring these steps to life.
Thanks for following along, and I can't wait to see what you build





