Saturday, February 02, 2008

Solenoid Lock -- Electronics

The construction of the solenoid lock electronics. Cost under $10 with part of a bigger order(Unless you can't scrounge up your own power supplies). The most expensive part is the relay.

Parts:
Below is the basic schematic. One thing to note is constant power is given to light up a C(For closed) on the second display, and one of the output pins on the pic is shorted to several to create the O(For open) when needed.


The circuit was quite easy, although I did have to plus up my microcontroller power supply with a 9V, to get enough current to drive the relay(I originally had a smaller display that broke, and adding the larger one sucked just enough amps to stop the relay from reliably switching).

The code for the PIC is in MCC18 and was compiled in MPLab. Source code can be downloaded here. Also the hex file for PIC18F4520 is here.

It's a pretty simple analog to digital conversion, then chop off all but the upper bits to get the proper hex value. It uses a separate thread to monitor how long the number was held for. One issue that took me forever to debug is the conversion takes several cycles and the number you are storing to has no definite value at that time. Meaning if another thread interrupts in the middle and tries to read that value it will get garbage. This is easily mitigated with a temporary variable being used during the conversion.

Soldering it up was hassle free, although I had a lot of wires that were required. 2 Power supplies to the control box, then 4 wires of power to the solenoid and microcontroller, 9 wires from the microcontoller to the control box for the display, and then a phone cord was used to hook up the trim pot to the microcontroller. If I had been willing to, it would have been *much* nicer to have embedded everything into the door, control box and all, so there were only the power wires.

Picture of the spaghetti wiring:

Rehashed video from an earlier post of the electronics running(Note: I'm manipulating a potentiometer offscreen to scroll through the numbers):


No comments: