Once upon a time, I had the idea of completely replacing the deadbolt lock on my front door with a solenoid.  I knew how solenoids worked, but I had never played with one, much less programmed a board to make one work.

This project takes a switch and uses it to trigger the solenoid.  My basic design premise was I wanted the door to always be locked if it was closed.  It should only be unlocked when I pushed the button.  

I later realized that if the house has settled to the point that the solenoid-powered deadbolt didn't line up in the doorjamb properly, the door wouldn't lock automatically because the doorjamb would prevent the deadbolt from traveling the full distance to engage.  For maximum security, you don't want the hole for the deadbolt to have a ton of wiggle room (because that will make it easier to kick open the door).  So, this project was put on the back-burner because there were a lot of "gotchas" that I didn't really feel like spending the time/effort/money into investigating solutions.  Maybe one day when I have something I want to lock just for fun.

 

Nevertheless, here's the code & a video:

Video:

 

Code:

// -*- mode: C++ -*-
//
// Moves a solenoid when a button is switched on/of
//
// Copyright (C) 2012 Adam Shantz
// $Id: HRFMessage.h,v 1.0 2012/06/01 22:56:00 ashantz Exp ashantz $

const int buttonPin = 2;     // the number of the pushbutton pin
const int solPin1 =  5;      // the number of the solenoid pin
const int solPin2 =  6;      // the number of the solenoid pin
const int solPin3 =  7;      // the number of the solenoid pin
const int solPin4 =  8;      // the number of the solenoid pin
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {  
    Serial.begin(9600);
    
    // initialize the LED pin as an output:
    pinMode(solPin1, OUTPUT);
    pinMode(solPin2, OUTPUT);
    pinMode(solPin3, OUTPUT);
    pinMode(solPin4, OUTPUT);
    // initialize the pushbutton pin as an input:
    pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value
  buttonState = digitalRead(buttonPin);
  Serial.println("loop");
    
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) { 
    Serial.println("button high");

    digitalWrite(solPin1, HIGH);
    digitalWrite(solPin2, HIGH);
    digitalWrite(solPin3, HIGH);
    digitalWrite(solPin4, HIGH);
    
  } else if (buttonState == LOW) {
    digitalWrite(solPin1, LOW); 
    delay(2000);
    digitalWrite(solPin2, LOW); 
    delay(2000);
    digitalWrite(solPin3, LOW); 
    delay(2000);
    digitalWrite(solPin4, LOW); 
  }
}