Uno + Lora SX1278

Hi all,
i made to connect two arduino Uno's with 2 Lora sx1278 modules...On transmitter side (Ts) there are 2 switches (On/Off)...On receiver side (Rs) there are two relays (5V)....When I put switch in On position, signal is transferred from Ts to Rs, and relay is turned On....It is defined by code that number 11 is transferring to relays for ON, and number 22 for OFF. Also as a signal which shows that Lora modules are in range I use led diode which is blinking when Ts and Rs can see eachother
Where is the problem?
The problem is when i press switch to ON and data number 11 is sent, the Rs is not reacting sometimes and relay is still in OFF position...so there was no reaction even the action was sent...

I wanted to connect Ts to laptop and in Serial Monitor to type 11 several times instead of switching switch ON/OFF.... but when i typed 11 in SM nothing happend......so, is that possible and how to be sure that relay is turned on after signal is transferred?

Please help.
Thanks

Check for relay contact closure with your multimeter, or use the relay contacts to switch on an LED.

yes the contact is good on both sides....sometimes signal is transferred and relay is turned on, but sometimes signal is not transferred and relay is off even i put switch to ON....and when i repeat the process again, relay is turned ON from 2nd or 3rd attempt

post your code? how do you power the devices?

for both sides I am using USB cable for both arduinos from laptop...i noticed when i am using serial monitor and turn on switch 1 it reacts on serial monitor on transmitter side, so switch state is changed, but on receiver side is received nothing....when i repeat the process first go to off and again to on, then relay is turned on or off,...and then everything is working several times but suddenly it misses to turn off or turn on relay and then it works 4-5 times normally and then again miss to turn or off etc...thats why i wanted to have on transmitter side proof that relay is really turned on when switch is turned on

here are the pics and codes for both sides:

transmitter code

#include <LoRa.h>
//int pot = A0;
const int SW1 = 3;
const int SW2 = 4;

int SyncWord = 0x22;

void setup() {
Serial.begin(9600);
pinMode(SW1,INPUT_PULLUP);
pinMode(SW2,INPUT_PULLUP);

cli(); //stop interrupts
//set timer1 interrupt at 1Hz = 1sec
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // initialize counter value to 0
// set compare match register for 1hz increments
OCR1A = 15624; // = (1610^6) / (11024) - 1 (must be <65536)

TCCR1B |= (1 << WGM12); // turn on CTC mode
TCCR1B |= (1 << CS12) | (1 << CS10); // Set CS10 and CS12 bits for 1024 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt

sei(); //allow interrupts

while (!Serial);
Serial.println("LoRa Sender");
if (!LoRa.begin(433E6)) { // or 915E6, the MHz speed of yout module
Serial.println("Starting LoRa failed!");
while (1);
}

LoRa.setSpreadingFactor(12); // ranges from 6-12,default 7 see API docs
LoRa.setSignalBandwidth(62.5E3 ); // for -139dB (page - 112)
LoRa.setCodingRate4(8); // for -139dB (page - 112)
LoRa.setSyncWord(SyncWord);
/*
Serial.print("current spreading factor : ");
Serial.println(LoRa.getSpreadingFactor());
Serial.print("current bandwidth : ");
Serial.println(LoRa.getSignalBandwidth());
Serial.println("LoRa init succeeded.");
*/
}

int priviousSwitchValue1 = 1;
int priviousSwitchValue2 = 1;
int liveSwitchValue1 = 0;
int liveSwitchValue2 = 0;
bool switchPressFlag1 = false;
bool switchPressFlag2 = false;
bool gLedPin = 0;

int data = 1;

void loop() {
//static int data = 1;

liveSwitchValue1 = digitalRead(SW1);
if( (liveSwitchValue1 == 0) and (switchPressFlag1 == false) )
{
delay(50);
data = 11;
Serial.println("11");
switchPressFlag1 = true;
priviousSwitchValue1 = !priviousSwitchValue1;

LoRa.beginPacket();  
LoRa.print(data);
LoRa.endPacket();

}
if( (liveSwitchValue1 == 1) and (switchPressFlag1 == true) )
{
delay(50);
data = 22;
Serial.println("22");
switchPressFlag1 = false;
LoRa.beginPacket();
LoRa.print(data);
LoRa.endPacket();
}

liveSwitchValue2 = digitalRead(SW2);
if( (liveSwitchValue2 == 0) and (switchPressFlag2 == false))
{
delay(50);
data = 33;
Serial.println("33");
switchPressFlag2 = true;
priviousSwitchValue2 = !priviousSwitchValue2;
LoRa.beginPacket();
LoRa.print(data);
LoRa.endPacket();
}
if( (liveSwitchValue2 == 1) and (switchPressFlag2 == true) )
{
delay(50);
data = 44;
Serial.println("44");
switchPressFlag2 = false;
LoRa.beginPacket();
LoRa.print(data);
LoRa.endPacket();
}

if(gLedPin == 1)
{
data = 55;
Serial.println("55");
gLedPin = 0;
LoRa.beginPacket();
LoRa.print(data);
LoRa.endPacket();
}

// LoRa.beginPacket();
// LoRa.print(data);
// LoRa.endPacket();
}

