Merge branch 'pirsensor' of https://github.com/htcheroportugal/meshtastic into pr/738

This commit is contained in:
rcarteraz 2023-07-19 15:27:53 -07:00
commit f834833bb8

View file

@ -253,7 +253,7 @@ while True:
#### Arduino Mini Pro Wiring #### Arduino Mini Pro Wiring
![image](/img/modules/Serial/arduino-mini-pro-pir-wiring.png) ![image](https://i.ibb.co/g3ZffzT/pir.png)
- T-BEAM RX PIN 13 to TX PIN on the ARDUINO MINI - T-BEAM RX PIN 13 to TX PIN on the ARDUINO MINI
- T-BEAM TX PIN 14 to RX PINon the ARDUINO MINI - T-BEAM TX PIN 14 to RX PINon the ARDUINO MINI
@ -265,26 +265,32 @@ while True:
#### Arduino Mini Pro Code #### Arduino Mini Pro Code
```c++ ```cpp
int LED = 13; // the pin that the LED is atteched to int LED = 13; // the pin to which the LED is connected
int PIR = 2; // the pin that the sensor is atteched to int PIR = 2; // the pin to which the sensor is connected
int previousState = LOW; // previous state of the sensor
void setup() { void setup() {
pinMode(LED, OUTPUT); // initialize LED as an output pinMode(LED, OUTPUT); // initialize the LED as an output
pinMode(PIR, INPUT); // initialize sensor as an input pinMode(PIR, INPUT); // initialize the sensor as an input
Serial.begin(9600); // initialize serial Serial.begin(9600); // initialize serial communication
} }
void loop(){ void loop(){
if (digitalRead(PIR) == HIGH) { // check if the sensor is HIGH int currentState = digitalRead(PIR); // read the current state of the sensor
digitalWrite(LED, HIGH); // turn LED ON if (currentState != previousState) { // check if the state has changed
Serial.write(":Motion!:"); if (currentState == HIGH) { // check if there is motion
delay(10000); // delay 100 milliseconds digitalWrite(LED, HIGH); // turn the LED on
} Serial.println("Motion Detected");
else { }
digitalWrite(LED, LOW); // turn LED OFF else {
Serial.write("Motion stopped!"); digitalWrite(LED, LOW); // turn the LED off
delay(10000); // delay 100 milliseconds Serial.println("No Motion");
}
previousState = currentState; // update the previous state
} }
delay(100); // small delay to avoid false sensor readings
} }
``` ```