Hi there!I've been an avid fan of EEVblog for quite some time and figured now that Youtube have royally screwed up comments that I'd join in on the forum, introduce myself and say hi.
I'm firmly in the young player category as far as EE goes, but love tinkering with projects, learning and making a mess. I can usually be found flying model aircraft with video downlinks with a "first person view" perspective, or plodding along with work (IT / Media).
I thought perhaps one of the better ways to introduce myself might be to show you guys what I've been up to over the christmas break.
Electronic Desk LockI have an old wooden desk sourced from a second hand store; which I think was rescued from a school at some point. The desk has two lockable drawers built into it that I’ve never had the key for.
This is the desk in question, after the electric lock modification:
Components- Arduino Pro Mini (Sainsmart knockoff)
- Numbered Keypad
- Hitech HS-65MG Servo - metal geared and pretty solid
- Piezo Buzzer
- Variable voltage PSU (set to 5v)
I have played with Arduino’s in the past, but I've never really made anything permanent with one; so I bought Arduino Pro to save me from having to permanently embed my Uno or Mega into my desk. Arduino Pro's are awesome for the small footprint.
WiringI don’t have any pictures of the wiring or my dodgy soldering, but the servo, keypad and buzzer were pretty simple to hook up to the various digital ports:
- D2 -> D9 - Keypad
- D10 Servo
- D12 Piezo Buzzer
The difficult part was getting the 8 pins from the Keypad to run from my movable drawer to a fixed point inside the frame of the desk. I ended up hacking up a CAT5e network cable which has 8 cores to extend the length. Twice the required length is left hanging from the back desk drawer compartment to allow the drawer to fully extend.
I’m using the direct 5V input on the Arduino Pro since it’s more efficient and this thing will always be on. I might also have toasted the onboard regulator at some point.
I originally wanted to use a 9V PP9 battery, but power consumption was an issue. The arduino with the onboard regulator pulls around 24mA when active and around 7mA when sleeping - definitely not low enough to survive long term use from a PP9. I started to look at tuning power usage by turning off various devices in the chip, scaling back the clock frequency, and working out how to reliably wake the device back up, but I gave up pretty quickly - and just opted to plug it in to 5v supply instead.
Locking MechanismThe locking mechanism is pretty straightforward; the key barrel is screwed into the desk drawer, and contains a long metal prong that rotates off-centre when the key is turned. This metal prong in turn moves the locking slide rail up and down inside the drawer frame.
Using the servo, I made an electronic replacement for the barrel prong to live inside the drawer frame.
3D Printed Key BarrelTo prevent interference with the new servo mechanism I had to remove the original key barrel, which left an unsightly hole in the drawer.
Luckily, I bought a 3D printer some months ago but hadn’t graduated to actually designing my own parts. I spent some time getting to grips with 123D design, and managed to successfully build a replacement barrel without the prong:
This didn’t turn out too badly once printed:
And once installed, it covers up the gap nicely:
Demo VideoArduino Sketch#include <Servo.h>
#include <Password.h>
#include <Keypad.h>
// set up our piezo beeper:
int beeperPin = 12;
Password password = Password( "1234" );
// Define the Keypad ROWS and COLS and Keymap
const byte ROWS = 4; // Four rows
const byte COLS = 4; // Three columns
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 2, 3, 4, 5 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 6, 7, 8, 9 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
// Servo for lock control:
Servo myservo;
// Lock and unlock functions:
void lock()
{
myservo.attach(10);
myservo.write(30);
delay(500);
myservo.detach();
}
void unlock()
{
myservo.attach(10);
myservo.write(180);
delay(500);
myservo.detach();
}
void beepOnce()
{
// quick chirp for keypad feedback:
digitalWrite(beeperPin, HIGH);
delay(50);
digitalWrite(beeperPin, LOW);
}
void beepErr()
{
// Annoying error beep:
digitalWrite(beeperPin, HIGH);
delay(1000);
digitalWrite(beeperPin, LOW);
delay(200);
digitalWrite(beeperPin, HIGH);
delay(1000);
digitalWrite(beeperPin, LOW);
delay(200);
digitalWrite(beeperPin, HIGH);
delay(1000);
digitalWrite(beeperPin, LOW);
delay(200);
}
void guessPassword(){
if (password.evaluate()){
unlock();
password.reset();
}else{
beepErr();
password.reset();
}
}
void setup() {
pinMode(beeperPin, OUTPUT);
digitalWrite(beeperPin, LOW);
}
void loop()
{
char key = kpd.getKey();
if(key) // Check for a valid key.
{
switch (key)
{
case '*':
lock();
break;
case '#':
guessPassword();
break;
default:
beepOnce();
password.append(key);
break;
}
}
}