r/microbit • u/elecfreaks_official • 1d ago
We Built a Password-Protected Safe with micro:bit – 3 Wrong Attempts and You're Locked Out! 🔐
We wanted to build something a little more interesting than a regular box made from building blocks, so we turned one into a small password-protected safe.
The idea is simple: use the A and B buttons on a micro:bit as the keys, enter the correct combination, and let a motor open the door. But we also wanted it to behave a bit more like an actual safe, so we added a few extra rules.
The default password is AABB. Each time a button is pressed, the micro:bit records the input and displays how many characters have been entered on its 5×5 LED matrix. It only shows the number of characters, not the actual password.
Once all four characters have been entered, the program waits five seconds and checks the combination automatically. There's no separate submit button needed. If the password is correct, a check mark appears and a PlanetX Smart Brick Motor connected to port M1 on the Nezha Pro rotates 90 degrees counterclockwise to open the door.
Of course, getting the password wrong is part of the fun.
The first two incorrect attempts show a cross on the LED display, giving the user another chance. But make three consecutive mistakes, and the safe gets a little less friendly: the display flashes a warning, then starts a 10-second lockout countdown. During this time, button inputs are ignored. Once the countdown finishes, "TRY AGAIN" scrolls across the display and the safe is ready for another attempt.
We also added a couple of useful controls. Pressing A+B while entering a password clears the current input, so there's no need to start over if you accidentally press the wrong button. After the door opens, A+B rotates the motor 90 degrees clockwise to close it again.
The mechanical part was just as important as the code. We used the Nezha Pro Sport Kit to build the safe body, hinged door, and motor linkage. The door needs to move freely, and the motor's starting position needs to match the fully closed position. Otherwise, even a perfectly correct password won't help if the door gets stuck!
The project uses a micro:bit, a Nezha Pro Breakout Board, and one PlanetX Smart Brick Motor. We used the Nezha Pro's angle-based motor control to make the opening and closing movements 90-degree rotations, rather than simply running the motor for a set amount of time.
It's a small project, but it combines quite a few ideas: button input, variables, timing, conditional logic, error handling, and mechanical movement.
Now I'm wondering what would make this safe more interesting. Maybe a longer password, a different combination system, or even a second condition before the door unlocks?
Would you trust a building-block safe to protect your snacks? 😄



