Wireless Control With Lora
by Lan_Makerfabs in Circuits > Arduino
10624 Views, 54 Favorites, 0 Comments
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.
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.
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:
- Maduino Lora
- 4-Channel Lora Relay-10A
- Battery
- 4 Buttons
- Breadboard
- Jumper Wires
- RGB LED
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.
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.
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.
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.