Close
0%
0%

Arduino controlled door trigger light bulb

I always forget to turn off the light, no longer bother to turn the lights

Similar projects worth following
I always forget to turn off the light, no longer bother to turn the lights

When the door is opened the relay pulls,
If the door is closed wait 10 seconds and leave the role.

View all 9 components

  • 1
    Step 1

    Source code:

    int rolePin = 2; // pin that connects the relay 
    int magnetPin = 3; // pin that connects magnetic switches 
    int wait = 10000; // time to turn off light (in milliseconds) 
    boolean doorStatus = false;
    
    
    void setup() { 
    pinMode(rolePin, OUTPUT); 
    pinMode(magnetPin, INPUT_PULLUP); 
    
    
    } 
    
    
    void loop() { 
    int magnetState = digitalRead(magnetPin); 
    
    
    if (magnetState == HIGH) { 
    digitalWrite(rolePin, HIGH);  
    doorStatus = true;
    } 
    else{ 
      if (doorStatus == true) {
    delay(wait);
    digitalWrite(rolePin, LOW); 
    doorStatus = false;
     }
    } 
    delay(5);
    }

View all instructions

Enjoy this project?

Share

Discussions

Similar Projects

131
35
3
Project Owner Contributor

Simulation

sophi--esophi--e

Does this project spark your interest?

Become a member to follow this project and never miss any updates