
Control a Servo motor from Miles Away! Heltec WiFi LoRa 32 V3 Arduino Tutorial (TX)
In this guide, we’re taking the exact sketches from our Heltec ESP32 LoRa V3 servo project and walking through how they work—no extra code added. You’ll learn how the transmitter reads a rotary encoder, secures and sends that angle over LoRa, and how the receiver decrypts it and drives a micro-servo. All part and code links are below, and if you order through our affiliate links it helps us keep making these tutorials.
1. Transmitter (TX) hardware & setup
On the TX side you need:
Heltec WiFi LoRa 32 V3 board (in Meshnology N33 case, powered by 3000 mAh pack)
Rotary encoder wired to GPIO 6 (CLK), GPIO 5 (DT), GPIO 4 (SW)
OLED display on I²C (SDA= 4, SCL= 15)
The sketch begins by including and initializing everything exactly as in Heltec_ESP32_LoRa_V3_Sevo_TX_AiRotaryEncoder.ino
:
cppCopyEdit#include "AiEsp32RotaryEncoder.h"
#include "HT_SSD1306Wire.h"
#include "LoRaWan_APP.h"
#include "mbedtls/aes.h"
// …
static SSD1306Wire display(0x3c, 500000, SDA_OLED, SCL_OLED, GEOMETRY, RST_OLED);
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(
PIN_A, PIN_B, SW_PIN, ROTARY_ENCODER_VCC_PIN, false, true, true);
const int homePosition = 90;
const int MAX_ANGLE = 180;
int servoAngel = homePosition;
In setup()
, the code:
Powers on the display, sets font
Calls
rotaryEncoder.begin()
,rotaryEncoder.setup(readEncoderISR)
,rotaryEncoder.setBoundaries(0, MAX_ANGLE, true)
androtaryEncoder.setAcceleration(20)
Resets encoder to
homePosition
Initializes LoRa via
Mcu.begin(HELTEC_BOARD, SLOW_CLK_TPYE)
and sets upRadioEvents
, channel, and parameters exactly as in the provided sketch.
2. Sending the angle securely
Every loop cycle runs rotary_loop()
, which:
Reads the encoder in the ISR
When
servoAngel
changes, packages it into a 16-byte buffer, encrypts with AES-128 (encryptAES()
from the sketch), and callscppCopyEditRadio.Send(data, sizeof(data));
Sets
lora_idle = false
untilOnTxDone()
fires and resets it.
3. Receiver (RX) hardware & setup
On the RX side you need:
Heltec WiFi LoRa 32 V3 board (same case/battery)
Micro-servo (e.g. SG90) on GPIO 6 (or any tested PWM pin)
OLED display
The sketch in Heltec_ESP32_LoRa_V3_Sevo_RX.ino
starts with:
cppCopyEdit#include <ESP32Servo.h>
#include "HT_SSD1306Wire.h"
#include "LoRaWan_APP.h"
#include "mbedtls/aes.h"
// …
const int servoPin = 6;
const int SERVO_DUTY_MIN = 400; // us
const int SERVO_DUTY_MAX = 2400; // us
Servo myservo;
int servoAngel = homePosition;
In setup()
, it:
Powers on Vext for the display/LoRa module (
VextON()
)Calls
Radio.Init(&RadioEvents)
and configures RX with the same LoRa parametersAttaches the servo with
myservo.attach(servoPin, SERVO_DUTY_MIN, SERVO_DUTY_MAX)
and centers it athomePosition
.
4. Receiving, decrypting, and driving the servo
The core is the OnRxDone(uint8_t *payload, …)
callback:
cppCopyEditdecryptAES((uint8_t*)rxpacket, userKey);
if (isNumber(rxpacket)) {
servoAngel = atoi(rxpacket);
myservo.write(servoAngel);
delay(15);
}
Serial.println("Angle: " + String(servoAngel));
lora_idle = true;
It decrypts the 16-byte block, converts to an integer, and immediately updates the servo.
5. PWM pin support & servo tuning
We tested these ESP32 pins for PWM output and they all work for driving a micro-servo:
CopyEdit1, 2, 3, 4, 5, 6, 19, 35, 36, 38, 39, 40, 41, 42, 45, 47, 48
For a standard SG90, our code uses a pulse range of 400 µs (0°) to 2400 µs (180°), which gives a smooth, full sweep without jitter.
6. Wiring diagram
Below are placeholders where you can drop in your TX and RX schematics:


Code & Affiliate Links
All of the above sketches are available for download in the “Code & Resources” section below. If you’d like to build this yourself, please consider buying your Heltec LoRa32 V3 module, Meshnology N33 case, rotary encoder, and SG90 servo via our affiliate links. It costs you nothing extra and helps us keep making free tutorials like this!
Video Chapters for Reference
00:00 Introduction & Overview
00:05 Remote Control Concepts
00:19 LoRa Communication Basics
00:23 Hardware Preview
00:28 Case & Battery Showcase
01:03 Module Features
01:42 Specs & Connectivity
02:54 Powering the Servo
03:05 Wiring & Pinout
09:35 Antenna Placement
11:04 Case Assembly
29:26 Uploading Sketches
35:09 Range Test 1.2 km
36:38 Range Test 1.4 km
38:41 Performance Recap
43:04 Conclusion & Support
Comments will be displayed here.