Doorbell sender with 10 kOhm pulldown

This commit is contained in:
2020-11-17 12:39:47 +01:00
parent 58803871be
commit 4b333a367d
@@ -1,37 +1,49 @@
int ledPin = LED_BUILTIN;
int buttonPin = 2; // Button connected to D2 and GND
int flare_threshold = 20;
/*
* https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button
*
* D2 -------------
* | |
* Button |
* | |
* +5V ----- |
* 10kOhm
* |
* GND -------------
*/
const int ledPin = LED_BUILTIN;
const int buttonPin = 2; // Button connected to D2
const int flare_threshold = 20;
bool active = false;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
Serial.println("Starting doorbell sensor");
Serial.println("Doorbell sensor");
}
void loop() {
int val = digitalRead(buttonPin);
if (val == LOW) {
if (val == HIGH) {
delay(flare_threshold); // catch flares
val = digitalRead(buttonPin);
if (val == LOW && active == false) {
if (val == HIGH && active == false) {
Serial.println("RING");
digitalWrite(ledPin, HIGH);
active = true;
delay(250);
}
else if (val == HIGH) {
else if (val == LOW) {
Serial.print("flare (<");
Serial.print(flare_threshold);
Serial.println(")");
}
}
else {
active = false;
} else {
digitalWrite(ledPin, LOW);
active = false;
}
}