Klingel-Sensor mit Arduino Nano und Python

This commit is contained in:
2020-08-26 21:22:35 +02:00
parent 78698d12bf
commit e8e1422119
2 changed files with 53 additions and 0 deletions
@@ -0,0 +1,35 @@
int ledPin = LED_BUILTIN;
int buttonPin = 2; // Button connected to D2 and GND
bool active = false;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
Serial.begin(9600);
Serial.println("Starting doorbell sensor");
}
void loop() {
int val = digitalRead(buttonPin);
if (val == LOW) {
delay(2); // catch flares
if (val == LOW && active == false) {
Serial.println("RING");
digitalWrite(ledPin, HIGH);
active = true;
delay(250);
}
else {
// Serial.println("flare");
}
}
else {
delay(2); // catch flares
if (val == HIGH) {
active = false;
digitalWrite(ledPin, LOW);
}
}
}