Doorbell sender with 10 kOhm pulldown
This commit is contained in:
@@ -1,37 +1,49 @@
|
|||||||
int ledPin = LED_BUILTIN;
|
/*
|
||||||
int buttonPin = 2; // Button connected to D2 and GND
|
* https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button
|
||||||
int flare_threshold = 20;
|
*
|
||||||
|
* 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;
|
bool active = false;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(ledPin, OUTPUT);
|
pinMode(ledPin, OUTPUT);
|
||||||
pinMode(buttonPin, INPUT_PULLUP);
|
pinMode(buttonPin, INPUT);
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("Starting doorbell sensor");
|
Serial.println("Doorbell sensor");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
int val = digitalRead(buttonPin);
|
int val = digitalRead(buttonPin);
|
||||||
|
|
||||||
if (val == LOW) {
|
if (val == HIGH) {
|
||||||
delay(flare_threshold); // catch flares
|
delay(flare_threshold); // catch flares
|
||||||
val = digitalRead(buttonPin);
|
val = digitalRead(buttonPin);
|
||||||
|
|
||||||
if (val == LOW && active == false) {
|
if (val == HIGH && active == false) {
|
||||||
Serial.println("RING");
|
Serial.println("RING");
|
||||||
digitalWrite(ledPin, HIGH);
|
digitalWrite(ledPin, HIGH);
|
||||||
active = true;
|
active = true;
|
||||||
delay(250);
|
delay(250);
|
||||||
}
|
}
|
||||||
else if (val == HIGH) {
|
else if (val == LOW) {
|
||||||
Serial.print("flare (<");
|
Serial.print("flare (<");
|
||||||
Serial.print(flare_threshold);
|
Serial.print(flare_threshold);
|
||||||
Serial.println(")");
|
Serial.println(")");
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
active = false;
|
|
||||||
digitalWrite(ledPin, LOW);
|
digitalWrite(ledPin, LOW);
|
||||||
|
active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user