Node to Node communication on LoRa With ESP32

What is LoRa?

LoRa, short for long-range, is the physical layer or the wireless modulation utilized to create a long-range communication link. LoRa is based on Chirp Spread Spectrum (CSS) modulation, which maintains the same low power characteristics as FSK modulation but significantly increases the communication range.

Material Required is as follows:

  1. 2x LoRa Bee modules
  2. 2xESP32
  3. 1x Breadboard
  4. Jumper Wires

Circuit Diagram

circuit diagram for communication on LoRa With ESP32

Pin Details

LoRe BEE

LoRe BEE

physical pin

ESP32 Pin

MISO

Β  4

Β  Β  Β  Β  D19(MISO)

Β 

RESET

Β 5

Β  Β  Β  Β  D14

MOSI

11

Β  Β  Β  Β  D23(MOSI)

D0 Β 

Β 12

Β  Β  Β  Β  D2

NSS

Β 17

Β  Β  Β  Β  D5

SCK

Β 18

Β  Β  Β  Β  D22(SCLK)

3V3

Β  1

Β  Β  Β  Β  Β 3V3

GND

Β 10

Β  Β  Β  Β  Β GND

Β 

Now we are going to set up LoRa Node to Node communication using ESP32. In Node to Node communication, we use two nodes. One of the nodes we configure as Transmitter and another node as Receiver

Step1: Installing ESP32 Add-on in Arduino IDE

To install the ESP32 board in your Arduino IDE, follow the steps given below

In your Arduino IDE, go to File> Preferences

Β 

Enter https://dl.espressif.com/dl/package_esp32_index.jsonΒ into the β€œAdditional Board Manager URLs” field as shown in the figure below.

Then, click the β€œOK” button

Go to Tools > Board > Boards Manager

Β 

Search ESP32 and Click on the install button

It should be installed after a few seconds.

Step2: Code And Library

Β Download as Zip file of Arduino-LoRa Library refer below link

https://www.arduino.cc/reference/en/libraries/lora/

Β 

Installing library

In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library.

Β 

At the top of the drop-down list, select the option to "Add. ZIP Library'' and choose the library zip file downloaded from the link given above.

Step 3: Sender Code

In your Arduino IDE, go to Tools > Board>ESP32 Arduino

Select your Board

Enter the following code and click on the Upload button in the Arduino IDE

#include <SPI.h>

#include <LoRa.h>

Β 

//define the pins used by the transceiver module

#define ss 5

#define rst 14

#define dio0 2

Β 

int counter = 0;

Β 

void setup() {

Β  //initialize Serial Monitor

Β  Serial.begin(115200);

Β  while (!Serial);

Β  Serial.println("LoRa Sender");

Β 

Β  //setup LoRa transceiver module

Β  LoRa.setPins(ss, rst, dio0);

Β 

Β  //replace the LoRa.begin(---E-) argument with your location's frequency

Β  //433E6 for Asia

Β  //866E6 for Europe

Β  //915E6 for North America

Β  while (!LoRa.begin(866E6)) {

Β  Β  Serial.println(".");

Β  Β  delay(500);

Β  }

Β  // Change sync word (0xF3) to match the receiver

Β  // The sync word assures you don't get LoRa messages from other LoRa transceivers

Β  // ranges from 0-0xFF

Β  LoRa.setSyncWord(0xF3);

Β  Serial.println("LoRa Initializing OK!");

}

Β 

void loop() {

Β  Serial.print("Sending packet: ");

Β  Serial.println(counter);

Β 

Β  //Send LoRa packet to the receiver

Β  LoRa.beginPacket();

Β  LoRa.print("hello ");

Β  LoRa.print(counter);

Β  LoRa.endPacket();

Β 

Β  counter++;

Β 

Β  delay(10000);

}

Once the code is uploaded, open the Arduino Serial monitor

Step 4: Receiver Code

In your Arduino IDE, go to Tools > Board>ESP32 Arduino

Select your Board

Enter the following code and click on the Upload button in the Arduino IDE

#include <SPI.h>

#include <LoRa.h>

Β 

//define the pins used by the transceiver module

#define ss 5

#define rst 14

#define dio0 2

Β 

void setup() {

Β  //initialize Serial Monitor

Β  Serial.begin(115200);

Β  while (!Serial);

Β  Serial.println("LoRa Receiver");

Β 

Β  //setup LoRa transceiver module

Β  LoRa.setPins(ss, rst, dio0);

Β 

Β  //replace the LoRa.begin(---E-) argument with your location's frequency

Β  //433E6 for Asia

Β  //866E6 for Europe

Β  //915E6 for North America

Β  while (!LoRa.begin(866E6)) {

Β  Β  Serial.println(".");

Β  Β  delay(500);

Β  }

Β  Β // Change sync word (0xF3) to match the receiver

Β  // The sync word assures you don't get LoRa messages from other LoRa transceivers

Β  // ranges from 0-0xFF

Β  LoRa.setSyncWord(0xF3);

Β  Serial.println("LoRa Initializing OK!");

}

Β 

void loop() {

Β  // try to parse packet

Β  int packetSize = LoRa.parsePacket();

Β  if (packetSize) {

Β  Β  // received a packet

Β  Β  Serial.print("Received packet '");

Β 

Β  Β  // read packet

Β  Β  while (LoRa.available()) {

Β  Β  Β  String LoRaData = LoRa.readString();

Β  Β  Β  Serial.print(LoRaData);

Β  Β  }

Β 

Β  Β  // print RSSI of packet

Β  Β  Serial.print("' with RSSI ");

Β  Β  Serial.println(LoRa.packetRssi());

Β  }

}

Once the upload is complete, open the Arduino Serial monitor

On the receiver, you can see the packet transmitted by the transmitter.

Troubleshooting

Β 

After uploading code if you are not receiving any packet into the receiver node follow the below steps

Β 

Β  Β  1.Make sure both node sender and receiver are working the same

Β  Β  Β  Β Frequency. Check the following lines in both the codes:

Β 

while (!LoRa.begin(866E6))

Β  2.Β Ensure that the Serial Monitor is using a bad rate of 115200.

3. Check all connections to ensure they are correct.

Β 

Leave a comment

Please note, comments must be approved before they are published