Project Objective:
- A device to monitor garage door's status. If the door remains open for too long (for example, people forget to close it). It will close the door by itself. Some false positive and negative should be consider to software design to reduce the potential risk by using this device.
Feature:
- Monitor the garage door is opened or closed
- If the door is open more then 540 second (9 min), it sounds slow reminder alarm.
- If the door remain in opened in 600 second (10 min), it will sound rapid door closing alarm
- After the door switch is triggered,
- it will check the status of the door in 23 second.
- 23 second is the door close and re-open cycle time if something/someone prevent the door from closing.
- If the door is still closed, it will back to normal monitor cycle.
- If the door is still opened, it will attempt to close it again, and then stay in the infinity loop with error reminder (blanking LED and chipping)
- Risk assessment, What if:
- FP: it will attempt to close the door twice. It will end up just open and close the door.
- FN: it will do nothing.
- The overall risk is low for using this device.
- It communicates to user with simple Morse code, such as "Hi" after initialized, or "D" after closing the garage door.
Component List:
- 1x Arduino Nano
- 1x HC-SR04
- 1x PC817 (or equivalent)
- 1x A-1557 (or equivalent)
- 1x Red LED
- 1x Green LED
- 1x 5V Buzzer
- 1x 10K ohm resistor
- 1x 170 ohm LED resistor, (or any similar resistor)
- 1x 440 ohm LED resistor, (or any similar resistor)
- 1x 110 ohm PC817 resistor, (or any similar resistor)
- 5V power supply
- 1x power switch (for power supply)
- 1x power switch or jumper (for mode selection)
- 2x quick connector
- Wires
- Project enclosure box
Schematic:
It is a simple schematic (please excuse my chicken scratch...) |
Breadboarding. It is for example only, a bit difference from schematic. When you build it, please only reference to schematic |
Assembly and integration. Add a power switch. |
Quick Connection for power and door switch |
Installed on top of garage door. |
It does NOT detecting door id open. |
It detects the garage door is open (the red LED is ON) |
Demo 1 (Normal operation. User just forget to close the garage door.)
Demo 2 (None standard operation. For example, someone or some thing prevent the door from closing)
Arduino Code:
/* Automatic Garage Door Closer Project*
* Author: Samson Yang
* Date: 3/20/2017
*
* Feature:
* 1. Monitor the garage door is opened or closed
* 2. If the door is open more then 540 second (9min), it sounds slow reminder alarm.
* 3. If the door remain in opened in 600 second (10 min), it will sound rapid door closing alarm
* 4. After the door switch is trigered,
* a. it will check the status of the door in 23 second.
* b. 23 second is the door close and re-open cycle time if something/someone prevent the door from closing.
* 5. If the door is still closed, it will back to normal monitor cycle.
* 6. If the door is still opened, it will attemp to close it again, and then stay in the inifinity loop with error reminder (blanking LED and chipping)
* 7. Risk assesment, What if:
* a. FP: it will attemp to close the door twice. It will end up just open and close the door.
* b. FN: it will do nothing.
* c. The overall risk is low for using this device.
*
* Note:
* * FP(false positive, dooe is closed, but sensor say it is opened).
* * FN(false negative, door is opened, but sensor say it is closed).
*
* Pin Arrangement:
* D2 --> Garage door switch
* D4 --> Door status red LED
* D5 --> Test mode selection (with pull up)
* D7 --> US Trigger
* D8 --> US Echo
* D9 --> Buzzer
*
*
*/
#include <TimeLib.h>
bool buzer = 1;
int Pre_closing_alarm_time=540; //after 9 minutes sound reminder
int Closing_door_time=600; //after 10 minutes close door
int Closed_Door_Threshold=600;
int Time_check_door_is_closed=23000; //Wait 23 sec, if door cannot be closed, it can be detected after 23 seconds.
long int count=0;
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
pinMode(2, OUTPUT); //Door Control switch
pinMode(4, OUTPUT); //Door status indicator
pinMode(7, OUTPUT); //Triger pin
pinMode(9, OUTPUT); //Alarm pin
pinMode(8, INPUT); //Counting pin
pinMode(5, INPUT); //Test pin, 1: testing, 0:Normal
digitalWrite(2, LOW);
digitalWrite(4, LOW);
digitalWrite(7, LOW);
digitalWrite(9, LOW);
//Test mode when pin 5 is high
if(digitalRead(5)){
Pre_closing_alarm_time=3;
Closing_door_time=7;
Time_check_door_is_closed=10000;
}
say_hi();
}
int door_open_time=0;
void loop() {
int time_gap=0;
//count=0;
bool door_status = check_door();
//Check how much time the door has been opened
time_gap=now()-door_open_time;
//Door is opened
if (door_status) {
digitalWrite(4, HIGH); //Turn on door status indicator LED
if (time_gap>Pre_closing_alarm_time){
digitalWrite(9, buzer);
buzer=!buzer;
}
}
else {
//Door is closed
digitalWrite(4, LOW); //Turn off door status indicator LED
door_open_time=now();
digitalWrite(9, LOW); //Turn off buzer
}
//Check is it time to close the door
if (time_gap>Closing_door_time){
close_door();
door_open_time=now();
}
//Send message out
Serial.print("");Serial.print(" ");
Serial.print(now());Serial.print(" ");Serial.println(door_open_time);
//Max frequency is 10Hz, or use 100 or higher value
delay(500);
}
void close_door(){
int i;
buzer = 1;
for (i = 1;i<50;i++){
digitalWrite(9, buzer);
buzer=!buzer;
delay(50);
}
digitalWrite(9, LOW);//Turn off buzer
//Close garage door
digitalWrite(2, HIGH);
delay(1000);
digitalWrite(2, LOW);
delay(Time_check_door_is_closed);
if (!check_door()) say_done();
else {
//Something wrong, and show slow blanking door status LED.
//Try close and the door 2nd times
//It should mitigate FP (false positive). Its means door is closed, but sensor think it is opened issue.
//If there is FP, the second dooe closing activity, will close the door when the first FP open the door.
buzer = 1;
for (i = 1;i<100;i++){
digitalWrite(9, buzer);
buzer=!buzer;
delay(100);
}
digitalWrite(9, LOW);//Turn off buzer
//Close garage door
digitalWrite(2, HIGH);
delay(1000);
digitalWrite(2, LOW);
//Infinity loop and show blanking door status LED.
while (1){
digitalWrite(4, HIGH);
delay(200);S();
digitalWrite(4, LOW);
delay(3000);
}
}
}
bool check_door(){
//if Closed return 0
//if Opened return 1
long int count_in=0;
//Triger the signal
digitalWrite(7, HIGH);
digitalWrite(7, LOW);
//Wait ultra sound echo
while (!digitalRead(8));
//Measure the distance
while (digitalRead(8)){count_in++;}
if (count_in<Closed_Door_Threshold)
{return 1;}
else
{return 0;}
}
void say_done(){
//Say mose code D (it means done)
L();S();S();
}
void say_hi(){
S();S();S();S();_();S();S();
}
void L(){
digitalWrite(9, HIGH);
delay(300);
digitalWrite(9, LOW);
delay(50);
}
void S(){
digitalWrite(9, HIGH);
delay(100);
digitalWrite(9, LOW);
delay(50);
}
void _(){
digitalWrite(9, LOW);
delay(300);
}
I love the way you write and share your niche! Very interesting and different! Keep it coming! Garage Door Service Tolleson AZ
ReplyDelete