Author Topic: Introduction / Desk Lock Project  (Read 9034 times)

0 Members and 1 Guest are viewing this topic.

Offline holozipTopic starter

  • Supporter
  • ****
  • Posts: 23
  • Country: gb
Introduction / Desk Lock Project
« on: December 30, 2013, 11:52:45 pm »
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 Lock
I 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.


Wiring
I 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 Mechanism

The 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 Barrel

To 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 Video



Arduino Sketch

Code: [Select]
#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;
    }
  }
}
« Last Edit: December 30, 2013, 11:55:58 pm by holozip »
 

Offline Stonent

  • Super Contributor
  • ***
  • Posts: 3824
  • Country: us
Re: Introduction / Desk Lock Project
« Reply #1 on: December 31, 2013, 12:50:07 am »
Cool! How sturdy is it if someone just pulls really hard, will it break the servo?
The larger the government, the smaller the citizen.
 

Offline tsmith35

  • Frequent Contributor
  • **
  • Posts: 265
  • Country: us
Re: Introduction / Desk Lock Project
« Reply #2 on: December 31, 2013, 12:55:50 am »
Cool! How sturdy is it if someone just pulls really hard, will it break the servo?

It 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! :-+
 

Offline Stonent

  • Super Contributor
  • ***
  • Posts: 3824
  • Country: us
Re: Introduction / Desk Lock Project
« Reply #3 on: December 31, 2013, 01:07:59 am »
Cool! How sturdy is it if someone just pulls really hard, will it break the servo?

It 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! :-+

Ok I see how he did it now.
The larger the government, the smaller the citizen.
 

Offline holozipTopic starter

  • Supporter
  • ****
  • Posts: 23
  • Country: gb
Re: Introduction / Desk Lock Project
« Reply #4 on: December 31, 2013, 01:12:07 am »
Thanks Stonent :)

It'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 :)
 

Offline holozipTopic starter

  • Supporter
  • ****
  • Posts: 23
  • Country: gb
Re: Introduction / Desk Lock Project
« Reply #5 on: December 31, 2013, 01:19:39 am »
It 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! :-+

Thanks! :D
 

Offline sachleen

  • Contributor
  • Posts: 39
  • Country: us
    • My Site
Re: Introduction / Desk Lock Project
« Reply #6 on: December 31, 2013, 01:27:27 am »
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...
 

Offline holozipTopic starter

  • Supporter
  • ****
  • Posts: 23
  • Country: gb
Re: Introduction / Desk Lock Project
« Reply #7 on: December 31, 2013, 01:35:31 am »
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 :)
 

Offline SeanB

  • Super Contributor
  • ***
  • Posts: 16308
  • Country: za
Re: Introduction / Desk Lock Project
« Reply #8 on: December 31, 2013, 06:21:14 am »
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.
 

Offline Skimask

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: Introduction / Desk Lock Project
« Reply #9 on: December 31, 2013, 06:24:17 am »
One pry bar...
.3 seconds...
Done...
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline SeanB

  • Super Contributor
  • ***
  • Posts: 16308
  • Country: za
Re: Introduction / Desk Lock Project
« Reply #10 on: December 31, 2013, 07:38:18 am »
I wanted to use it again though...........
 

Offline firewalker

  • Super Contributor
  • ***
  • Posts: 2450
  • Country: gr
Re: Introduction / Desk Lock Project
« Reply #11 on: December 31, 2013, 07:56:02 am »
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.
Become a realist, stay a dreamer.

 

Offline holozipTopic starter

  • Supporter
  • ****
  • Posts: 23
  • Country: gb
Re: Introduction / Desk Lock Project
« Reply #12 on: December 31, 2013, 11:21:12 am »
One pry bar...
.3 seconds...
Done...

Yep, 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 :)
 

Offline holozipTopic starter

  • Supporter
  • ****
  • Posts: 23
  • Country: gb
Re: Introduction / Desk Lock Project
« Reply #13 on: December 31, 2013, 11:58:37 am »
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.

Awesome - 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?
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8319
Re: Introduction / Desk Lock Project
« Reply #14 on: December 31, 2013, 12:28:20 pm »
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.
 

Offline firewalker

  • Super Contributor
  • ***
  • Posts: 2450
  • Country: gr
Re: Introduction / Desk Lock Project
« Reply #15 on: December 31, 2013, 12:43:05 pm »
Awesome - 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?

The 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.
« Last Edit: December 31, 2013, 12:53:25 pm by firewalker »
Become a realist, stay a dreamer.

 

Offline ivan747

  • Super Contributor
  • ***
  • Posts: 2045
  • Country: us
Introduction / Desk Lock Project
« Reply #16 on: December 31, 2013, 12:47:11 pm »

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.

Awesome - 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?

Well 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.


 

Offline holozipTopic starter

  • Supporter
  • ****
  • Posts: 23
  • Country: gb
Re: Introduction / Desk Lock Project
« Reply #17 on: December 31, 2013, 12:53:36 pm »
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.

That 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 pliers ;) The desk is fairly attackable from the outside whilst locked without doing a great deal of damage once you know how the locking mechanism works.


 

Offline firewalker

  • Super Contributor
  • ***
  • Posts: 2450
  • Country: gr
Re: Introduction / Desk Lock Project
« Reply #18 on: December 31, 2013, 12:56:45 pm »

Well 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.

As I can recall it was 2000-2001.
Become a realist, stay a dreamer.

 

Offline holozipTopic starter

  • Supporter
  • ****
  • Posts: 23
  • Country: gb
Re: Introduction / Desk Lock Project
« Reply #19 on: December 31, 2013, 01:00:52 pm »
Quote
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.

I 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.
 

Offline firewalker

  • Super Contributor
  • ***
  • Posts: 2450
  • Country: gr
Re: Introduction / Desk Lock Project
« Reply #20 on: December 31, 2013, 01:42:02 pm »
Eclipse is a beast! Give CodeBlocks a try.

Alexander.
Become a realist, stay a dreamer.

 

Offline tsmith35

  • Frequent Contributor
  • **
  • Posts: 265
  • Country: us
Re: Introduction / Desk Lock Project
« Reply #21 on: December 31, 2013, 04:52:42 pm »
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.

That 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 pliers ;) The desk is fairly attackable from the outside whilst locked without doing a great deal of damage once you know how the locking mechanism works.

Assuming 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. :)
 

Offline ConKbot

  • Super Contributor
  • ***
  • Posts: 1394
Re: Introduction / Desk Lock Project
« Reply #22 on: December 31, 2013, 10:37:02 pm »
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.

One pry bar...
.3 seconds...
Done...

found the hardware override ;)
 

Offline Skimask

  • Super Contributor
  • ***
  • Posts: 1433
  • Country: us
Re: Introduction / Desk Lock Project
« Reply #23 on: December 31, 2013, 10:42:41 pm »
Yep, 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 :)
Ya I guess.
Locks only keep the honest people honest...
I didn't take it apart.
I turned it on.

The only stupid question is, well, most of them...

Save a fuse...Blow an electrician.
 

Offline tsmith35

  • Frequent Contributor
  • **
  • Posts: 265
  • Country: us
Re: Introduction / Desk Lock Project
« Reply #24 on: January 01, 2014, 02:22:51 am »
Ya I guess.
Locks only keep the honest people honest...

And sometimes they keep dishonest people honest... lol
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf