Created
October 19, 2023 20:45
-
-
Save TomyCesaille/ba15e88fb859e4b6b4bfe53a8dce0dfb to your computer and use it in GitHub Desktop.
Rain alarm - Proto 2 - Rain Sensor Transmitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LoRa.h> | |
#include <SPI.h> | |
#define ss 5 | |
#define rst 14 | |
#define dio0 4 | |
int SWITCH_PIN = 15; | |
int LED_PIN = 2; | |
struct Payload | |
{ | |
int rain; | |
}; | |
void setup() | |
{ | |
Serial.begin(115200); | |
while (!Serial) | |
; | |
Serial.println("Starting..."); | |
pinMode(SWITCH_PIN, INPUT_PULLUP); | |
pinMode(LED_PIN, OUTPUT); | |
Serial.println("LoRa Sender"); | |
LoRa.setPins(ss, rst, dio0); | |
while (!LoRa.begin(433E6)) | |
{ | |
Serial.println("."); | |
delay(500); | |
} | |
LoRa.setSyncWord(0x7E); | |
Serial.println("LoRa Initializing OK!"); | |
} | |
void loop() | |
{ | |
int switchState = digitalRead(SWITCH_PIN); | |
if (switchState == LOW) | |
{ | |
digitalWrite(LED_PIN, HIGH); | |
} | |
else | |
{ | |
digitalWrite(LED_PIN, LOW); | |
} | |
Payload data; | |
data.rain = switchState == LOW ? 1 : 0; | |
LoRa.beginPacket(); | |
LoRa.write((uint8_t *)&data, sizeof(Payload)); | |
LoRa.endPacket(); | |
Serial.print("."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment