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:

  • 2x LoRa Bee modules
  • 2xESP32
  • 1x Breadboard
  • Jumper Wires

Circuit Diagram

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