આ ટ્યુટોરિયલ આનો ભાગ છે: WiFi LoRa 32 ટ્યુટોરિયલ્સ
Heltec WiFi LoRa 32 સંબંધિત તમામ વિડિઓઝ આ જૂથનો ઉપયોગ કરીને સંબંધિત છે. અન્ય વિડિઓઝની લિંક્સ આ લેખની નીચે છે.
દૂરથી સર્વો મોટરને નિયંત્રિત કરો! Heltec WiFi LoRa 32 V3 Arduino ટ્યુટોરિયલ (TX)
આ માર્ગદર્શિકામાં, અમે અમારા Heltec ESP32 LoRa V3 સર્વો પ્રોજેક્ટમાંથી ચોક્કસ સ્કેચ લઈ રહ્યા છીએ અને તે કેવી રીતે કાર્ય કરે છે તે સમજાવી રહ્યા છીએ—કોઈ વધારાનો કોડ ઉમેર્યા વિના. તમે શીખી શકશો કે ટ્રાન્સમીટર રોટરી એન્કોડર કેવી રીતે વાંચે છે, તે કોણને LoRa પર સુરક્ષિત કરીને મોકલે છે, અને રીસીવર તેને કેવી રીતે ડિક્રિપ્ટ કરીને માઇક્રો-સર્વો ચલાવે છે. બધી ભાગ અને કોડ લિંક્સ નીચે છે, અને જો તમે અમારી એફિલિએટ લિંક્સ દ્વારા ઓર્ડર કરો છો, તો તે અમને આ ટ્યુટોરિયલ્સ બનાવતા રહેવામાં મદદ કરે છે.
Heltec ESP32 બોર્ડ્સ ઇન્સ્ટોલ કરવું
વિડિયોમાં બતાવ્યા પ્રમાણે આ પાથ તમારા Arduino IDE ની પ્રેફરન્સમાં ઉમેરો:https://resource.heltec.cn/download/package_heltec_esp32_index.json
1. ટ્રાન્સમીટર (TX) હાર્ડવેર અને સેટઅપ
TX બાજુએ તમને જોઈએ:
-
Heltec WiFi LoRa 32 V3 બોર્ડ (Meshnology N33 કેસમાં, 3000 mAh પેક દ્વારા પાવર્ડ)
-
રોટરી એન્કોડર GPIO 6 (CLK), GPIO 5 (DT), GPIO 4 (SW) સાથે વાયર્ડ
-
OLED ડિસ્પ્લે I²C પર (SDA= 4, SCL= 15)
સ્કેચ બરાબર 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;
setup() માં, કોડ:
-
ડિસ્પ્લે ચાલુ કરે છે, ફોન્ટ સેટ કરે છે
-
rotaryEncoder.begin(),rotaryEncoder.setup(readEncoderISR),rotaryEncoder.setBoundaries(0, MAX_ANGLE, true)અનેrotaryEncoder.setAcceleration(20)કૉલ કરે છે -
એન્કોડરને
homePositionપર રીસેટ કરે છે -
Mcu.begin(HELTEC_BOARD, SLOW_CLK_TPYE)દ્વારા LoRa ઇનિશિયલાઇઝ કરે છે અનેRadioEvents, ચેનલ અને પેરામીટર્સ બરાબર આપેલ સ્કેચમાં જેમ છે તેમ સેટ કરે છે.
2. કોણ સુરક્ષિત રીતે મોકલવું
દરેક લૂપ સાયકલ rotary_loop() ચલાવે છે, જે:
-
ISR માં એન્કોડર વાંચે છે
-
જ્યારે
servoAngelબદલાય છે, ત્યારે તેને 16-બાઇટ બફરમાં પેકેજ કરે છે, AES-128 (encryptAES()સ્કેચમાંથી) સાથે એન્ક્રિપ્ટ કરે છે, અને કૉલ કરે છેcppCopyEditRadio.Send(data, sizeof(data)); -
OnTxDone()ફાયર ન થાય અને તેને રીસેટ ન કરે ત્યાં સુધીlora_idle = falseસેટ કરે છે.
3. રીસીવર (RX) હાર્ડવેર અને સેટઅપ
RX બાજુએ તમને જોઈએ:
-
Heltec WiFi LoRa 32 V3 બોર્ડ (સમાન કેસ/બેટરી)
-
માઇક્રો-સર્વો (દા.ત. SG90) GPIO 6 પર (અથવા કોઈપણ પરીક્ષણ કરેલ PWM પિન)
-
OLED ડિસ્પ્લે
Heltec_ESP32_LoRa_V3_Sevo_RX.ino માં સ્કેચ આનાથી શરૂ થાય છે:
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;
setup() માં, તે:
-
ડિસ્પ્લે/LoRa મોડ્યુલ માટે Vext ચાલુ કરે છે (
VextON()) -
Radio.Init(&RadioEvents)કૉલ કરે છે અને સમાન LoRa પેરામીટર્સ સાથે RX ગોઠવે છે -
myservo.attach(servoPin, SERVO_DUTY_MIN, SERVO_DUTY_MAX)સાથે સર્વો જોડે છે અને તેનેhomePositionપર કેન્દ્રિત કરે છે.
4. પ્રાપ્ત કરવું, ડિક્રિપ્ટ કરવું અને સર્વો ચલાવવું
મુખ્ય ભાગ OnRxDone(uint8_t *payload, …) કૉલબેક છે:
cppCopyEditdecryptAES((uint8_t*)rxpacket, userKey);
if (isNumber(rxpacket)) {
servoAngel = atoi(rxpacket);
myservo.write(servoAngel);
delay(15);
}
Serial.println("Angle: " + String(servoAngel));
lora_idle = true;
તે 16-બાઇટ બ્લોકને ડિક્રિપ્ટ કરે છે, પૂર્ણાંકમાં રૂપાંતરિત કરે છે, અને તરત જ સર્વો અપડેટ કરે છે.
5. PWM પિન સપોર્ટ અને સર્વો ટ્યુનિંગ
અમે PWM આઉટપુટ માટે આ ESP32 પિન પરીક્ષણ કર્યા અને તે બધા માઇક્રો-સર્વો ચલાવવા માટે કાર્ય કરે છે:
CopyEdit1, 2, 3, 4, 5, 6, 19, 35, 36, 38, 39, 40, 41, 42, 45, 47, 48
પ્રમાણભૂત SG90 માટે, અમારો કોડ 400 µs (0°) થી 2400 µs (180°) ની પલ્સ રેન્જ વાપરે છે, જે ઝટકા વિના સરળ, સંપૂર્ણ સ્વીપ આપે છે.
6. વાયરિંગ ડાયાગ્રામ
નીચે પ્લેસહોલ્ડર્સ છે જ્યાં તમે તમારા TX અને RX સ્કીમેટિક્સ મૂકી શકો છો:


