I wanted a simple device that would tell me if somebody had been in my hotel safe whilst I was out on holiday, so I designed LightSafer. LightSafer is a tiny 33 x 21 mm (1.3 x 0.8 inch) gadget with PIN code entry that lets you know if somebody has been snooping around in your hotel safe (or sock drawer).
It's completely silent. You just press the button to arm LightSafer, put it in your safe and if anybody opens the safe and fails to enter the correct PIN, the alarm LED lights. Once the alarm is triggered there is no way to turn it off. Even if the battery is removed, as soon as a new one is put in, the alarm LED lights straight back up.
Entering the correct PIN is the only way to disable the alarm.
Already got LightSafer? Read the LightSafer User Guide for a full description on how to use it!
At the heart of the device is a PIC microcontroller, specifically the PIC16LF18345. The correct PIN is stored in the built-in EEPROM and the the code protect bits have been set. This prevents anybody from being able to dump the code of the PIC and read out the EEPROM.
The light sensor used is a Broadcom APDS-9300. I did originally use the APDS-9301, which supported 3 volt operation, but they've since discontinued that device so I moved to the APDS-9300 which is a 2.5 volt device, and added a 2.5 volt regulator. The sensor uses an I2C interface to the PIC and has a handy interrupt feature which can wake the PIC when a certain light level is reached.
LightSafer is powered by the ubiqitous CR2032 coin cell. The voltage of these coin cells can be anywhere from 3.3 volts to 2.5 volts, so I had to make sure all components supported operation inside this range.
Low power consumption is really important - I wanted to leave the coin cell permanently in LightSafer, so the power consumption when off had to be tiny. When in turned off, the APDS-9300 is powered down and the PIC is put into a super low power sleep mode, waiting for the button to be pressed to turn it on.
The interrupt feature of the APDS-9300 also lets me save power. When LightSafer is armed inside the safe, the APDS-9300 light sensor is configured by the PIC to raise an interrupt when the light exceeds a certain level. This lets the PIC go into a low power sleep whilst it waits for the APDS-9300 to wake it up.
I've wired the battery through a potential divider into an ADC input of the PIC, so the battery life can be communicated to the user.
|State||Current Consumption @ 3.0V|
|Armed (i.e. sat in your safe)||146 μA|
User input is through a 5-way joystick: up, down, left, right, push. LightSafer uses an 8-digit PIN for disarming. Digits 1-4 can be used in the PIN - 1 is up, 2 is right, 3 is down and 4 is left. For example, a PIN of 14322312 would be up, left, down, right, right, left, up, right. The device is turned on and armed by pushing the joystick in. See the instruction guide below for more.
The design is fairly simple and comprises 6 LEDs (three dual colour packages), the PIC, the APDS-9300 light sensor, a 2.5 volt regulator, a programming connector and some capacitors and resistors.
Warning: this isn't a very pretty schematic! Click it to enlarge.
I wanted to try and get a description of what each of the LEDs meant onto the PCB, so the hardest part about the PCB design was trying to fit in the silkscreen! I've just about managed it though, you don't have to squint too much.
The PCB is shown below. As with all of my projects (see burningimage.net), I've used oshpark.com to manufacture the PCB. If you're interested in making your own LightSafer then you can even order yourself one by clicking the button below! They're only $5.45 for 3 boards, shipped worldwide for free.
The BoM for the project is given below - I've included links to component suppliers where available. Any manufacturer will do for the resistors and capacitors, so I've not given links for those. Any 0603 part of the right value will be fine.
|Ref Des||Qty||Description||Package||Manu. Part Number||RS Part Number|
|B1||1||CR2032 battery holder||-||BC-2001||219-7954|
|1||2.5 V regulator||SOT-23||MCP1700T-2502E/TT||669-4853|
|R1-5, R8||6||1k resistor||0603||-||-|
|3||Bi-colour surface mount LED||-||HSMF-C155||486-0430|
|1||6 way JST programming socket||-||SM06B-SRSS-TB||546-8827|
The PIC code was written in C using MPLAB, using the free MPLAB XC8 compiler. If you'd like to make your own LightSafer then the hex file to program into the PIC is below. The pins on the JST programming header map 1:1 to the PICkit 2/3/4 programmer header. Alternatively, you can send boards to me and I can program them for you.
Read the LightSafer User Guide for a full description on how to use LightSafer.