For this project, I wanted my front door to lock when it was closed. I live in a condo, so often when one of us leaves the house, if someone else is in the house or we are doing something quickly, we don't lock the front door to our specific unit. I thought making a device that locks the door behind us would be helpful.
Coding the Big Sound SensorFirst, I coded an Arduino big sound sensor. The purpose of this sensor was to detect when the door had been closed.
When first testing my big sound sensor, I made it so when it detected noise, an LED would light up.
void loop() {
int statusSensor = digitalRead(soundSensor);
if(statusSensor == 1){
digitalWrite(LED, HIGH);
delay(1000);
}
else{
digitalWrite(LED, LOW);
}
}
It was then easy to change an LED turning on to a servo motor moving later in the coding process.
Coding the Servo MotorI then coded the servo motor. This is what I was going to use to flip the lock (how that is done, we'll get to later).
I implemented the servo into my code, and firstly just tested it on it's own.
void loop() {
myservo.write(0);
delay(750);
myservo.write(90);
delay(750);
myservo.write(180);
delay(500);
}
Once that was tested and the servo was working, I put two and two together and put the sound sensor to work with the servo.
void loop() {
int statusSensor = digitalRead(soundSensor);
if(statusSensor == 1){
delay(1000);
myservo.write(180);
delay(1000);
}
else{
myservo.write(0);
}
}
Setting It UpNext was to set up the actual door locking system.
I made a box to attach my portable battery to the door and a box to hold my big sound sensor.
I attached my breadboard to my door, and now all that was left was the sensor...
Door Lock Attempt #1My original idea to lock the door was to have the servo flip the switch closed. This did not go well for a multitude of reasons:
- The arm of the servo was taller than the lock itself, causing the longer arm I had to attach to it to be a more difficult creation.
- I had no better idea for the longer arm of the servo than popsicle sticks... (not the best move on my part).
- With the way the servo moved and the way the lock flipped, it would need even more power to actually flip the lock.
- And finally, the servo was only so powerful (and it's even less powerful when there are popsicle sticks taped to it...)
Needless to say this attempt gave me nothing but frustration and blue fingers (because apparently whatever dye they use for blue popsicle sticks comes off very easily if you have sweaty hands).
Now for the actually successful attempt(!). I was frustrated and thinking of idea when I realized a sort of "walmart" pulley system could be the answer I was looking for.
And so, I got some dental floss and attached one end to the lock and the other to the servo. I then used an empty mini m&m's tube and put some plastic loosely around it as a sort of peg or wheel type thing to make the pull on the string not as challenging for the servo. And with a few attempts and a lot of tape, it worked! When the sound sensor heard the door close, the servo was able to successfully lock the lock.
While I would call this a successful project, I will say that the lock did not flip all the way closed. It still locked, so it doesn't matter on a technical level, but it is a flaw in this project that is apparent to me. If I were to do this again, I would probably figure out a way to flip the lock that I was confident in before I began coding.
Comments