# Using LoRa To Control LEDs but cannot get it to work

**URL:** <https://forum.arduino.cc/t/using-lora-to-control-leds-but-cannot-get-it-to-work/1253507>\
**Category:** Programming\
**Created:** [April 29, 2024, 9:36am UTC](https://forum.arduino.cc/t/using-lora-to-control-leds-but-cannot-get-it-to-work/1253507 "2024-04-29T09:36:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hayden\_little22](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hayden_little22/32/1066178_2.png) [@hayden\_little22](https://forum.arduino.cc/u/hayden_little22)\
**Post date:** [April 29, 2024, 9:36am UTC](https://forum.arduino.cc/t/using-lora-to-control-leds-but-cannot-get-it-to-work/1253507/1 "2024-04-29T09:36:54Z")

</div>

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:

```arduino
#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);
    }

}

```

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [April 29, 2024, 10:21am UTC](https://forum.arduino.cc/t/using-lora-to-control-leds-but-cannot-get-it-to-work/1253507/2 "2024-04-29T10:21:59Z")

</div>

Hi, @hayden_little22  
Welcome to the forum.

> [@How to get the best out of this forum](https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966):
>
> See also [FAQ - Arduino Forum](https://forum.arduino.cc/faq) for general rules on forum behavior and etiquette. Hello, Welcome to the Arduino Forum. This guide explains how to get the best out of this forum. Please read and follow the instructions below. Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is frus…

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... 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [April 29, 2024, 10:23am UTC](https://forum.arduino.cc/t/using-lora-to-control-leds-but-cannot-get-it-to-work/1253507/3 "2024-04-29T10:23:23Z")

</div>

you do that

> [@hayden\_little22](#):
>
> ```arduino
> String LoRaLabel = LoRa.readString();
> LoRa.read();
> if (LoRaLabel.endsWith("Tight")) {
> digitalWrite(LED_Green, HIGH);
> }
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [April 29, 2024, 10:36am UTC](https://forum.arduino.cc/t/using-lora-to-control-leds-but-cannot-get-it-to-work/1253507/4 "2024-04-29T10:36:21Z")

</div>

in case you string contains end\_of\_line characters try using [IndexOf](https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/indexof/)

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

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 26, 2024, 10:37am UTC](https://forum.arduino.cc/t/using-lora-to-control-leds-but-cannot-get-it-to-work/1253507/5 "2024-10-26T10:37:11Z")

</div>

Closed on October 26, 2024, 10:37am UTC

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