PROJECT LORA
Pada project kali ini akan mengirim data menggunakan LoRa. Sebelum membuat project ini siapkan alat-alat yang diperlukan sebagai berikut:
- 2 ESP32
- LoRa Transmitter Tranceiver module
- 8 Kabel Jumper Female-female
Selanjutnya rangkai rangkaian seperti pada gambar dibawah ini:
Setelah terhubung dengan baik sesuai dengan gambar, buka aplikasi Arduino IDE. Apabila belum pernah menginstall dan mengupload program menggunakan Arduino IDE bisa pelajari terlebih dahulu dalam postingan sebelumnya disini.
sebelum memulai pastikan install library LoRa terlebih dahulu. Buka aplikasi Arduino IDE, keudian klik Sketch>>Include Library>>Manage Library>>Manage Libraries kemudian cari LoRa, Pilih LoRa Library kemudian klik install. Tunggu hingga proses selesai.
Selanjutnya meng-upload program ke Board ESP32. Berikut ini merupakan program yang digunakan ESP32 untuk mengatur LoRa sebagai pengirim data:
.
.
.
/*********
Modified from the examples of the Arduino LoRa library
More resources: https://randomnerdtutorials.com
*********/
#include <SPI.h>
#include <LoRa.h>
//define the pins used by the transceiver module
#define ss 5
#define rst 14
#define dio0 2
int counter = 0;
void setup() {
//initialize Serial Monitor
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Sender");
//setup LoRa transceiver module
LoRa.setPins(ss, rst, dio0);
//replace the LoRa.begin(---E-) argument with your location's frequency
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
while (!LoRa.begin(866E6)) {
Serial.println(".");
delay(500);
}
// Change sync word (0xF3) to match the receiver
// The sync word assures you don't get LoRa messages from other LoRa transceivers
// ranges from 0-0xFF
LoRa.setSyncWord(0xF3);
Serial.println("LoRa Initializing OK!");
}
void loop() {
Serial.print("Sending packet: ");
Serial.println(counter);
//Send LoRa packet to receiver
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
delay(10000);
}
Modified from the examples of the Arduino LoRa library
More resources: https://randomnerdtutorials.com
*********/
#include <SPI.h>
#include <LoRa.h>
//define the pins used by the transceiver module
#define ss 5
#define rst 14
#define dio0 2
int counter = 0;
void setup() {
//initialize Serial Monitor
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Sender");
//setup LoRa transceiver module
LoRa.setPins(ss, rst, dio0);
//replace the LoRa.begin(---E-) argument with your location's frequency
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
while (!LoRa.begin(866E6)) {
Serial.println(".");
delay(500);
}
// Change sync word (0xF3) to match the receiver
// The sync word assures you don't get LoRa messages from other LoRa transceivers
// ranges from 0-0xFF
LoRa.setSyncWord(0xF3);
Serial.println("LoRa Initializing OK!");
}
void loop() {
Serial.print("Sending packet: ");
Serial.println(counter);
//Send LoRa packet to receiver
LoRa.beginPacket();
LoRa.print("hello ");
LoRa.print(counter);
LoRa.endPacket();
counter++;
delay(10000);
}
Selanjutnya meng-upload program ke Board ESP32. Berikut ini merupakan program yang digunakan ESP32 untuk mengatur LoRa sebagai penerima data:
.
.
.
/*********
Modified from the examples of the Arduino LoRa library
More resources: https://randomnerdtutorials.com
*********/
#include <SPI.h>
#include <LoRa.h>
//define the pins used by the transceiver module
#define ss 5
#define rst 14
#define dio0 2
void setup() {
//initialize Serial Monitor
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Receiver");
//setup LoRa transceiver module
LoRa.setPins(ss, rst, dio0);
//replace the LoRa.begin(---E-) argument with your location's frequency
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
while (!LoRa.begin(866E6)) {
Serial.println(".");
delay(500);
}
// Change sync word (0xF3) to match the receiver
// The sync word assures you don't get LoRa messages from other LoRa transceivers
// ranges from 0-0xFF
LoRa.setSyncWord(0xF3);
Serial.println("LoRa Initializing OK!");
}
void loop() {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet '");
// read packet
while (LoRa.available()) {
String LoRaData = LoRa.readString();
Serial.print(LoRaData);
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
}
Modified from the examples of the Arduino LoRa library
More resources: https://randomnerdtutorials.com
*********/
#include <SPI.h>
#include <LoRa.h>
//define the pins used by the transceiver module
#define ss 5
#define rst 14
#define dio0 2
void setup() {
//initialize Serial Monitor
Serial.begin(115200);
while (!Serial);
Serial.println("LoRa Receiver");
//setup LoRa transceiver module
LoRa.setPins(ss, rst, dio0);
//replace the LoRa.begin(---E-) argument with your location's frequency
//433E6 for Asia
//866E6 for Europe
//915E6 for North America
while (!LoRa.begin(866E6)) {
Serial.println(".");
delay(500);
}
// Change sync word (0xF3) to match the receiver
// The sync word assures you don't get LoRa messages from other LoRa transceivers
// ranges from 0-0xFF
LoRa.setSyncWord(0xF3);
Serial.println("LoRa Initializing OK!");
}
void loop() {
// try to parse packet
int packetSize = LoRa.parsePacket();
if (packetSize) {
// received a packet
Serial.print("Received packet '");
// read packet
while (LoRa.available()) {
String LoRaData = LoRa.readString();
Serial.print(LoRaData);
}
// print RSSI of packet
Serial.print("' with RSSI ");
Serial.println(LoRa.packetRssi());
}
}
Pada program tersebut transmitter akan mengirim data "hello (0-seterusnya (counter up))". Apabila sudah selesai upload dapat dilihat pada serial monitor ESP32 sebagai pengirim data akan muncul sending packet 0 dan seterusnya sesuai dengan program yang dibuat megnirim data counter up. dan serial monitor ESP32 sebagai penerima data akan muncul Receive Packet "hello 0" dan seterusnya sesuai data yang dikirim berupa data counter up dari pengirim.
Untuk lebih jelasnya dapat lihat video nya disini.
No comments:
Post a Comment