Introduction / Desk Lock Project - Page 1
Forum section: electronics / projects

author: holozip
author_rank: Unknown
timestamp: December 30, 2013, 11:52:45 pm
content: 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:ComponentsArduino Pro Mini (Sainsmart knockoff)Numbered KeypadHitech HS-65MG Servo - metal geared and pretty solidPiezo BuzzerVariable 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 - KeypadD10 ServoD12 Piezo BuzzerThe 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 SketchCode:#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 Keymapconst byte ROWS = 4; // Four rowsconst byte COLS = 4; // Three columnschar keys = {{'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 = { 2, 3, 4, 5 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.byte colPins = { 6, 7, 8, 9 };// Create the KeypadKeypad 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;}}}

author: Stonent
author_rank: Super Contributor
timestamp: December 31, 2013, 12:50:07 am
content: Cool! How sturdy is it if someone just pulls really hard, will it break the servo?

author: tsmith35
author_rank: Frequent Contributor
timestamp: December 31, 2013, 12:55:50 am
content: Quote from: Stonent on December 31, 2013, 12:50:07 amIt looks like it uses an indirect (linked) locking mechanism, kind of like turning the knob on a deadbolt lock. The servo basically "turns the knob", while the actual locking bar provides all the strength. Looks like the locking bar slides up/down.Looks like an awesome job!

author: Stonent
author_rank: Super Contributor
timestamp: December 31, 2013, 01:07:59 am
content: Quote from: tsmith35 on December 31, 2013, 12:55:50 amOk I see how he did it now.

author: holozip
author_rank: Unknown
timestamp: December 31, 2013, 01:12:07 am
content: Thanks StonentIt'll hold up well against someone just pulling on the drawer(s), the servo just moves the original locking mechanism up and down (see blue arrows below), and doesn't bear any of the force.Though I discovered desk drawers aren't really very secure at all; they're pretty easy to break into with a big pair of pliers and some determination

author: holozip
author_rank: Unknown
timestamp: December 31, 2013, 01:19:39 am
content: Quote from: tsmith35 on December 31, 2013, 12:55:50 amThanks!

author: sachleen
author_rank: Contributor
timestamp: December 31, 2013, 01:27:27 am
content: Nice job! Does the keypad just stick to the drawer? I see the wires going down to the bottom, I assume the electronics are mounted on the bottom of the drawer...

