Previously I introduced an opencv computer vision project I had been working on called the eye blink password. Most people password protect their valuables with a text based password. With this eye blink password code and a camera, you can protect your valuables with the correct sequence of blinks. If you want to see how to code works or how to run it yourself, or want to see the eye blink safe in action, check out this video.

That video is cool and all, but the code was just a proof of concept and hadn’t been put to a practical use. That is why I created this eye blink safe. It is a simple design powered by a raspberry pi 3B+ that actually uses the eye blink password code to protect an actual thing.

This is a wide ranging project that covers many topics, such as: raspberry pis, 3D printing, computer vision, python programming and many other things.

If you are interested in creating one of these for yourself, this thorough guide will walk you through all the required steps, in additional to outlining required tools and hardware.

Tool Requirements:

Hardware Requirements:

(I recommend just going to HomeDepot or Lowes to get these for cheaper, but if you want to simply order an assortment of screws that will work from online, check here)

(Assortment of jumpers here)

Steps to Building Eye Blink Safe:

1. 3D Print the Eye Blink Safe

I have made my designs available here:

I highly recommend the Creality Ender 3. It is super cheap and I’m frankly surprised at the quality of the builds it is capable of. The slicing software I am using is Ultimate Cura version 4.4

The eye blink safe is relatively large, so the printing time will take a lot of time.

The print settings I used to speed up the printing process are:

  • Profile .28 mm
  • Infill of 10%

But even with this, the total printing time for all parts is ~30 hours.

Here are the list of parts you will need to 3D print:

  • Safe base The internal safe dimensions are 5x5x5 inches
  • Safe door 

    Door of the safe. The extension seen on this door faces the inside of the safe.

  • Hinge

    Base, hinge and door connected after 3D printing

  • Safe top: The top and base have holes that align and will connect the two together. Recommend using 4×40 1/2″ screws.

  • Peg stands for safe (4 required): 

2. Assemble the 3D Printed Parts and Hardware

The 3D printed hinge is pretty neat, it requires no assembly to become a moving part. You just need to rotate the hinge back and forth to remove some of the support filament.

Once you can freely rotate the hinge without substantial resistance, it is time to connect the hinge to the base of the safe.

The right side is the safe base (door is already connected in this picture).

The hinge can move 270 degrees. We want the hinge to be fully rotated when the door is closed (at a 90 degree angle). When you are testing the movement of the hinge, it should be near completely vertical.

Hinge is completely extended to ~270 degrees with the door closed.

Once you have found the correct placement of the hinge, mark where the holes of the hinge should align on the base of the safe. Then drill the holes and connect the hinge to the base of the safe with your 6×32 1/2″ screws.

Once the hinge is connect to the base of the safe, you can attach the door to the moving side of the hinge. The process here will be similar- simply mark where the holes of the hinge align on the door, drill the holes and connect the door.

Inside of the safe, showing the screws that connect the hinge to the base of the safe. Make sure to screw the nuts on (not pictured).

You should now have a swinging door connected to the base of the safe.

Now connect the four peg stands to the bottom of the safe base so that it is elevated off the ground. Note, you may need to super glue the peg stands into the holes on the bottom of the base.

At this point, it is time to prep the top of the safe by attaching the locking solenoid.

Top of the safe with solenoid and LCD mounting screws already attached.

You could choose to secure the solenoid with screws to the mount on the top of the safe, but I would recommend simply super gluing the solenoid in place.

The solenoid should pressure fit into the hole in the top safe.


We want the top of the solenoid to be completely flush and level with the the mounting bracket (the solenoid should not be higher or lower than the top of the mounting bracket +/- 1.5 mm).

It is crucial to get the placement of the solenoid right, as this precision is what allows the door of the safe to close. Once the solenoid is in place, super glue the crap out of it.

Solenoid poking through the bottom of the top part of the safe.

Of course, you can also opt to actually screw the solenoid to the mounting bracket if you have an appropriate size screw on hand.

Now lets attach the Pi Cam to the top of the safe. We first want to attach the connector to the Pi Cam before mounting it.

Take the Pi Cam and open the black bracket. Below is a picture of the bracket in an ‘open’ state.

Pi Cam with Mounting Bracket Open

Front of Pi Cam. The Raspberry Pi logo shows the bottom of the Pi Cam.










Now insert the Pi Cam <-> Raspberry Pi connector. Ensure the blue side of the connector is facing the back of the Pi Cam.

Blue side of connector facing the back of the Pi Cam

Once the connector is inserted into the Pi Cam, close the black bracket. The connector should now be locked into the Pi Cam.

Now we can connect the Pi Cam to the top of the Eye Blink safe. Take a small drill bit and make the mounting holes of the Pi Cam and LCD screen a little large.

The top mount is for the LCD, the smaller mount is for the Pi Cam.

We want the Pi Cam to be facing in the correct direction. The correct position of the Pi Cam will have the connector coming off the bottom of the Pi Cam when mounted.