ISR(TIMER1_COMPA_vect){//timer1 interrupt 1Hz toggles pin 13 (LED)
//generates pulse wave of frequency 1Hz/2 = 0.5kHz (takes two cycles for full wave- toggle high then toggle low)
static volatile int ledFlag = 0;
if(++ledFlag >= 5)
{
gLedPin = 1;
ledFlag = 0;
}
}

receiver picture with code

#include <LoRa.h>

const int LED1 = 3; // indicator LED
const int RLY1 = 4; // relay 1
const int RLY2 = 5; // relay 2

String inString = ""; // string to hold input
int val = 0;
int SyncWord = 0x22;

void setup() {
Serial.begin(9600);
pinMode(LED1,OUTPUT);
pinMode(RLY1,OUTPUT);
pinMode(RLY2,OUTPUT);

digitalWrite(LED1 , LOW);
digitalWrite(RLY1 , HIGH);
digitalWrite(RLY2 , HIGH);

while (!Serial);
Serial.println("LoRa Receiver");
if (!LoRa.begin(433E6)) { // or 915E6
Serial.println("Starting LoRa failed!");
while (1);
}
LoRa.setSpreadingFactor(12); // ranges from 6-12,default 7 see API docs
LoRa.setSignalBandwidth(62.5E3); // for -139dB (page - 112)
LoRa.setCodingRate4(8); // for -139dB (page - 112)
LoRa.setSyncWord(SyncWord); // ranges from 0-0xFF, default 0x12, see API docs
/*
Serial.print("current spreading factor : ");
Serial.println(LoRa.getSpreadingFactor());
Serial.print("current bandwidth : ");
Serial.println(LoRa.getSignalBandwidth());
Serial.println("LoRa init succeeded.");
*/
}
bool i=0;
int priviousValue = 0;
int liveValue = 0;

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();
digitalWrite(LED1 , HIGH);
delay(10);
digitalWrite(LED1 , LOW);
delay(10);
}
inString = "";
LoRa.packetRssi();
}

Serial.println(val);
liveValue = val;

if(priviousValue != liveValue)
{
priviousValue = liveValue;

if(val == 11)
{
  digitalWrite(RLY1 , LOW);
}

if(val == 22)
{
  digitalWrite(RLY1 , HIGH);
}

if(val == 33)
{
  digitalWrite(RLY2 , LOW);
}

if(val == 44)
{
  digitalWrite(RLY2 , HIGH);
}

}
delay(50);
}

/*

    1. when switch 1 is pressed turn ON RLY1 & RLY2
    1. if
      */

lets say i am at the apartment and want to turn on the fan in the basement which is one floor below the apartment...when i turn on the switch one i dont have any visual info that fan is started to work...the only visual contact i have on receiver side when led is blinking which shows me that both sides are connected....how to get any info on transmitter side that relay is turned on/off?

@horace i published codes 5 days ago and still waiting for your answer.... @jremington

it is some time since I used Lora peer to peer networking and not this particular Lora board.
You send a packet from the transmitter to the receiver why not send an acknowledgement back?
The acknowledgement could contain the relay status on or off by reading the pin state - of course the relay may not be connected or the fan working.
to check if the fan is operating one could use a sensor

  1. to detect fan rotation
  2. check the electrical supply current (be very careful when working with mains voltages)

dont know how to send an acknowledgement back? can you help me

in the receiver I assume you would use similar packet send as in the transmitter

LoRa.beginPacket();
LoRa.print(data);
LoRa.endPacket();

and the transmitter has a parsepacket to receive it

in the LoRa examples there is a LoRaDuplex.ino which appears to support two way communication

I want to add led diode on transmitter side like the one that exists on receiver side

this led diode will be blinked when the action is done (which means when relay is turned off or on) but do not how to do that

when the sender gets the acknowledgement from the receiver it can blink a LED - use millis() to time the blinking so you don't block execution of the code (as happens with delay())

could you add that your idea to the code i published above so i can upload and try?

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