#include <M5SX127x.h> // Use the M5-SX127x library
M5SX127x lora; // Create a LoRa object
#define MOTION_SENSOR 4 // PIR sensor connected to GPIO 4
void setup() {
Serial.begin(115200);
pinMode(MOTION_SENSOR, INPUT_PULLUP);
// Initialize LoRa on 433 MHz. Adjust frequency if needed.
if (!lora.begin(433E6)) {
Serial.println("LoRa init failed");
while (true); // Halt execution if initialization fails
}
Serial.println("LoRa init success");
}
void loop() {
int motion = digitalRead(MOTION_SENSOR);
lora.beginPacket();
if (motion == HIGH) {
lora.print("Motion detected");
} else {
lora.print("No motion detected");
}
lora.endPacket();
delay(1000); // Transmit every second
}