LoRa lost connection

I need to make wireless control for pump, but it's about 1,5 km between pump and water tank so I used LoRa, but I meet incoming problem. In first few minutes after connection to power everything is working correctly, but when some time pass reciving module just stop working while transciver module is still working good. Did anybody already met this problem?
I wire it like on this page, but with some change
[Interfacing SX1278 Ra-02 LORA Module with Arduino]

I connected transmitter module as on the image, but instead of potentiometer I used hardware debounced switch connected to pin 2 and LED on pin 4 showing correct state.

On receiver side I also made a little change, instead of LED I connected transistor to control relay

There is receiver code

#include <SPI.h>
#include <LoRa.h> 
int LED = 3;
String inString = "";    // string to hold input
int val = 0;
 
void setup() {
  Serial.begin(9600);
  pinMode(LED,OUTPUT);
  pinMode(4,OUTPUT);
  
  while (!Serial);
  Serial.println("LoRa Receiver");
  if (!LoRa.begin(433E6)) { // or 915E6
    Serial.println("Starting LoRa failed!");
    while (1);
  }

  LoRa.setSyncWord(0xF3);

}


void loop() {
  
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize) { 
    // read packet    
    while (LoRa.available())
    {
      int inChar = LoRa.read();
      inString += (char)inChar;
      val = inString.toInt();       
    }

    Serial.println(inString);
    inString = "";     
    LoRa.packetRssi();    
    

  }
      
  
  digitalWrite(LED, val);

}

And that's transmitter

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

bool sw = 0;

void button();

void setup() {
  Serial.begin(9600);

  pinMode(4, OUTPUT);
  pinMode(2, INPUT_PULLUP);
  while (!Serial);  
  Serial.println("LoRa Sender");
  if (!LoRa.begin(433E6)) { // 433E6 or 915E6, the MHz speed of yout module
    Serial.println("Starting LoRa failed!");
    while (1);
  }
  LoRa.setSyncWord(0xF3);
  LoRa.setTxPower(2);
  
  delay(5000);
}

 
void loop() {
 
  if(digitalRead(2) == HIGH)
  {
    delay(1000);
    LoRa.beginPacket();  
    LoRa.print(1);
    LoRa.endPacket();
    digitalWrite(4, HIGH);
  }
  else{
    delay(1000);
    LoRa.beginPacket();  
    LoRa.print(0);
    LoRa.endPacket();
    digitalWrite(4, LOW);
  }
}

Sorry for my english

You forgot to tell us which Arduino you are using. If it is an AVR based Arduino, like the Uno, use of Strings eventually causes program crashes.

If that is the case, remove all references to String objects in your code.

For example, you can replace all of this:

  while (LoRa.available())
    {
      int inChar = LoRa.read();
      inString += (char)inChar;
      val = inString.toInt();       
    }

    Serial.println(inString);
    inString = "";     
    LoRa.packetRssi();    
    

  }
      
  
  digitalWrite(LED, val);

With something like this:

  while (LoRa.available())
    {
      char inChar = (char) LoRa.read();
     if (inChar == '1') digitalWrite(LED, 1);
     if (inChar == '0') digitalWrite(LED, 0);
      }

Another potential problem is the power supply. Relays and other electrical equipment can introduce noise in the Arduino power supply which can reset an Arduino, or cause it to malfunction.

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