Node to Node communication on LoRa with Arduino Nano and 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. Arduino Nano
  2. ESP32
  3. 2x LoRa Bee modules
  4. 4x 3.2K ohm Resistor
  5. 74LVC125A IC
  6. Jumper Wires

Circuit Diagram

circuit diagram of LoRa with Arduino Nano and ESP32

circuit diagram of esp

Pin Details

ESP32

LoRa BEE

LoRa 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

Β Arduino Nano

LoRa BEE

LoRa BEE

physical pin

74LVC125A

Arduino Nano

MISO

Β  4

Β  Β  Β  Β 12

Β 

Β  Β  Β  Β ----

RESET

Β 5

Β  Β  Β  Β ----

Β  Β  Β  Β D10

MOSI

11

Β  Β  Β  Β  Β 3

Β  Β  Β  Β ----

D0 Β 

Β 12

Β  Β  Β  -----

Β  Β  Β  Β D2

NSS

Β 17

Β  Β  Β  Β  Β 8

Β  Β  Β  Β ----

SCK

Β 18

Β  Β  Β  Β  6

Β  Β  Β  Β ----

3V3

Β  1

Β  Β  Β  14

Β  Β  Β  ----

GND

Β 10

Β  Β  Β  Β 7

Β  Β  Β  ----

Β 

Arduino Nano

74LVC125A

MISO

Β  Β  Β  Β  11

MOSI

Β  Β  Β  Β  Β 2

NSS

Β  Β  Β  Β  Β 9

SCK

Β  Β  Β  Β  Β 5

3V3

Β  Β  Β  Β  14

GND

Β  Β  Β  Β  Β  7

Β 

For node to node communication, the Nano will be configured as the Transmitter and the ESP32 will be configured as the receiver.

Step 1: Installing ESP32 Add-on in Arduino IDE

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

1. In your Arduino IDE, go to File> Preferences.

2. 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.

    3. Go to Tools > Board > Boards Manager

      Β 

      4. Search for β€œESP32” and Click on the install button

        5. The installation may take a while depending on your network performance. Once done, close the board manager

          Β 

          Step 2: Code and Library

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

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

          Installing library

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

            Β 

            2. At the top of the drop-down list, select the option to "Add. ZIP Library''.

              Step 3: Transmission Code

              1. In your Arduino IDE, go to Tools > Board > Arduino Nano.

                2. Type in the code below and click on the Upload button to upload the code in the Arduino IDE.

                Β 

                  #include <SPI.h>

                  #include <LoRa.h>

                  //define the pins used by the transceiver module

                  #define ss 10

                  #define rst 9

                  #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);

                  }

                  Β 

                  3. After uploading code open Arduino serial monitor to observe the data being transmitted.

                    Β 

                    Step 4: Receiver Code

                    1. In your Arduino IDE, go to Tools > Board > ESP32 Dev Module.

                    2. Type in the code below and click on the Upload button to upload the code 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());

                      Β  }

                      }

                      1. After uploading code open Arduino serial monitor to observe the data being received.
                      2. Β 

                        1. In receiver end, you can see the received packet

                        Β 

                        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. You can check so, by making sure the below line is the same in both receiver and transmitter code

                          while (!LoRa.begin(866E6))

                          2.Β Make sure the baud rate is set to 115200 in the Serial monitor for both the devices

                          Leave a comment

                          Please note, comments must be approved before they are published