It is quite complicated, because there are many subroutines and procedures that run simultaneously. To simplify the code reading, i have split it into files, each one with a specific set of subroutines. The EEPROM_Support_inc is responsible for reading and writing into the EEPROM memory. The myInitilization.inc has the basic chip initialization routines, along with the oscillator configuration. The buzzer.inc has the subroutines with the buzzer sounds. The mSecDelayGenerator2MHz.inc has as always the subroutines with the pre-programmed millisecond delays, the ServoControl.inc has the routines to change the PWM duty cycle of the servo, the setup_modules.inc has the initialization routines for the capacitance sensor module and the PWM module of the servo and the isr.inc has all the dirty job in the Interrupt Service Routine, in which a key touch is sensed.
The EEPROM needs some attention
The code is stored in the EEPROM. I chose this memory, because in the future i plan to upgrade the software to be able the operator to change the code from the keypad. Right now, in version 1.0, the code can only be programmed directly in the EEPROM. So when you upload the firmware, remember to upload the EEPROM code as well. Here is how to do it:
The first position of the EEPROM memory (offset 0x00) has the length of the code. So, if your code is 1234, then the first position (0x00) must be 0x04, which means that the code has 4 digits. The code is then saved in EEPROM positions 0x01 and above. So, here is an example of the EEPROM memory, if your code is '182736'
0x06 (6 digits long)
0x01 (1st digit)
0x08 (2nd digit)
0x02 (3rd digit)
0x07 (4th digit)
0x03 (5th digit)
0x06 (6th digit)
Putting it all together and running a first test
I am not going to install the system directly inside the door. I will keep it outside temporary, because i want to measure the battery voltage, i may want to change firmware, and generally, any change that needs to be done would require to dismantle the door lock every time. Therefore, i used double sided duct tape to fix the keypad and a carton box that the PCB will be housed (temporary). The battery pack is fixed again with double sided duct tape above the carton box. Here are some pictures of the assy:
This is a temporary position for the circuit
The controller is inside the carton box
Looks ugly but strangely interesting
The touchpad may change face
In previous pages where i described the keypad, i had double sided duct tape on each button. I was going to put a plexiglas or a glass or plastic above these buttons, but hey, i can use the PCB itself as the touch surface! Why not? Or i could stick something on it, like a black film, or i could paint it black... The surface is very nice to work with. So, with double sided duct tape, i fixed the touchpad onto the door, with the copper side facing the door.
There is a hole that needs to be covered (big deal) and also i have to move the 2 jumpers from the back side to the copper side (again big deal). But i really like this layout and i think i will keep it that way.
Change code from the keyboard is now possible!
I uploaded a major update for the PIC firmware. With version 2.0 the operator can change the code directly from the touch pad. Here is how it works:
First the operator needs to know the current code. So, to confirm, the door must be opened.
After entering the correct code, the operator does not open the door. Instead, the door must be pulled back to activate the pull switch. The operator has to keep it back as long as the green LED flashes.
If the above condition is executed, a distinctive sound is heard from the buzzer. The operator can enter the new code.
After entering the new code, the operator must press the enter. The buzzer sounds to inform the operator that he must re-enter the code for confirmation.
The operator re-enters the code. If the code is incorrect, the procedure is terminated and the old code remains. If the confirmation succeeds, the old code is replaced by the new code and the procedure is terminated.
This is a feature that was missing from the project. So now, if you visit me, do not try to enter with the 1-5-9 code, for it is changed!
Sorry,to be more precise I meant the wire which is attached to your servo to unlock and lock the door. There is something like a piece of tape holding them together, looks really solid! May i know what did you use for to hold the 2 pieces of wire together?
Going through your schematics, the keypad (without the LED backlit) is powered from the main PIC, or am i missing something? Even going through the code you have the RB5 port set as KeypadSupply. I know that the PIC16F1937 can work with very low current, I'm just trying to confirm if i need an external power pin on the keypad. (The backlit is already powered externaly in my design)
I understand the color coding for the RC servos, i just wanted to confirm the connector layout on your project. In the code the PWM pin is connected to register C2, which means that the D registers and the relay are used for power, is that correct?
Also is it safe to power the keypad directly from the PIC via the B5 pin without a transistor?
Thank you for your replies, I'm trying to expand this project a bit with an LCD and other periferals. However that relay's got me a bit perplexed, still does tbh. Also I haven't seen the 100uH inductor on the photos. If im correct a 0.5A inductor should be enough, right?
Hello, Your work is interessant. I have well test the same capacitive
keyboard like your. Now I would like to test the
communication with a PC by rs232. But I do not sometimes happen to
find this program for the keyboard on your site. Could you help me to
find it? Thank you.
Great project. We want to make an electronic door for our hackerspace in Istanbul, Turkey. We are lokking for something that actually locks the door. In your case, the system only pulls the thing at the top, right? It does not actually fully lock or unlock the door.
How can we do that for more security? What would be your suggestions. Thank you.
@Giorgos Nak a solenoid would work as well, but the problem is that you want the "tongue" of the locker to remain open for 3 seconds so that you have time to open the door. This means that the solenoid must be always powered for these 3 seconds, something that does not happen with the motor. The breaking power of the gears is enough to hold the tongue in the opened position. So, the motor works for a few miliseconds to pull the tongue and then you remove the power for as long as you want, until again the power is connected to release the tongue. This is for me a good solution. For better power consumption i would get a better servo with smaller motor.
But think about this: every time you open the door, the servo draws 200mA for 1 sec to open another 150mA (less torque needed) for 1 sec to close, a total of 350mA for 1 second. A typical (non-alkaline) battery can provide 1200mAh. This means that the 4 batteries (6V @ 1200mA) can open and close the servo about 12.000 times (theoretically). I use 4 alkaline batteries.
I really thank you for the prompt reply.
I tried also to manufacture something similar, and I used a DC motor (with gearing to transfer the movement). The current that the motor draws is 150mA approx. So, you would also propose something different than the servo or the DC motor to create the wanted movement?
I had measured the current of the servo and it was around 200mA (if i remember correct). An estimation with many educative guesses was that the batteries will hold more than 1 year with normal operation (12 openings per day, every day). There are better products than the cheap servo i used of course, but not a simple DC motor because the servo has the built-in controller for the positioning.
The best 3 points for limiting the power consumption are the sleep mode of the PIC (16uA standby-current), the mechanical switch to wake up the PIC (so no more standby current is required) and the latching relay to power the servo only when moving.
I write to you some thoughts that came up seeing the videos.
1. Have you measured the mA that the servo draws and also the power consumption during the movement?
2. Which could be in your opinion an estimated lifetime of the batteries with a normal use?
3. A simply DC motor (of course using a gearing to reduce speed) could be maybe less power \"hungry\" than the servo?
@shobdy no this is not correct. check this out:
the touchpad is exactly this, only that i have add the resistors and the transistor for the leds. That page will help you. I use these channels:
which correspond to these buttons respectively:
OK, after going through the ASM with my limited knowledge the best I could figure out is:
Pin 34 (Cap_check_Ch_1) is hooked to touch pad 1
Pin 35 (Cap_check_Ch_2) is hooked to touch pad 2
Pin 37 (Cap_check_Ch_3) is hooked to touch pad 3
Pin 38 (Cap_check_Ch_4) is hooked to touch pad 4
Pin 06 (Cap_check_Ch_5) is hooked to touch pad 5
Pin 07 (Cap_check_Ch_6) is hooked to touch pad 6
Pin 19 (Cap_check_Ch_7) is hooked to touch pad 7
Pin 20 (Cap_check_Ch_8) is hooked to touch pad 8
Pin 21 (Cap_check_Ch_9) is hooked to touch pad 9
Pin 27 (Cap_check_Ch_10) is hooked to touch pad 10
I thought I just about had the keypad figured out when I noticed that the pins on the PIC didn't make sense to me. It looks like (from looking at your printouts of the front and back of the PCB):
Pin 37 is hooked to touch pad 1
Pin 35 is hooked to touch pad 2
Pin 27 is hooked to touch pad 3
Pin 38 is hooked to touch pad 4
Pin 34 is hooked to touch pad 5
Pin 21 is hooked to touch pad 6
Pin 06 is hooked to touch pad 7
Pin 19 is hooked to touch pad 8
Pin 20 is hooked to touch pad 9
Pin 07 is hooked to touch pad 0
Is this correct? I may be able to go through the ASM and figure it out before you respond but it is always better to ask the designer if you can :)
@shobdy correct, these are 2 more LEDs to show the status, the red and green LEDs. I do not use them any more, you can totally omit them. I do have though a connector in case that....
The VLED is not part of the PCB. It is a wire that goes directly onto a transistor. The transistor is on the air, it is not soldered anywhere. When i decided to add backlit, i had already the PCB made, and i did not make a new. (http://pcbheaven.com/projectpages/images/servoactuateddoorkeylockhack_1309163657.jpg)
As for the resistors, any value between 220 and 6K8 will do. I used 6K8 because the PIC can work with a little current. But i stated 220, because it is the lowest limit that someone can use without damaging the PIC from over current if something goes bad, like short-circuiting the wires or pacing them at +5v.
To me it looks like X3-1, X3-2, X4-1, and X4-2 are not really used on the newest version of the doorlock. It looks like it ran two different LEDS in the earlier version. Is it OK to omit that part of the circuit or is it used for something else I am unaware of?
Next part is to clarify something for me. It looks like you soldered 6 wires to the keypad. Your schematic shows 7. Did you solder the VLED somewhere else on your pcb?
The last thing for today is while studying the photos I noticed a few differenced in resistor values. Example is the for you added to the keypad for protection look like they are 6k8. Yet on the schematics you have them down as 220. Which is correct?
Will probably ask more tomorrow. I have started ordering parts to get this going. Wish me luck and thanks for answering all my questions.
@shobdy correct, the leds goes to the emitter. They are all connected in parallel with a limiting resistor.
For the 7th pin: The keypad gets power NOT from the +4.5V on the board. Instead, the PIC on the controller provides power from one pin to the board outside, just to save more power. When the PIC on the controller goes to sleep, the PIC on the touchpad gets absolutely no power, so draws 0 current. But the pin cannot provide enough current for the leds, so i need more current therefore i have one extra line. That other line is the VLED.
About the relay: 15-2 and 16-1 are the SET and RESET, 9-12 is the Normal Open contact for the servo power.
SG1 is the buzzer. It is a simple 5V buzzer.
One more point: Notice in the close image of the touchpad: I have connect the ground wire to the "hatched area" of the PCB, this is something that you need to do as well. Also, i have connect the bottom side hatched area with the top-side hatched area together, so both areas around the keys are grounded.
Thanks for the answers; I have had some training on assembly language years ago and have been trying to brush up on it recently;
The LED's for lighting the keypad, in the schematic I am creating, are hooked to the emitter of the transistor you labeled as Q1 on the keypad schematic; this it correct? The 4 LEDs you used, were they in parellel or serial?
The 7 pin connector you have. Why is there a LED power on the 7th pin if it isn't hooked up on the other end? Can I do away with that and just make the connector a 6 pin also?
Why did you label the VLED seperate from the other power sources? It is 4.5 volts like the rest; couldn't I just tie it in with the others?
Another question I have is about the latching relay. I can't find the one you used so I am going to adapt one from ebay to do it. What I need to know is: on the doorlock schematic, pins 1 and 16 of the relay, are they the ones that enable the relay? pins 2 and 15 disable the relay? and pins 10 and 12 run the servo? or do the first 4 mentioned pins do something else?
SG1, it is just a piezo buzzer? anything you can tell me about it that will help me find a replacement?
I am sorry that I am hitting you with these question but I am trying to re-create your work with different parts and I am not sure of my modding skills yet.
Any and all answers are appreciated and welcomed as they further my knowledge.
@shobdy VLED is the voltage for the LED indeed. The transistor T1 (bc548) is a last minute add. The emitter of the transistor should have the LEDs (which are not shown in the schematic - my bad). The thing is that the LEDs along with the transistor and the resistor are NOT in my prototype, i soldered them directly on the air. SO you need to keep that in mind.
Also, as you may notice, the 2 connector which connect the controller with the keypad are not consient, one has 7 pins and the other 6. So be careful when you connect them. Do you know anything about PIC programming and assembly? That will help you.
C3 and C4 are 0.1 uF ceramic capacitor and D1 is 1N4007 diode or any 1A shottky barrier diode (better use a shottky diode).
I wanted to say that your project looks awesome. I would like to try and do it but I am having a bit of a time following your schematics. The keypad schematic wasn't bad except I am not sure what the to lead called "VLED" go to. Are they supposed to hooked to the LED's you lit your keypad with? I don't see LED's anywhere in your schematic. On the other schematic I see that there are a few parts that are not labeled. Examples are: C3, C4, D1, The transistor in the bottom left corner. Did you create a part's list? Sorry to hit you with all these questions. I am excited about trying to build this and don't want to screw it up!
hye i'm really interested with this project.can U tell & show me the detail about the programming that U use to to operate the PIC here.I'm really not know how to create the programming.And also can U show the detail of circuit layout?please....
Wow. This is awesome. The tech editor at Instructables.com, my boss, put my onto this project and I've got to thank both of you! This is brilliant.
We're actually running a contest right now that this project would qualify for, if you're up for putting the instructions onto Instructables.com. You could win a bus pirate (http://dangerousprototypes.com/docs/Bus_Pirate) and a hundred bucks just for joining and adding this to the contest. Could be cool.
Let me know if you're interested. This is exactly the kind of project that benefits from the step by step format of Instructables.
@Stefan i strongly suggest you use different capacitance channel for each button. Use 10 channels and not 5 as i did. The paired method does not work very good when a 4mm plexiglass is between the buttons. I look forward to see photos from your project. Good luck.
It is an optical scanner. The previous ones are two scanners from Authentec. I found them on devices I bought from ebay. The problem is that they don't have an integrated processor on board, so I have to write the software.
It should not be too hard, I found some linux users who wrote the application and they say it works, so perhaps I 'll try to migrate the code from the C linux environment to a ARM7 or ARM9. I am too lazy to build the board though.
No I don't have a blog or a site, I am too lazy for that, perhaps when I finish (it won't be until the next couple of months) I will give all the material to you and you can host it here if you like.
@Panagiotis there is no trick in hiding inside the door, nor you need any ingenious way to do it. I just happen to know exactly how these doors are made (i used to work in a factory that makes doors). And i know, that, if you keep things thin (under 20mm), you can put almost anything inside. That is why i kept the PCB and the batteries thin.
"i will have more serious problems to solve than this, namely the hurricane katrina that is right above my house :D"
Ha ha ha ha....Thank God Greece is safe from hurricanes!!!Well i'll be waiting news...Also i would like to thank you for your useful instructions about the servo because i didn't know that you can make these calculations to calculate the torgue!!!!!!! :-)
" i post detail documentation about my hacks, no tricks hidden ;) "
I didn't mean that you will hide something,but it will be a tricky-(smart) way the way you will put it in the door!!! :-)
Hi panagioti. Regarding the waking of the PIC, i have include already a case that the PIC will only wake if the pull switch is continuously activated for 250mSec, exactly for this reason (the wind). Moreover, the door has rubber sealing which act as spring and prevents it from hitting and making noise from the wind. Because of these two, if the PIC ever wakes due to air, i will have more serious problems to solve than this, namely the hurricane katrina that is right above my house :D
Regarding the servos, 1.6 Kg-cm is very good torque. But after making this hack, i began testing all the door locks to see how "hard" the spring is. What i've found is that there are keylocks with very hard spring, as well as others with very soft. Luckily, the one that my door had is somewhere in the middle, and the servo can easily pull it back. Here is your calculation: Your servo can pull 1.6 kilos with a lever of 1cm. But there is no need to use a whole cm as lever. I used about 6mm, so the servo can pull about 1.6 times more weight (1/0.6) which is 2.56 kilos, far enough to overcome any spring.
Regarding the video now, as always, i post detail documentation about my hacks, no tricks hidden ;)
When you finish it please post a video of how you placed it into the door... that is going to be a little tricky.Also i would like to mention you something about the wakening of the pic,(if you have\\\'t consider it yet).I think that you must find another way of wakening up the pic.Everytime that the wind blows you will have a wakening of the pic so i don\\\'t know if these contacts are the best solution to wake up the pic.
(for energy saving and only)
Yeasterday i bought a pack of 9g servo and in the description was saying that have 1,6kg/cm.Is this value ok to pull the \\\"tongue\\\" of the keylock?
yes Fung, there are like a million different uses for the inductors. As a matter of fact, you could somehow consider inductors like the opposite of capacitors. They are used in filters, smoothing applications, PWM power supplies and many more.
Regarding the buzzer, the limiting resistor is mainly to protect the transistor, as it is selected to operate in saturation. So, no matter how small you make it, you will see no difference. You could try to change the duty cycle of the signal, but i have never test it that deep.