In the previous article, we discussed Basic how to sending and receiving data on wireless communication using 433MHz Lora Ra-02 and Arduino Uno. So in this discussion, will be developed by adding switches and LEDs. The working principle in this debate, ie when the switch in circuit 1 (transmitter) is pressed, arduino will send a message to circuit 2 (receiver) via Lora radio communication. In circuit 2 when there is incoming data from circuit 1 which is then captured by Lora module in circuit 2 then go into Arduino and continued LED will light up then off. For more details like in the following block diagram picture:
Electronic component materials are used as follows.
- Arduino Uno: 2 pieces.
- 433MHz Lora radio RA-02: 2 pieces.
- Switch: 1 piece.
- LED: 1 piece.
- Resistor: 2 pieces.
- Project Board: 2 pieces.
The circuit diagram 433MHz Lora Ra-02 Arduino.
For the first circuit or data sender, there are some electronic components, such as 433MHz Lora radio RA-02, Arduino, switches, and resistors. Schematic wiring diagram as follows.
For second circuit or data receiver, there are some electronic components, such as 433MHz Lora radio RA-02, Arduino, LED and resistor. Schematic wiring diagram as follows.
Arduino Code for transmitter and receiver.
When the switch in circuit 1 is pressed then the switch will send a high logic signal to arduino, then arduino will send a text message through lora module and sent to circuit 2. In circuit 2 lora radio ra-02 take data from circuit 1 and then processed by arduino then turn on led then lapse 1 second killed.
In this experiment, there are two scenarios for text messages sent from series 1 to series 2. It is the first one-letter text format, the second one with the text format with one sentence.
The first scenario, when the switch is pressed then arduino in circuit 1 sending packet “1” in 1 letter text format, here is arduino code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <SPI.h> #include <LoRa.h> int btn = 3; void setup() { Serial.begin(9600); while (!Serial); Serial.println("LoRa Sender"); if (!LoRa.begin(433E6)) { Serial.println("Starting LoRa failed!"); while (1); } LoRa.setSpreadingFactor(10); LoRa.setSignalBandwidth(62.5E3); LoRa.crc(); pinMode(btn, INPUT); Serial.println("Push the button switch for send packet"); } void loop() { int data = digitalRead(btn); if (data == HIGH){ Serial.println("Send packet"); // send packet LoRa.beginPacket(); LoRa.print("1"); LoRa.endPacket(); } delay(500); } |
Here is the display result transmitter code on the serial monitor arduino IDE when circuit 1 sending packet data to circuit 2.
In circuit 2 it serves to received packet data message “1” from circuit 1. The following is the arduino code in the receiver circuit (circuit 2).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #include <SPI.h> #include <LoRa.h> int led = 3; void setup() { Serial.begin(9600); while (!Serial); Serial.println("Lora Receiver"); if (!LoRa.begin(433E6)) { Serial.println("Lora Error"); while (1); } LoRa.setSpreadingFactor(10); LoRa.setSignalBandwidth(62.5E3); LoRa.crc(); pinMode(led, OUTPUT); } void loop() { // try to parse packet int packetSize = LoRa.parsePacket(); if (packetSize) { // received a packet Serial.print("received a packet : "); // read packet while (LoRa.available()) { char data = LoRa.read(); Serial.print(data); if (data == '1'){ digitalWrite(led, HIGH); delay(500); digitalWrite(led, LOW); delay(500); } //Serial.print((char)LoRa.read()); } Serial.println(" "); } } |
Display results receiver code on the serial monitor arduino IDE, which in series 2 is as follows.
In the second scenario of data sent by series 1 in the form of long text or 1 sentence, in this experiment, the text message is “switch”. The arduino code for the sending packet (circuit 1) is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <SPI.h> #include <LoRa.h> int btn = 3; void setup() { Serial.begin(9600); while (!Serial); Serial.println("LoRa Sender"); if (!LoRa.begin(433E6)) { Serial.println("Starting LoRa failed!"); while (1); } LoRa.setSpreadingFactor(10); LoRa.setSignalBandwidth(62.5E3); LoRa.crc(); pinMode(btn, INPUT); Serial.println("Push the button switch for send packet"); } void loop() { int data = digitalRead(btn); if (data == HIGH){ Serial.println("Send packet"); // send packet LoRa.beginPacket(); LoRa.print("switch,"); LoRa.endPacket(); } delay(500); } |
The arduino code for the receiver circuit (circuit 2), when receiving the message data “switch” is as follows.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | #include <SPI.h> #include <LoRa.h> int led = 3; String readString; char data = 0; void setup() { Serial.begin(9600); while (!Serial); Serial.println("Lora Receiver"); if (!LoRa.begin(433E6)) { Serial.println("Lora Error"); while (1); } LoRa.setSpreadingFactor(10); LoRa.setSignalBandwidth(62.5E3); LoRa.crc(); pinMode(led, OUTPUT); } void loop() { int packetSize = LoRa.parsePacket(); if (packetSize) { // received a packet Serial.print("received a packet : "); // read packet while (LoRa.available()) { data = LoRa.read(); if (data == ',') { if (readString.length() > 1) { Serial.print(readString); //prints string to serial port out Serial.println(' '); //prints delimiting "," digitalWrite(led, HIGH); // LED ON delay(500); digitalWrite(led, LOW); // LED OFF delay(500); //do stuff with the captured readString readString=""; //clears variable for new input } } else { readString += data; //makes the string readString } } } } |
The display results receiver code in the serial monitor arduino IDE in the receiving packet are as follows.
The results of the experimental video are as follows.
Kumar.A
Starting Lora module is failed it is displaying on the serial monitor
Irone Chank
Hello kumar. if you have an error on the serial monitor, there may be an error for pinout the arduino installation. try to be checked again. thanks …
Kumar.A
hi,
Are these Lora module has any settings that needed to be followed, intially,I think the transmitter and receivers are not matching, is there any configuaration that need to be done in the code. thanks.
Irone Chank
Hi .. In principle to use the lora module does not require special setting, only that needs to be done is the placement of pin connections lora correct position on arduino.
if you open library lora (LoRa.h) for pinout position placement you must connect is as follows.
/ * For lora connection ra-02 with Arduino Uno and arduino nano * /
#define LORA_DEFAULT_SS_PIN 10
#define LORA_DEFAULT_RESET_PIN 9
#define LORA_DEFAULT_DIO0_PIN 8
One more thing to initialize for the frequency of the Lora you are using.
If you use lora with 433MHz frequency then setting like below.
if (! LoRa.begin (433E6)) {
Serial.println (“Lora Error”);
while (1);
}
If you use lora with 915MHz frequency then setting like below.
if (! LoRa.begin (915E6)) {
Serial.println (“Starting LoRa failed!”);
while (1);
}
Kumar.A
thanks for the reply, the problem persists like the lora starting is failed,
As you said above the DIO pin you mentioned in the diagram above is to be connected to D2 pin of Arduino, but you mentioned above in the recent reply that it to be connected to D8 pn of Arduino which one to follow…?
mosab mahmod nairoukh
I TEST IT ANT ITS WORKING 100%