Using LoRa SX1278 & Arduino UNO (as transmitter) and ESP32 Devkit V1 & LoRa SX1278 (as receiver), failed to connect

The test project uses a TMP36 sensor in the transmitter to send data wirelessly to the receiver, yet it has failed numerous times. I have double-checked the connections and the configuration of LoRa such as spread factor, bandwidth, coding rate, and frequency in Asia, yet it keeps failing. I need your help if I have overlooked some factors to solve the issue.

Below are the schematic diagram and the code.
[Transmitter]

[Receiver]

TX Code

//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>
//Library for pin assignments
#include <Wire.h>

//define the pins used by the transceiver module
#define SS 10
#define RESET 9
#define DIO0 2
#define SCK 13
#define MISO 12
#define MOSI 11

//433E6 for Asia
#define LORA_FREQUENCY 433E6  // Set your desired frequency (in Hz)
#define LORA_SPREADING_FACTOR 12
#define LORA_SIGNAL_BANDWIDTH 125E3
#define LORA_CODING_RATE 7

const int tmp36Pin = A0;
float temperature;

void setup() {
  Serial.begin(115200);
  while (!Serial);
  if (!LoRa.begin(LORA_FREQUENCY)){  // Initialize LoRa module
    Serial.println("LoRa initialization failed. Check your connections.");
    while (1);
  }
  LoRa.setSpreadingFactor(LORA_SPREADING_FACTOR);
  LoRa.setSignalBandwidth(LORA_SIGNAL_BANDWIDTH);
  LoRa.setCodingRate4(LORA_CODING_RATE);


  Serial.println("LoRa transmitter started.");
}

void loop() {
  int sensorValue = analogRead(tmp36Pin);        // Read temperature from TMP36 sensor
  float voltage = sensorValue * (5.0 / 1023.0);
  temperature = (((voltage - 0.5) * 100.0)* 1.8) +32;

  // Send temperature data over LoRa
  Serial.print("Sending temperature: ");
  Serial.println(temperature);
  LoRa.beginPacket();
  LoRa.print(temperature);
  LoRa.endPacket();

  delay(5000); // Send data every 5 seconds
}

RX Code

#include <SPI.h>
#include <LoRa.h>
#include <Wire.h>

//define the pins used by the transceiver module
#define ss 4
#define rst 14
#define dio0 21

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(433E6)) {
    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());
  }
}

Note: The assigned pins for ESP32 Devkit V1 for NSS & DIO0 have been changed due to conditions in the ESP32 pinout hence why it was specified in the RX code.

The Arduino UNO is a 5V Logic level device.

The LoRa device uses 3.3V logic levels so can be damadged if you connect it directly to a 5V logic device such as a UNO.

You need to use logic level conversion circuits between the UNO and the LoRa device.

Is the Tx Arduino running at 5v?
The picture is difficult to read. Is the receiving ESP32 using D19 for SS?

Other issues.

DO NOT set syncwords, they do not work like you might think they do. Some syncwords just dont work, some are leaky and some reduce sensitivity. Stick to the two that are known to work;

#define LORA_MAC_PRIVATE_SYNCWORD                   0x12
#define LORA_MAC_PUBLIC_SYNCWORD                    0x34

Your setting the Spreading factor to 12 in the TX but leaving it as default (7) in the RX code.

There may be other errors, I gave up looking.

I would try your initial setup with the basic LoRaSender and LoRaReceiver examples from the library, at least your starting with known working code.

Hi! Yes the TX Arduino is running at 5V, but It's connected to my laptop. While the RX ESP32 NSS uses D4

I see, but I connected the LoRa VCC to the 3.3V of Arduino Uno, that wouldn't get damaged right?

Not correct.

The UNO puts out 5V logic level signals on SS, SCK, and MOSI pins. So your connecting 5V signals to a device that has a 3.3V supply, do you see the potential problem ?

Much easier to just use 3.3V Arduinos for LoRa devices.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.