My first project is a box with a magnetic lock controlled by a RFID reader.

The hardware

I started out with Arduino Yun but quite quickly a replaced the Yun with the smaller Arduino Nano. Beside the Ardoino Nano I have used the following components for this project.

There are a couple of reasons for selecting a permanent electromagnet instead of a normal electromagnet. With a permanent magnet you dont have to supply power to the magnet when the box is idle (closed) which of course makes it consume less power and the box also appears “locked” even when the power if disconnected. Another reason is that the magnet becomes quite warm when the power is on.

The mosfet is used to control the power supply for the 12v electromagnet and the microswitch is used to make sure that the power to the magnet is on whenever the lid is open, otherwise the box would turn in to a finger guillotine. It’s been a long time since I used a transistor and after googling for similar projects I found this blog post that described the mosfet and how to use it.

Finally I mounted and soldered everything on a small board and before it was installed in the box, the finished product looked liked this.

Finished product

The code

Here you can find the code. I know It needs to be cleaned up and refactored and in the project there is also an unfinished implementation for another RFID reader. I plan to cover this and the factory pattern I used in a separate post, when I get it to work…

Images

The finished product

Finished product

Finished product

Finished product

The hardware before it was mounted in the box

Finished product

The hardware installed in the box

Finished product

The lock is a permanent electro magnet (300N). You can also se the micro switch that makes sure that the current is on whenever the lid is open. Otherwise the magnet will close the lid quite fast….

Finished product