Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // EMPFÄNGER
- #include <LoRa.h>
- #include <SPI.h>
- #define ss 5
- #define rst 14
- #define dio0 4
- #define ledPin 2 // On-board LED pin. Change if different for your board.
- void setup() {
- pinMode(ledPin, OUTPUT); // Set the LED pin as an output
- digitalWrite(ledPin, LOW); // Ensure LED is off
- delay(1000);
- Serial.begin(115200);
- while (!Serial);
- delay(1000);
- Serial.println("LoRa Receiver");
- LoRa.setPins(ss, rst, dio0); // Setup LoRa transceiver module
- LoRa.setSyncWord(0xab);
- LoRa.setSpreadingFactor(7);
- LoRa.setSignalBandwidth(125E3);
- LoRa.setCodingRate4(5);
- LoRa.setTxPower(14);
- while (!LoRa.begin(433E6)) { // Initialize LoRa at 433 MHz
- Serial.println(".");
- delay(500);
- }
- Serial.println("LoRa Initializing OK!");
- }
- void loop() {
- int packetSize = LoRa.parsePacket(); // Try to parse packet
- if (packetSize) {
- Serial.print("Received packet '");
- String LoRaData = "";
- while (LoRa.available()) { // Read packet
- LoRaData += (char)LoRa.read();
- }
- Serial.print(LoRaData);
- Serial.print("' with RSSI ");
- Serial.println(LoRa.packetRssi());
- // Check if the received message is "Hello, LoRa!"
- if (LoRaData == "Hello, LoRa!") {
- // Blink the LED
- digitalWrite(ledPin, HIGH); // Turn on LED
- delay(500); // Wait for 500 milliseconds
- digitalWrite(ledPin, LOW); // Turn off LED
- }
- }
- }
- // ----------------------------------------------------------------------
- // SENDER
- #include <SPI.h>
- #include <LoRa.h>
- // Define the LoRa module pins
- #define ss 5
- #define rst 14
- #define dio0 4
- void setup() {
- Serial.begin(115200);
- while (!Serial);
- Serial.println("LoRa Sender Test");
- // Setup LoRa transceiver module
- LoRa.setSyncWord(0xab); // LoRa Sync Word
- LoRa.setSpreadingFactor(7); // Spreading Factor: Ranges from 6 to 12 (default is 7)
- LoRa.setSignalBandwidth(125E3); // Bandwidth: Lower bandwidth (125 kHz)
- LoRa.setCodingRate4(5); // Coding Rate: 4/5 for some added robustness
- LoRa.setTxPower(14);
- LoRa.setPins(SS, RST, DI0);
- if (!LoRa.begin(433E6)) {
- Serial.println("Starting LoRa failed!");
- while (1);
- }
- }
- void loop() {
- Serial.println("Sending packet: Hello, LoRa!");
- // Send packet
- LoRa.beginPacket();
- LoRa.print("Hello, LoRa!");
- LoRa.endPacket();
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment