Usage Example for ESP32-LoRa Wireless Transmission

Last revision 2026/01/06

This article outlines the steps for setting up ESP32-LoRa wireless transmission, including necessary hardware and software, wiring instructions, and sample code for master and slave devices to communicate effectively.

Hardware Preparation

Software Preparation

Wiring Diagram

TEL0125-Wiring diagram

Connection:

  • Joint ESP32 board and LoRa module together.
  • Connect ESP32 board to PC via USB line.

Other Preparation Work

Pin Connection Configuration Guide

Item Details
Default Pin Connections CS Pin → D4, RESET Pin → D2
Custom Pin Assignment Method Modify the program and specify other IO interfaces by passing parameters to the initialization function
Initialization Function Prototype init(uint8_t NSSPin = NSS_PIN, uint8_t NRESETPin = RESET_PIN)

Supplementary Notes:

  • NSSPin/NRESETPin: Function input parameters for specifying custom CS/RESET pins.
  • NSS_PIN/RESET_PIN: Default macro definitions corresponding to the default pins D4/D2.

Sample Code

Download the master program and the slave program to two ESP32 board respectively.

The Slave program code: LoRa module receives data, prints data/RSSI and toggles onboard LED.

/*!
 * @file receiverTest.ino
 * @brief DFRobot's received data
 * @n [Get the module here]
 * @n This example is receive.
 * @n [Connection and Diagram]
 *
 * @copyright	[DFRobot](https://www.dfrobot.com), 2016
 * @copyright	GNU Lesser General Public License
 *
 * @author [yangyang]
 * @version  V1.0
 * @date  2017-04-10
 */
#include <DFRobot_LoRa.h>

DFRobot_LoRa lora;

uint8_t len;
uint8_t rxBuf[32];

void setup()
{
	Serial.begin(115200);

	pinMode(LED_BUILTIN, OUTPUT);
	Serial.println("Receiver Test");
        //init(uint8_t NSSPin = NSS_PIN, uint8_t NRESETPin = RESET_PIN)
	if(!lora.init()) {
		Serial.println("Starting LoRa failed!");
		while (1);
	}

	lora.rxInit();    
}
void loop()
{
	if(lora.waitIrq()) {   // wait for RXDONE interrupt
		lora.clearIRQFlags();
		len = lora.receivePackage(rxBuf);  // receive data
		Serial.write(rxBuf, len);    
		Serial.println();
		lora.rxInit();    // wait for packet from master
		
		// print RSSI of packet
    	Serial.print("with RSSI ");
    	Serial.println(lora.readRSSI());

		static uint8_t i;
		i = ~i;
		digitalWrite(LED_BUILTIN, i);
	}
}

The Master program code: LoRa module sends specified data cyclically, counts and prints send times.

/*!
 * @file sendTest.ino
 * @brief DFRobot's send data
 * @n [Get the module here]
 * @n This example is send.
 * @n [Connection and Diagram]
 *
 * @copyright	[DFRobot](https://www.dfrobot.com), 2016
 * @copyright	GNU Lesser General Public License
 *
 * @author [yangyang]
 * @version  V1.0
 * @date  2017-04-10
 */

#include <DFRobot_LoRa.h>

DFRobot_LoRa lora;

uint8_t counter = 0;
uint8_t sendBuf[] = "HelloWorld!";

/* The default pin:
/		SS:D2
/		RST:D3
*/

void setup()
{
	Serial.begin(115200);
	//init(uint8_t NSSPin = NSS_PIN, uint8_t NRESETPin = RESET_PIN)
	if(!lora.init()) {
		Serial.println("Starting LoRa failed!");
		while (1);
	}
}
void loop()
{
	Serial.print("Sending packet: ");
	Serial.println(counter);

	// send packet
	lora.sendPackage(sendBuf, sizeof(sendBuf)); // sending data
	lora.idle();    // turn to standby mode

	counter++;
#if 0
	if(counter%10 == 0) {
		lora.sleep();
		delay (5000);// sleep 5 seconds
	}
#endif

	delay(500);
}

Results

Two ESP32 motherboards successfully communicate and receive data.

TEL0125-The master sends data

TEL0125-The slave receives data

Was this article helpful?

TOP