Place the Pi Cam by the mounting holes and secure it to the top of the safe with zipties. It is important to already have the connector attached to the Pi Cam before securing it to the safe.


Top Down view

Next up is attaching the LCD to the top of the eye blink safe. We will be securing the LCD to the safe with 4×40 1/2″ screws, but you could opt to also secure it with zipties.

Take your drill again and drill slightly larger holes into the mounting holes, then secure the LCD to the top.

LCD attached to top of eye blink safe.

We are now ready to attach the top of the safe to the base. You should see four holes in the corners of the top of the safe. These should align with mounting holes on the base of the safe. Use your 4×40 1/2″ or 3/4″ screws through the top part of the safe into the base of the safe.

Place the top of the safe onto the base, and let the 4×40 screws slide through the holes of the base. You should now be able to close the door of the safe. Closing the door locks the safe, as the extension of the door pushes locks behind the solenoid.

Choosing to secure the screws with nuts so that the top cannot be removed is up to you. The advantage to not securing the top of the safe to the base with the nuts is that you can simply remove the top of the safe as a way of opening the door.

If you secure the top to the base with nuts, you will HAVE to gain access by unlocking it with your eye blink password (unless you wanted to break the door). I chose to keep the top unsecured so I could simply remove the top if needed.

3. Connecting the electronics

Now we can start wiring the electronics. Below is a very rough and high level outline of the electronics. We will have two power sources: One to power the Raspberry Pi, and another to power the solenoid.


You will notice the diagram above uses two 9V batteries in series, good for 18V if the batteries are brand new. This is about 50% greater than the rated actuation voltage of the solenoid. It appears to draw ~500 mA at 18V.

As the voltage of the batteries drop over time, the supply voltage will drop towards the 12V actuation voltage. You may elect to get more fancy with the power supply circuit, but this seems to work.

The raspberry pi will be able to trigger the solenoid on/off via the relay. This is required as the raspberry pi cannot supply the required output current of the solenoid (350 mA+). Let’s wire that up first.

The blue, purple and green wires are Female to Female jumper.

The black wire in the middle is a Male to Male jumper.

The Brown wire is a Male to Female jumper.

The right side of this picture of the relay connects to the Raspberry Pi. The green wire is the signal wire. This is the wire the RPi will trigger high or low to control the solenoid. The blue wire is (-) and the purple is (+).

Below is a diagram of the Raspberry Pi 3B+ that we are using.

We will be connecting the green wire to PIN 40 (GPIO21), the purple wire to PIN 2 (5V) and the blue wire to PIN 39 (GND)

Now let’s set up the 9V batteries. 

We will be placing two 9V batteries in series. Find two 9V connector harnesses- we will be making some modifications to wire them in series.

Take some scissors or a wire trimming tool, and cut insulation off one connector’s black wire, and the other connector’s red wire. Then wrap those two together so you have the red and black wires now connected. I recommend soldering the newly connected wires.

Take your scissors/wire cutter and remove ~5mm of insulation off the other wires.

Now connect the batteries. Make sure they are not getting hot and you didn’t wire them incorrectly. 

It would be wise to cover the connected red/black wires with a heat shrink.

Now you have a power supply for the solenoid. Take a female to male jumper, and connect the female end to the black wire of the power supply. Then connect the male end to the relay in the bay labeled “NO” (for normally open).

Next, take a male to male jumper, and connect the middle bay of the relay to the black wire of the solenoid itself.

Wires from the Solenoid itself

Now take a female to male jumper, connect the male side to the red wire of the solenoid, and the female end to the red wire of the 9V power supply.

The solenoid circuit should now be fully wired. When the raspberry pi sends a high voltage to the signal pin (green wire in the picture), it completes the circuit on the solenoid side and powers the voltage. When the signal pin goes low, the circuit is open and the solenoid is not powered.

Next up is connecting the Pi Cam connector to the Raspberry Pi. Again, unlock the black bracket, insert the connector into the Raspberry Pi and lock it closed. The blue side of the connector will be facing the USB hubs/ethernet port.

Last up is connecting the power and I2C lines to the LCD.

You will need to have the jumper pictured above connected to the two exposed pins to the left of this picture.

The wires on the right, from top to bottom, are: 

  • GND (Grey)
  • VCC (Orange)
  • SDA (Yellow)
  • SCL (Green)

Referring back to the Raspberry Pi 3B+ diagram: 

Connect GND to PIN 6, VCC to PIN 4, SDA to PIN 3 and SCL to PIN 5.

And with that, you should be completed with the wiring of the electronics! Now it is time to set up the Raspberry Pi and fetch all the dependencies required to run the openCV computer vision based eye blink password.

4. Setting up the Raspberry Pi

Now we are done with hardware and ready to set up the code on the raspberry pi.

The first step we have to do is flash the SD card with an OS. SD cards should be 8GB and larger, and you will need an SD card reader that you can plug into a computer.