કોડ અને એફિલિએટ લિંક્સ
ઉપરોક્ત તમામ સ્કેચ નીચેના “કોડ અને સંસાધનો†વિભાગમાં ડાઉનલોડ માટે ઉપલબ્ધ છે. જો તમે આ જાતે બનાવવા માંગો છો, તો કૃપા કરીને અમારી એફિલિએટ લિંક્સ દ્વારા તમારું Heltec LoRa32 V3 મોડ્યુલ, Meshnology N33 કેસ, રોટરી એન્કોડર અને SG90 સર્વો ખરીદવાનું વિચારો. તેનાથી તમને કોઈ વધારાનો ખર્ચ નથી થતો અને તે અમને આવા મફત ટ્યુટોરિયલ બનાવવાનું ચાલુ રાખવામાં મદદ કરે છે!
સંદર્ભ માટે વિડિયો પ્રકરણો
-
00:00 પરિચય અને ઝાંખી
-
00:05 રિમોટ કંટ્રોલ વિભાવનાઓ
-
00:19 LoRa સંચાર મૂળભૂત બાબતો
-
00:23 હાર્ડવેર પૂર્વાવલોકન
-
00:28 કેસ અને બેટરી શોકેસ
-
01:03 મોડ્યુલ સુવિધાઓ
-
01:42 સ્પેક્સ અને કનેક્ટિવિટી
-
02:54 સર્વોને પાવર આપવો
-
03:05 વાયરિંગ અને પિનઆઉટ
-
09:35 એન્ટેના પ્લેસમેન્ટ
-
11:04 કેસ એસેમ્બલી
-
29:26 સ્કેચ અપલોડ કરવા
-
35:09 રેન્જ ટેસ્ટ 1.2 કિમી
-
36:38 રેન્જ ટેસ્ટ 1.4 કિમી
-
38:41 પ્રદર્શન રીકેપ
-
43:04 નિષ્કર્ષ અને સમર્થન
આ ટ્યુટોરિયલ આનો ભાગ છે: WiFi LoRa 32 ટ્યુટોરિયલ્સ
- હેલ્ટેક WiFi LoRa 32 V3 નો ઉપયોગ કરીને DHT22 દ્વારા તાપમાન 1.4 કિમી સુધી પ્રસારિત કરવું
- 13 માઇલ 20 કિમી WiFi વગર? LoRa એ કેવી રીતે પાગલ અંતર પર વોલ્ટેજ મોકલ્યું! (Heltec WiFi LoRa 32 V3)
- 13 માઇલ (21 કિમી) દૂરથી ઉપકરણ ચાલુ કરો – WiFi LoRa 32 સાથેનો અલ્ટીમેટ ઓફ-ગ્રીડ LoRa પ્રોજેક્ટ!
- દૂરસ્થ દરવાજા ચેતવણી સિસ્ટમ 13 માઇલ 21 કિમી દૂરથી LoRa સાથે – ગ્રીડની બહાર! (Heltec WiFi LoRa 32 V3)
- DIY રિમોટ રિલે પ્રોજેક્ટ: 13 માઇલ નો-વાઇ-ફાઇ/નો-સિમ Heltec LoRa 32 મોડ્યુલ
- How to Use the Heltec LoRa CubeCell Development Board HTCC-AB01
/*
File: Heltec_ESP32_LoRa_V3_Sevo_TX_AiRotaryEncoder.ino
written on 24 Jun, 2025 by Ahmad Shamshiri
* =====================================================================
* ARDUINO CODE DESCRIPTION: SECURE LoRa SERVO CONTROL SYSTEM (TX)
* =====================================================================
*
* HARDWARE COMPONENTS:
* -------------------
* - Main Controller: Heltec WiFi LoRa 32 V3
* - Enclosure: Meshnology N33 case with 3000mAh battery
* - Input: Rotary encoder with push-button
* - Feedback: Built-in OLED display
* - Output: Servo motor + LoRa wireless transmission
*
* SYSTEM FUNCTIONALITY:
* -------------------
* [1] ROTARY ENCODER CONTROL:
* - Clockwise/Counter-clockwise rotation adjusts target angle (0°-180°)
* - Real-time angle display on OLED screen
* - Push-button returns servo to Home position (default: 90°)
*
* [2] SECURE WIRELESS TRANSMISSION:
* - All angle values encrypted before LoRa transmission
* - Home position command transmitted as special secure packet
* - Uses 433MHz LoRa band for reliable communication
*
* [3] POWER MANAGEMENT:
* - Optimized for battery operation (3000mAh)
* - Low-power modes between transmissions
*
* FOR COMPLETE SETUP INSTRUCTIONS:
* Please watch the tutorial video at: https://youtu.be/EPynuJ7sasY
* =====================================================================
Watch full video explaination: https://youtu.be/EPynuJ7sasY
Resources page: https://robojax.com/T635
* DISCLAIMER:
* This code is provided "AS IS" without warranty of any kind. The author
* shall not be held liable for any damages arising from the use of this code.
*
* LICENSE:
* This work is licensed under the GNU General Public License v3.0
* Permissions beyond the scope of this license may be available at Robojax.com
*
* SHARING TERMS:
* You are free to share, copy and modify this code for non-commercial purposes
* PROVIDED you:
* 1. Keep this entire comment block intact with the original code
* 2. Include the original Robojax.com link
* 3. Keep the YouTube tutorial link (if applicable)
* 4. Clearly indicate any modifications made
*
* Original tutorial at: https://robojax.com/T635
* YouTube Video: https://youtu.be/EPynuJ7sasY
*
* ********************************************************************
*/
#include <Wire.h>
#include "HT_SSD1306Wire.h"
#include "WiFi.h"
static SSD1306Wire display(0x3c, 500000, SDA_OLED, SCL_OLED, GEOMETRY_128_64, RST_OLED); // addr , freq , i2c group , resolution , rst
const int TX_POWER = 2;//dBm from 2 to 20. when powered via battery 2 to 14dBm is the best option
const int MAX_ANGLE = 180;//the most common is 180, but you can set it as needed
String labelAngle = "Angle";
const int homePosition = 90; //initial position
//endcoder
const int SW_PIN = 4;//define a pin for rotary encode switch
const int PIN_A = 6;
const int PIN_B = 5;//
const int ANGLE_STEP = 6;//
const bool debug= false;//to print debug data in serial moinitor set it to true, else false
int servoAngel = homePosition;
int oldAngleValue = servoAngel;
#include "mbedtls/aes.h"//for securing data
#include <cstring> // For memset, memcpy
mbedtls_aes_context aes;
const char *userKey = "hyhT676#h~_1a"; //Security key.
#include "LoRaWan_APP.h"
#include "AiEsp32RotaryEncoder.h"
#include "Arduino.h"
#define ROTARY_ENCODER_VCC_PIN -1
//instead of changing here, rather change numbers above
AiEsp32RotaryEncoder rotaryEncoder = AiEsp32RotaryEncoder(
PIN_A,
PIN_B,
SW_PIN,
ROTARY_ENCODER_VCC_PIN,
ANGLE_STEP);
#define RF_FREQUENCY 915432000 // Hz
#define TX_OUTPUT_POWER TX_POWER // dBm from 2 to 20. when powered via battery 2 to 14dBm
#define LORA_BANDWIDTH 0 // [0: 125 kHz,
// 1: 250 kHz,
// 2: 500 kHz,
// 3: Reserved]
#define LORA_SPREADING_FACTOR 7 // [SF7..SF12]
#define LORA_CODINGRATE 1 // [1: 4/5,
// 2: 4/6,
// 3: 4/7,
// 4: 4/8]
#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx
#define LORA_SYMBOL_TIMEOUT 0 // Symbols
#define LORA_FIX_LENGTH_PAYLOAD_ON false
#define LORA_IQ_INVERSION_ON false
#define RX_TIMEOUT_VALUE 1000
#define BUFFER_SIZE 64 // Define the payload size here
char txpacket[BUFFER_SIZE];
char rxpacket[BUFFER_SIZE];
double txNumber;
bool lora_idle=true;
static RadioEvents_t RadioEvents;
unsigned long lastTxTime = 0;
void OnTxDone( void );
void OnTxTimeout( void );
void decryptAES(uint8_t *data, const char *key);
void encryptAES(uint8_t *data, const char *key);
void processKey(const char *userKey, uint8_t *processedKey, size_t keySize);
void VextON(void);
void rotary_loop();//prototyp function: rotary encoder
void IRAM_ATTR readEncoderISR();//prototyp function: rotary encoder
void rotary_onButtonClick();//prototyp function: rotary encoder
void setup() {
Serial.begin(115200);
Serial.println();
VextON();
delay(100);
//we must initialize rotary encoder
rotaryEncoder.begin();
rotaryEncoder.setup(readEncoderISR);
bool circleValues = false;
rotaryEncoder.setBoundaries(0, MAX_ANGLE, circleValues); //minValue, maxValue, circleValues true|false (when max go to min and vice versa)
/*Rotary acceleration introduced 25.2.2021.
* in case range to select is huge, for example - select a value between 0 and 1000 and we want 785
* without accelerateion you need long time to get to that number
* Using acceleration, faster you turn, faster will the value raise.
* For fine tuning slow down.
*/
//rotaryEncoder.disableAcceleration(); //acceleration is now enabled by default - disable if you dont need it
rotaryEncoder.setAcceleration(20); //or set the value - larger number = more accelearation; 0 or 1 means disabled acceleration
rotaryEncoder.reset(homePosition); //set home position
// Initialising the UI will init the display too.
display.init();
display.setFont(ArialMT_Plain_10);
//LoRa stuff
Mcu.begin(HELTEC_BOARD,SLOW_CLK_TPYE);
txNumber=0;
RadioEvents.TxDone = OnTxDone;
RadioEvents.TxTimeout = OnTxTimeout;
Radio.Init( &RadioEvents );
Radio.SetChannel( RF_FREQUENCY );
Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
LORA_SPREADING_FACTOR, LORA_CODINGRATE,
LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
true, 0, 0, LORA_IQ_INVERSION_ON, 3000 );
}
void displayAngle() {
display.clear(); // Clear display before new content
// Line 1: Text: Angle
display.setTextAlignment(TEXT_ALIGN_LEFT);
// Line 2: Temperature value in 24pt font
display.setFont(ArialMT_Plain_24);
// Format
String angleString = String(servoAngel) + "°"; //
display.setFont(ArialMT_Plain_16);
display.drawString(0, 0, labelAngle);
display.setFont(ArialMT_Plain_24);
display.drawString(0, 15, angleString);
display.display(); // Update OLED
}
void VextON(void)
{
pinMode(Vext,OUTPUT);
digitalWrite(Vext, LOW);
}
void VextOFF(void) //Vext default OFF
{
pinMode(Vext,OUTPUT);
digitalWrite(Vext, HIGH);
}
void sendData()
{
String txData = String(servoAngel) ;
uint8_t data[BUFFER_SIZE];
memset(data, 0, sizeof(data)); // Zero-padding
strncpy((char*)data, txData.c_str(), sizeof(data) - 1); // Copy string safely
encryptAES(data, userKey); // Encrypt before sending
if(lora_idle == true)
{
//delay(1000);
Radio.Send(data, sizeof(data));
if(debug){
Serial.print("Sending: ");
Serial.println((char *)data);
}
lora_idle = false;
oldAngleValue =servoAngel;//keep record of angle change
}
Radio.IrqProcess( );
}
void loop() {
rotary_loop();
// clear the display
display.clear();
displayAngle(); //
if(oldAngleValue != servoAngel)
{
sendData();
}
//delay(100);
}
void OnTxDone( void )
{
if(debug){
Serial.println("TX done......");
}
lora_idle = true;
}
void OnTxTimeout( void )
{
Radio.Sleep( );
if(debug){
Serial.println("TX Timeout......");
}
lora_idle = true;
}
/**
* Converts a user-provided plaintext key into a fixed-length 16-byte (128-bit)
* or 32-byte (256-bit) key.
*/
void processKey(const char *userKey, uint8_t *processedKey, size_t keySize) {
memset(processedKey, 0, keySize); // Fill with zeros
size_t len = strlen(userKey);
if (len > keySize) len = keySize; // Truncate if too long
memcpy(processedKey, userKey, len); // Copy valid key part
}
/**
* Encrypts a 16-byte (one block) message using AES-128.
*/
void encryptAES(uint8_t *data, const char *key) {
uint8_t processedKey[16]; // 128-bit key
processKey(key, processedKey, 16);
mbedtls_aes_init(&aes);
mbedtls_aes_setkey_enc(&aes, processedKey, 128);
mbedtls_aes_crypt_ecb(&aes, MBEDTLS_AES_ENCRYPT, data, data);
mbedtls_aes_free(&aes);
}
/**
* Decrypts a 16-byte (one block) message using AES-128.
*/
void decryptAES(uint8_t *data, const char *key) {
uint8_t processedKey[16]; // 128-bit key
processKey(key, processedKey, 16);
mbedtls_aes_init(&aes);
mbedtls_aes_setkey_dec(&aes, processedKey, 128);
mbedtls_aes_crypt_ecb(&aes, MBEDTLS_AES_DECRYPT, data, data);
mbedtls_aes_free(&aes);
}
void rotary_onButtonClick()
{
static unsigned long lastTimePressed = 0;
//ignore multiple press in that time milliseconds
if (millis() - lastTimePressed < 500)
{
return;
}
lastTimePressed = millis();
if(debug){
Serial.print("button pressed ");
Serial.print(millis());
Serial.println(" milliseconds after restart");
}
}
void rotary_loop()
{
//dont print anything unless value changed
if (rotaryEncoder.encoderChanged())
{
if(debug){
Serial.print("Value: ");
Serial.println(rotaryEncoder.readEncoder());
}
servoAngel = rotaryEncoder.readEncoder();
}
if (rotaryEncoder.isEncoderButtonClicked())
{
rotaryEncoder.reset(homePosition);
servoAngel = homePosition;
rotary_onButtonClick();
}
}
void IRAM_ATTR readEncoderISR()
{
rotaryEncoder.readEncoder_ISR();
}
Common Course Links
Common Course Files
સંસાધનો અને સંદર્ભો
-
બાહ્યHeltec WiFi Kit 32 website linkheltec.org
-
બાહ્ય
-
બાહ્યPurchase a WiFi LoRa 32 V3 from AliExpresss.click.aliexpress.com
-
બાહ્યPurchase a WiFi LoRa 32 V3 from AliExpress-2s.click.aliexpress.com
-
બાહ્ય
ફાઇલો📁
Arduino લાઇબ્રેરીઓ (zip)
-
Robojax_HeltecLoRa32V3
Robojax_HeltecLoRa32V3.zip0.09 MB