Lora

Hi Guys,

I am setting up to Dragino LoRa mini Dev boards (I believe they are based on UNO) to talk to each other

I have got everything working except for turning off a relay. I have the sketch setup to turn on a relay (via pin A0) when it receives LoRa data.

I would like it to turn the relay off again, when it stops receiving LoRa data, but I don't want it do continuosly cycle the relay.

The code I have at the moment, will turn the relay on, but not off.

Any thoughts on where I went wrong, or a better approach?

Thanks
Dave

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

const int RelayPin =  A0;      // the number of the Relay pin
int count = 0;

void setup() {

 pinMode(RelayPin, OUTPUT);
  digitalWrite(RelayPin, LOW); 

  Serial.begin(9600);
  while (!Serial);

  Serial.println("LoRa Receiver");

  if (!LoRa.begin(433E6)) {
    Serial.println("Starting LoRa failed!");
    while (1);
  }
}

void loop() {
  count = 0;
  LoRa.setSpreadingFactor(10);           // ranges from 6-12,default 7 see API docs - perhaps use a jumper pin to set this
    LoRa.setSyncWord(0x23);           // ranges from 0-0xFF, default 0x34, see API docs
   LoRa.setTxPower(20);      // Supported values are `2` to `20` for `PA_OUTPUT_PA_BOOST_PIN`, and `0` to `14` for `PA_OUTPUT_RFO_PIN`.  Most modules have the PA output pin connected to PA BOOST,
   //  LoRa.setSignalBandwidth(62.5E3);    //  * `signalBandwidth` - signal bandwidth in Hz, defaults to `125E3`.  Supported values are `7.8E3`, `10.4E3`, `15.6E3`, `20.8E3`, `31.25E3`, `41.7E3`, `62.5E3`, `125E3`, and `250E3`.// try to parse packet
   LoRa.setCodingRate4(5); //- `codingRateDenominator` - denominator of the coding rate, defaults to `5`Supported values are between `5` and `8`, these correspond to coding rates of `4/5` and `4/8`. The coding rate numerator is fixed at `4`.
  int packetSize = LoRa.parsePacket();
  if (packetSize) {
    // received a packet
    Serial.print("Received packet '");

    // read packet
    while (LoRa.available()) {
      Serial.print((char)LoRa.read());
    }

    // print RSSI of packet
    Serial.print("' with RSSI ");
    Serial.println(LoRa.packetRssi());
    Serial.print(" and SNR ");
    Serial.println(LoRa.packetSnr());
   // print SNR of packet
   digitalWrite(RelayPin, HIGH);
   delay(25);
  }  else {

    count++;
    if (count > 100){
    Serial.println(count);
    // We need to write pin low, but need some sort of a delay to stop relay switching on and off
       digitalWrite(RelayPin, LOW); 
    }
}
}

The approach you have taken could be improved .............

First, dont adjust the syncword away from the defaults unless you have a full understanding of the implications, the 'wrong' values can cause a loss in receive sensitivity. Some combinations are transparrent too, you will receive packets with a different syncword.

Second every time a LoRa packet is received you turn the relay on\off, this makes the setup very prone to false triggering from noise (phantom packets) or geniune LoRa packets from other sources.

There is a 4 channel remote control program here (21_On_Off_Transmitter and 22_On_Off_Receiver);

Where the LoRa packet recieved needs to match on;

The first byte of the packet.
A 32 bit identity number in the packet.
Be the correct length (6bytes).

If there is no match no action is taken, the chances of a false trigger are fairly remote.

The transmitter program (with the 4 switches) when used with a bare bones Arduino has a sleep current of around 2uA.

Thanks for that.

I am brand new to Arduino and LoRa, so trying to get my head around the best way to do things.

I am trying to setup 2 separate remote controls using LoRa. Basically, each transmitter has a single button. whilst the button is pressed, it needs to transmit a signal to tell the receiver to turn on a relay. When the button is released, the relay needs to turn off again.

I was attempting to use the syncword to differentiate between the 2 remotes, but as you pointed out, that is probably not the best way to go about things. Both transmitters need to be able to transmit at the same time without interfering with each other. Will the method you described work for that, or do I need to look at different bandwidths / spreading factors or modify the base frequency?

Thanks

Dave

htdave:
Both transmitters need to be able to transmit at the same time without interfering with each other. Will the method you described work for that, or do I need to look at different bandwidths / spreading factors or modify the base frequency?

Could have been appropriate to mention the 2 transmitter requirement in the original post ?

Perhaps describe the real project in more detail, are there for instance two receivers as well ?

srnet:
Could have been appropriate to mention the 2 transmitter requirement in the original post ?

Perhaps describe the real project in more detail, are there for instance two receivers as well ?

All up there will be 3 transmitters. transmitter 1 & 2 need to be able to transmit simultaneously, while transmitter 3 will only ever be used when transmitter 1 & 2 are turned off.

Transmitter 1 & 2 will each have 1 button. Whilst the button is pressed on transmitter 1, relay 1 (connected to the receiver) needs to be on. when the button is released on transmitter 1, relay 1 needs to turn off. The same for transmitter 2 and relay 2.

When the button is pressed on transmitter 3, relay 3 needs to change state. ie 1st press relay 3 turns on. 2nd press relay 3 turns off. 3rd press relay 3 turns on etc.

Transmitter 1 & 2 both need to be able to reliably transmit over 200m, preferably at least 400m in steep / rugged terrain without LOS. Transmitter 3 only needs to be able to transmit 5m.

All three transmitters need to be battery powered and able to fit comfortably in a pocket, so no external antennas, and minimal power consumption.

The receivers will be vehicle mounted, so ~1m long whip antennas will be fine and power consumption is not an issue.

Ideally I would like to have only 1 receiver, but if that is not possible, then 2 receivers would be fine.

There will be the rare occasion where 2 of these systems will be working near each other, so essentially need to prevent interference from 4 transmitters all transmitting at once, although this is not a very likely scenario, so a bit of interference would be acceptable.

We will be using 433MHz boards

It might be possible, if the packets are short and there are longish random delays between packets, to have 3 transmitters sending packets such that a single receiver has a reasonable chance of picking up all 3 transmitters.

But that would depend on how short the pacekts were, and since shorter (in time) packets mean less range, that would depend on the environmement, so you would need to do a site test.

3 transmitters with and 3 seperate receivers would be easier to implement, just use seperate frequencies.