Maker.io main logo

DIY Electronic Safe Using Raspberry Pi 3 A+

2019-03-22 | By ASHLEY

License: None Magnets Raspberry Pi

Have a spare Raspberry Pi lying around? Well, we did, and what better day to use it than Pi Day! The idea behind this came from the fact that working in an office, there are always food thieves. Now, to combat those thieves you could do a number of things, but we decided to create a portable electronic safe for our pie, controlled by our Pi! Just a little bit of perception coming at you.

 

The electronics involved are minimal. We used a Raspberry Pi 3 Model A+ as the brains of the project. There is a hall effect sensor connected to GPIO17 (pin 11) on the Pi. The sensor has a logic output with an internal pull-up resistor setting it high. When a magnetic field is present the sensor’s output is pulled low, sending the signal to the Pi.

The low signal received by the Pi from the hall effect sensor then triggers a solid state relay on GPIO21 (pin40) of the Pi, to send a 12VDC to trigger a solenoid with a 12VDC coil. When the solenoid is triggered, the pin pulls back into the solenoid thus unlocking the case.

Image 2

Now, you might be saying, “Anyone could open the case with a magnet then, how is that a safe?” Well, the enclosure we selected is totally sealed and non-transparent. This gives us the ability to hide the sensor so well, that we even forgot where it was at one point. (If you’re wondering if we looked silly dragging a magnet all over a LARGE black case, the answer is YES.) Another perk to this, if someone figures out where the sensor is located, you can move the sensor, similar to changing a password or combination.

To power all of this we used a dual AC to DC power supply with 5VDC out to run the Pi and 12VDC out to run the solenoid. This was the easiest way to power this project and for our purposes, it was ok that it required an outlet. Now, if you want to make this wireless, you can use a 12VDC battery pack with a 5VDC regulator to power the Pi. One thing to keep in mind is that if the battery dies, the solenoid will not trigger and thus the case will stay locked indefinitely. If you go the battery pack route, make sure you place them on the outside of the case or place a charging connector that can be accessed from the outside.

We added neopixels to the inner bottom portion of the case for a sort of “glowing” effect like you see on movies when a treasure chest is opened. When doing this it was discovered that if the Pi was powered from the USB port, there was a significant voltage drop while the neopixels were lit so we had to directly wire the pi to the power supply.

Image 3

All of this is programmed with Python in Raspbian OS. The code is very straightforward. It has been embedded below for your use.

Overall the project isn’t super complex but was an extremely fun project that provided for an awesome video. There are a lot of modifications that you could make to this project. For example, the hall effect sensor could easily be switched out for RFID, a keypad, fingerprint scanner, etc. If you create this project, post it on social and use #MakeWithDigikey so we can see your versions! Happy Pi Day!

Code:

Copy Code
Kyle Meier

Digi-Key Electronics

Mar 2019

Pi Day 2019


Using Solid State Relay 255-2680-ND and hall effect sensor AH3582-P-BDI-ND.

Pull solenoid 1528-1191-ND is controlled by the SSR. This has a 12VDC coil,

Raspberry pi is 3.3v logic. SSR allows switching of the 12VDC supply to control

the solenoid.

SSR Pin 1 is LED input, pin 2 is LED GND. 1.5v up to 50mA. Use a 50ish ohm resistor.

Pins 3&4 of SSR switch, with normally open operation.

Hall effect sensor can accept 3-28Vin. Pin 1 Vin, 2 GND, 3 Output. Internal

pullup, output is low when magnet approaches.


GPIO21 (physical pin 40) SSR output

GPIO17 (physical pin 11) Hall effect input.

GPIO18, (physical pin 12) Neopixel Data pin

'''


import board

import neopixel

import RPi.GPIO as GPIO

import time

pixels = neopixel.NeoPixel(board.D18,150) # 150 is the number of pixels on your strip. Modify as needed.

GPIO.setwarnings(False)

GPIO.setup(21, GPIO.OUT, initial=GPIO.LOW) #SSR Output

GPIO.setup(17, GPIO.IN) #Input from hall effect sensor

lightsOn = 0 #Variable to control state of lights

while 1: #run this code forever

print (GPIO.input(17)) # Print status of hall effect sensor to shell.

time.sleep(0.5)

while (GPIO.input(17)== 0): # While the hall effect sensor output is low (magnet close to sensor)

GPIO.output(21, 1) # Activate SSR/Solenoid

lightsOn = not lightsOn

if lightsOn:

pixels.fill((255, 200, 0)) # Golden "treasure chest" look. Values are RGB.

else:

pixels.fill((0, 0, 0)) # turn lights off if lightsOn variable is = 0

time.sleep(1.5) # time to hold latch open

print (GPIO.input(17)) # Continue printing status

GPIO.output(21, 0)

 

制造商零件编号 1512
SOLENOID PULL 12V
Adafruit Industries LLC
¥125.97
Details
制造商零件编号 RD-35A
AC/DC CONVERTER 5V 12V 32W
MEAN WELL USA Inc.
¥145.95
Details
制造商零件编号 50470
CASE PLASTIC BLACK 20"L X 15"W
Flambeau Inc.
¥425.54
Details
制造商零件编号 AH3582-P-B
MAGNETIC SWITCH OMNIPOLAR 3SIP
Diodes Incorporated
¥1.71
Details
制造商零件编号 AQY212GH
SSR RELAY SPST-NO 1.1A 0-60V
Panasonic Electric Works
¥26.47
Details
制造商零件编号 PRT-08808
BREADBOARD GENERAL PURPOSE
SparkFun Electronics
¥15.87
Details
制造商零件编号 RF4711
SCOTCH GENERAL PURPOSE FASTENERS
3M
¥35.14
Details
制造商零件编号 9200-25ML
STRUCTURAL EPOXY ADHESIVE
MG Chemicals
¥255.12
Details
制造商零件编号 3174
HOOK-UP 22AWG SOLID - 10 X 25FT
Adafruit Industries LLC
¥251.28
Details
制造商零件编号 17621
HOT GLUE GUN 60W WITH PLASTIC TR
Aven Tools
¥286.08
Details
制造商零件编号 SSQ-120-03-T-D
CONN RCPT 40POS 0.1 TIN PCB
Samtec Inc.
¥37.44
Details
制造商零件编号 OSTVN10A150
TERM BLK 10P SIDE ENT 2.54MM PCB
On Shore Technology Inc.
¥25.15
Details
制造商零件编号 2552
ADDRESS LED STRIP SERIAL RGB 1M
Adafruit Industries LLC
¥142.82
Details
制造商零件编号 SC0130(J)
SBC 1.4GHZ 4 CORE 512MB RAM
Raspberry Pi
¥203.50
Details
Add all DigiKey Parts to Cart
TechForum

Have questions or comments? Continue the conversation on TechForum, DigiKey's online community and technical resource.

Visit TechForum