I used a car window motor and actuator with a Arduino to make a automatically closing screen door. It will help keep the flies out of your house.
Code is below:
unsigned long wait = 10000;
unsigned long doorOpen =0;
void setup() {
pinMode(2, INPUT_PULLUP);// SWITCH
pinMode(7, OUTPUT);// relay
Serial.begin(9600);
}
void loop() {
int sensorVal = digitalRead(2);
Serial.println (sensorVal);
if(sensorVal ==1 && doorOpen==0)
{ doorOpen =millis();
}
if(sensorVal ==1 && doorOpen greater then 0)
{
unsigned long difference= millis()-doorOpen;
if(difference greater then = wait)
{digitalWrite(7,HIGH);
Serial.println ("working");
}
}
else{
digitalWrite(7,LOW);
doorOpen =0;
}
}
Ещё видео!