Wireless Control With Lora

4,297

44

6

Introduction: Wireless Control With Lora

LoRa is a wireless technology widely used in the Internet of things, Compare to WiFi, LoRa has longer communication distance, more than 2km, and lower power, while compares with normal RF, Lora has longer distance& much higher communication data speed.

In addition, LoRa supports more nodes in the communication, that multiple transmitters& receivers could be implemented in the Lora network.

In this tutorial, I will make a simple LoRa wireless communication, based on Makerfabs Maduino Lora and LoRa Relay module.

Step 1: How to Do

There we will make a simple LoRa wireless controller and LoRa Relay, to remote control the LEDs& Fans ON/OFF.

The transmitter part is responsible for sending the control signal, that broadcast messages through the LoRa module. The receiver part is responsible for receiving messages and controlling relays, and thus to control the connected Leds& Fans On/Off.

Step 2: Preparation

I used the Maduino Lora module as the transmitter. Maduino LoRa is a board developed for Arduino &LoRa usage, it is based the Atmega328P and the LoRa module SX1278, that I can program it with Arduino IDE and Makerfabs provided libraries, to implement Lora functions into my project easily.

I used the 4-Channel Lora Relay-10A board as the receiver. Besides Atmega328P and the LoRa module SX1278, the 4-Channel Lora Relay-10A board integrates four relays, that could be used to control the connected modules On/Off directly.

All the LoRa modules’ frequency I use are 433MHz because 433MHz band is available in my country. You have to pay attention to the selection of the Lora module’s frequency, and make sure the frequency band is available locally.

The hardware:

  1. Maduino Lora
  2. 4-Channel Lora Relay-10A
  3. Battery
  4. 4 Buttons
  5. Breadboard
  6. Jumper Wires
  7. RGB LED

Step 3: ​Connection

As the picture shows, connect one pin of the 4 buttons to Maduino Lora IO ports(such as A0, A1, A2, A3 ), and another pin to the GND. In the Maduino, we set the IOs as Pull-up status, so if any of the buttons be pressed, the Maduino LoRa will detect it as a signal Low.

The relay is already integrated on the board and needs to be connected to the Leds or fan circuit. As the figure shows, the ‘NO’ pin of the relay is connected to the LED and the ‘COM’ pin is connected to the battery.

Step 4: Firmware

Lora is a broadcast network, there is no specific point-to-point transmission function. As long as the transmitter module sent the message, all receivers that detect the signal will receive a message. In order to control accurately, the transmitter has to send the given message that the receiver can recognize and drive the expected relay. For example, the LoRa transmitter sends "RELAY01", and the receiver will receive and recognize it to drive the relay 1 action.

1. Install the RadioLib library on the Arduino IDE.

2. The firmware can be obtained from here: https://github.com/Makerfabs/Lora-Relay-4Channel/...

3. In the transmitter firmware. Define the button pins and set them to pull-up input mode.

#define R1 A0
#define R2 A1
#define R3 A2
#define R4 A3
pinMode(R1,INPUT_PULLUP);
pinMode(R2,INPUT_PULLUP);
pinMode(R3,INPUT_PULLUP);
pinMode(R4,INPUT_PULLUP);

When any of button been pressed, the transmitter sends the message:

    int S1 = digitalRead(R1);
    int S2 = digitalRead(R2);
    int S3 = digitalRead(R3);
    int S4 = digitalRead(R4);
    int transtatus = 0;
    String str = "";
    if (S1 == 0)
    {
        str = "RELAY01";
        transtatus = 1;
		delay(50);
	}
int state = radio.transmit(str);

        if (state == ERR_NONE)
        {
        // the packet was successfully transmitted
            Serial.println(F(" success!"));
        // print measured data rate
            Serial.print(F("[SX1278] Datarate:\t"));
            Serial.print(radio.getDataRate());
            Serial.println(F(" bps"));
        }

4. In the receiver side, The LoRa module receives messages.

if (receivedFlag)
  {
    enableInterrupt = false;
    receivedFlag = false;
    String str;
int state = radio.readData(str);
    if (state == ERR_NONE) {
      // packet was successfully received
      Serial.println(F("[SX1278] Received packet!"));
      Serial.println(str);

And drive the related relay to act, as receiving the message such as “RELAY01”.

   if (str.indexOf("RELAY01") != -1)  
      {
        RS1 = !RS1;
        switch (RS1) {
        case LOW: {digitalWrite(RELAY1,LOW); } break;
        case HIGH: {digitalWrite(RELAY1,HIGH);} break;
		default: break;
        }

5. Upload the firmware “LoRa_Maduino_transmitter/LoRa_Maduino_transmitter.ino” to the Maduino LoRa board.

6. Upload the firmware “LoRa_Maduino_receiver/LoRa_Maduino_receiver.ino” to the 4-Channel Lora Relay-10A.

Step 5: Test

I use three relays to control an RGB LED. The color of the LED changes when different relays are switched on or off. As the picture shows, the green light near the relay on the board indicates the status of the relay.

Step 6: Finally

The simple wireless controller could be used for remote control beyond WiFi’s coverage. Of course, It could be used for data/ message communication. Besides, LoRa is a broadcast network, not a point-to-point network. It means that multiple LoRa receiver nodes can be remotely controlled within the LoRa range of the transmitter, which could be widely used in applications such as farm/ pasture.

If you have any suggestions, please leave a message, or contact me: gray@makerfabs.com.

Anything Goes Contest

Participated in the
Anything Goes Contest

Be the First to Share

    Recommendations

    • Tinkercad to Fusion 360 Challenge

      Tinkercad to Fusion 360 Challenge
    • Woodworking Contest

      Woodworking Contest
    • Origami Speed Challenge

      Origami Speed Challenge

    6 Comments

    0
    Babuprakash
    Babuprakash

    Question 9 months ago

    Can you please upload code so it works momentarily. That’s on when pressed, off when released.

    0
    kevlace81
    kevlace81

    Question 1 year ago

    Good Day. This looks like the exact thing that I need, but I have to ask one question first. Are the buttons you used momentary or latching? I am looking to use this with a float switch, so it is either high or low for long periods of time. The video looks like it is latching, but I would just like to check. Thanks very much

    0
    Lan_Makerfabs
    Lan_Makerfabs

    Answer 11 months ago

    I so sorry for replying too late.

    0
    Lan_Makerfabs
    Lan_Makerfabs

    Answer 11 months ago

    Not latching

    0
    langtupt
    langtupt

    Question 1 year ago

    Hello Bro,
    I very like to your project and can you add in code 4 led feedback in transmitter module?
    i would like sure it's relay control on receiver module working after press button 1,2,3,4 in transmitter module.
    Thank you very much and have a good day

    0
    Lan_Makerfabs
    Lan_Makerfabs

    Answer 1 year ago

    You can reference the transmitter code to add the code sent feedback message in the receiver :

    int state = radio.transmit(str);

    Add the received code in the transmitter:
    if (receivedFlag)

    {
    enableInterrupt = false;

    receivedFlag = false;

    String str;

    int state = radio.readData(str);