author: holozip
author_rank: Unknown
timestamp: December 31, 2013, 01:35:31 am
content: Yep, the keypad has a sticky back. The plastic connector from it is pretty short, so I just run it underneath the drawer where I convert it to a cat5 network cable and run it out to the back.The actual electronics are affixed underneath the top side of the desk within the drawer compartment (there's plenty of clearance up there and gaps to stick stuff in). Thankfully the arduino pro is minuscule, so its quite easy to put it wherever

author: SeanB
author_rank: Super Contributor
timestamp: December 31, 2013, 06:21:14 am
content: Those drawer units are easy to pick as well, all you need is a paper clip and a small screwdriver. Often faster than looking for the key.

author: Skimask
author_rank: Super Contributor
timestamp: December 31, 2013, 06:24:17 am
content: One pry bar....3 seconds...Done...

author: SeanB
author_rank: Super Contributor
timestamp: December 31, 2013, 07:38:18 am
content: I wanted to use it again though...........

author: firewalker
author_rank: Super Contributor
timestamp: December 31, 2013, 07:56:02 am
content: Memories!!!I had build a similar thing more than 10 years ago as an assignment for a lab exercise in uni.It was using an Atmel AT90s2313 mcu, an HD44780 LCD (riped from an old Z80 educational board) the keyboard and a relay.Alexander.

author: holozip
author_rank: Unknown
timestamp: December 31, 2013, 11:21:12 am
content: Quote from: Skimask on December 31, 2013, 06:24:17 amYep, wouldn't take much effort with a crow bar. I guess its no less secure than the original mechanism - which is about the best I could hope for. Really I don't need a locked drawer, it was just an excuse to build something

author: holozip
author_rank: Unknown
timestamp: December 31, 2013, 11:58:37 am
content: Quote from: firewalker on December 31, 2013, 07:56:02 amAwesome - glad I could invoke some memories; in hindsight I should have been playing with this stuff as a teenager, but it wasn't quite so accessible back then I guess.I can imagine programming an Atmel chip 10 years ago was significantly more involved than plugging an arduino into a free usb slot and hitting the upload button. Was the code written in C, or did you have to write in assembly?

author: amyk
author_rank: Super Contributor
timestamp: December 31, 2013, 12:28:20 pm
content: I think a hardware override (i.e. you can open/close with a regular key too) is a good idea, especially if something happens to the electronics.

author: firewalker
author_rank: Super Contributor
timestamp: December 31, 2013, 12:43:05 pm
content: Quote from: holozip on December 31, 2013, 11:58:37 amThe code was in assembly (the lab was about assembly).The programming part wasn't difficult. Everything had a true serial port. I remember strangling with some Windows 98 (No XP yet) quirks though. I had to install Windows 98 (I was already using GNU/Linux exclusively) for the AVR Studio.The "funny" part was that we where using 56 kbps (at best) Dial-Up modems to access public domain...Alexander.

author: ivan747
author_rank: Super Contributor
timestamp: December 31, 2013, 12:47:11 pm
content: Quote from: holozip on December 31, 2013, 11:58:37 amWell that was 2004, you could have used a PICAXE microcontroller programmed in flow charts and have the data downloaded via a serial cable. Or 15 years back you could have used an expensive (like more than $50 for the starter version) BASIC Stamp, it was just like an Arduino mini except the microcontroller had a BASIC interpreter and the program was stores in an onboard EEPROM memory.But those chips were limited to the education and hobby market. Arduino isn't because you can just take the chip out of the development board and extract the libraries out of the IDE and basically program in C in your favorite IDE. You can't do that with the other two.

author: holozip
author_rank: Unknown
timestamp: December 31, 2013, 12:53:36 pm
content: Quote from: amyk on December 31, 2013, 12:28:20 pmThat would be forward thinking, and sensible! Coming up with a mechanism that works both manually and electronically would have probably stumped me though, I'm not very mechanically minded.I do have a hardware override in the form of Skimask's pry bar, and / or a good pair of pliersThe desk is fairly attackable from the outside whilst locked without doing a great deal of damage once you know how the locking mechanism works.

author: firewalker
author_rank: Super Contributor
timestamp: December 31, 2013, 12:56:45 pm
content: Quote from: ivan747 on December 31, 2013, 12:47:11 pmAs I can recall it was 2000-2001.

author: holozip
author_rank: Unknown
timestamp: December 31, 2013, 01:00:52 pm
content: QuoteI recently managed to get avr-eclipse working, and couldn't believable how much of a faff it is to set up a new project and get all the project params set just so. Even after building all the base libraries, it still takes me about 5 mins of setup for a simple project, I must find a way to make it easier.

author: firewalker
author_rank: Super Contributor
timestamp: December 31, 2013, 01:42:02 pm
content: Eclipse is a beast! GiveCodeBlocksa try.Alexander.

author: tsmith35
author_rank: Frequent Contributor
timestamp: December 31, 2013, 04:52:42 pm
content: Quote from: holozip on December 31, 2013, 12:53:36 pmAssuming the locking bar moves up to unlock, you could drill a hole at the bottom of the locking bar slide, directly underneath the end of the locking bar. In the event of an unlocking failure, you can put a metal rod of suitable length into the hole to contact the bottom of the locking bar. A few taps with a hammer would snap off the servo arm or break the servo loose. Now the desk is unlocked.

author: ConKbot
author_rank: Super Contributor
timestamp: December 31, 2013, 10:37:02 pm
content: Quote from: amyk on December 31, 2013, 12:28:20 pmQuote from: Skimask on December 31, 2013, 06:24:17 amfound the hardware override

author: Skimask
author_rank: Super Contributor
timestamp: December 31, 2013, 10:42:41 pm
content: Quote from: holozip on December 31, 2013, 11:21:12 amYa I guess.Locks only keep the honest people honest...

author: tsmith35
author_rank: Frequent Contributor
timestamp: January 01, 2014, 02:22:51 am
content: Quote from: Skimask on December 31, 2013, 10:42:41 pmAnd sometimes they keep dishonest people honest... lol