Using LoRa To Control LEDs but cannot get it to work

Hi all,

I'm working on 2 LoRa32u4 devices.
One is sending a signal if a strap is loose or tight. The other should change the attached LEDs Red or Green if it is Loose or Tight respectively.

The sender LoRa unit is sending "Tight" or "Loose"

The below is my receiver code:

#include <LoRa.h>

/*********
  Modified from the examples of the Arduino LoRa library
  More resources: https://randomnerdtutorials.com
*********/

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

//define the pins used by the transceiver module
#define ss 8
#define rst 4
#define dio0 7

#define LED_Green   13
#define LED_Red     12

void setup() {

  pinMode(LED_Red, OUTPUT);
  pinMode(LED_Green, OUTPUT);

  //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());
  }

    String LoRaLabel = LoRa.readString();
    LoRa.read();
    if (LoRaLabel.endsWith("Tight")) {
      digitalWrite(LED_Green, HIGH);
    }

}

Hi, @hayden_little22
Welcome to the forum.

What is your code doing?

Have you used the Library examples to prove you have control of the Lora units and have a communications link?

Can you please post a link specs/data of the Lora32u4 device?

Is the Lora library compatible with the device?

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

you do that

all the time in the loop, whether or not you've received a packet... and when you get a packet you actualu dump it without checking what's the content...

also you never use the red led...

in case you string contains end_of_line characters try using IndexOf

if (LoRaLabel.indexOf("Tight")  >=  0) {

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