Next we need to download the OS image for the RPi. I am using the Buster lite image which you can download from my drive here. The latest official image can be obtained here but you run the risk of using a different OS than what the eye blink safe in this tutorial uses.

After this is downloaded, we need to flash the OS image to the SD card. To do that download Balana etcher. Open etcher once it installs.

Select the image that you just downloaded, then select the SD card or ‘target’ you want to flash to. Then simply press ‘Flash!’ and the process will begin.

This will take a few minutes to complete. Once done, it’s time to set up the wifi and ssh on the SD card before booting it up with the Raspberry Pi. Navigate to your SD card in the file exlporer. If you can’t see the contents of your SD card after flashing, it is likely because Linux uses a different file system than Windows.

To get around this, I downloaded Ext2fsd which allows you to view Linux file systems on a Windows computer.

I also suggest downloading Notepad++ for the next few steps, which can be found here.

Once you can view the contents of your SD card from the file explorer, open up Notepad++ or whatever text editor you are using. Create a new empty file and name it ‘ssh’ and save it to your boot partition of the SD card.

This enables SSH on your Raspberry Pi.

Now create a new file called ‘wpa_supplicant.conf’ on the same boot partition. The contents of this file will allow the Raspberry Pi to connect to the WiFi.

Simply paste the following into the wpa_supplicant.conf file









Place the name of your Wifi inside the double-quotes of ssid, and the password to access that Wifi inside the double quotes of psk.

Save that file and eject it from your computer.

Plug the SD card into the bottom of the Raspberry Pi and power it on with your Android power cable. Your Raspberry Pi should shortly connect to the internet if everything was set up correctly. The problem is we do not know the IP address to ssh into.

Download Advanced IP Scanner here, which allows you to search for all the connected devices on your local network.

Open up the command prompt with cmd and then type ‘ipconfig’. Under ‘Wireless LAN adapter Wi-Fi:’ look for the IPv4 IP Address. My IPv4 address was so the subnet my network is using is 192.168.0

Open up Advanced IP Scanner and type this “”. Replace the 192.168.0 beginning with whatever your subnet is. Below is an example if the output.

Look for an IP address that has the Manufacturer as ‘Raspberry Pi’. In this case, the IP address is for my Raspberry Pi.

Once the IP address is known we can ssh into it. To do this, I use putty but you can use whatever SSH client you prefer.

Open up putty and type the IP address of your RPi.

Then hit “OPEN”.

The username for a newly install Raspberry Pi is pi and the password is raspberry

5. Install the dependencies

We are now down the home stretch and just have to install the dependencies to run the code. This can be very painful if done incorrectly. There are many outdated guides for installing opencv on a raspberry pi that do not work. Thankfully, all we need to do to get opencv running is these two commands below.

Installing opencv with apt-get fetches all the opencv dependencies for you automatically.

Run these commands in order:

sudo apt-get update 

     sudo apt-get install python3-opencv

The installation of opencv will take some time. After it finishes, you can check that it succeeded by typing in the terminal:

  •      python3 
  •      import cv2
  •      exit()

If you were able to import cv2 without any errors, you are good to go.

Next we need to download some dependencies for our eye blink safe

  • sudo apt-get install git
  • git clone
  • git clone

The LCD repo is a python library that allows us to easily write text to the LCD screen. CD into the lcd repo and run the following command:

  • sudo cp /usr/lib/python3/dist-packages

Next install pip3, which is a python package handler for python3. After pip3 is installed we have a few python packages to install.

  • sudo apt-get install python3pip
  • sudo pip3 install matplotlib 
  • sudo pip3 install imutils
  • sudo pip3 install RPi.GPIO
  • sudo pip3 install smbus

Now we need to ensure the LCD screen is working correctly. Go back to the lcd directory and run:


If you are not seeing output on your LCD screen, you need to rotate the potentiometer on the back of the LCD screen with a small screwdriver until text becomes visible.

Now we need to modify some raspberry pi configurations with:

sudo raspi-config

From here we need to enable I2C and the Camera. Go down to ‘Interfacing Options’, click into ‘Camera’ and ‘I2C’ and enable both of those. Restart the raspberry pi after this has completed.

Once it boots back up, navigate to eyeblinkpassword repo.

Lets first test the script by itself to make sure it is working. There is a variable in the script called isEyeBlinkSafe. If it is set to False, only the camera will be operating (and not the LCD screen or the solenoid). Run the script with


If this is working, lets enable the isEyeBlinkSafe variable to True. Open up the


Find the variable and change it to True. Also, feel free to change the password to whatever you want. Password digits can be either L (for Left eye closed, R for Right eye closed and B for both eyes closed).

Exit by typing CTRL+X and saving the file.

Now run the again:


The script should now be running. You can now try unlocking the safe with your eye blink password! Once you match the password, the solenoid will be unlocked for four seconds before re-locking.

Congratulations, you now have a computer vision powered eye blink safe!