SmartVault: Arduino-Controlled 3D Printed Lockbox
by daya11 in Circuits > Arduino
106 Views, 0 Favorites, 0 Comments
SmartVault: Arduino-Controlled 3D Printed Lockbox
I designed and built SmartVault, a 3D-printed lockbox controlled using an Arduino Nano, servo motor, button and two LEDs.
When the button is pressed, the servo moves the lid mechanism while the LEDs show the state of the box: green when open and red when closed.
This project combines CAD modelling, 3D printing, electronics, mechanisms and microcontroller programming into one working design.
Supplies
electronic components:
- arduino nano
- nano expansion board
- servo motor
- push button
- green and red led ( 1 each )
- 2 resistors
- jumper wires
- USBC cable
construction:
- 3D printed smart vault enclosure
- 3D printed lid
- hinges
- screws
- servo/lid mechanism components
software + tools:
- arduino IDE
- 3D printer
- Screwdriver / drill
ELECTRONICS + CODE
Starting with the code:
The code:
#include <Servo.h>
Servo lockServo;
const int buttonPin = 2;
const int greenLED = 3;
const int redLED = 4;
bool openState = false;
void setup() {
lockServo.attach(9);
pinMode(buttonPin, INPUT_PULLUP);
pinMode(greenLED, OUTPUT);
pinMode(redLED, OUTPUT);
lockServo.write(60);
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
}
void loop() {
if (digitalRead(buttonPin) == LOW) {
delay(50);
while (digitalRead(buttonPin) == LOW) {
}
openState = !openState;
if (openState) {
lockServo.write(120);
digitalWrite(greenLED, HIGH);
digitalWrite(redLED, LOW);
} else {
lockServo.write(60);
digitalWrite(greenLED, LOW);
digitalWrite(redLED, HIGH);
}
delay(200);
}
}
Pin connections on the expansion board are:
D2 = push button
D3 = green LED
D4 = red LED
D9 = Servo signal
Insert the Arduino Nano securely into the Nano expansion board.
Connect the servo signal wire to D9, with its power and ground wires connecting to the corresponding power and ground connections on the expansion board. Then connect through a green led to D3 and the red LED to D4 like mentioned above, using a 220 resistor with each LED. Then connect the push button to D2.
Finally connect the Nano using the USBC/data cable. Do not permanently install everything yet. It's better to upload the code and check that the complete circuit works before finalizing everything.
Test the circuit before putting it inside the enclosure. When first powered, the smartvault should stay closed. The servo should be at 60°, the red LED should be on and the green LED should be off.
Press the button once, the servo should rotate to 120, the red LED should switch off and the green LED should switch on.
Press the button again. The servo should return to 60° and the red LED should turn back on. if all three components respond correctly the electronics are ready to be installed.
CAD
My original design used a lot of separately printed shell components, but after testing, I redesigned it to reduce material waste and create more space for the electronics.
The most effective design includes:
- A recessed section for the electronic components that acts as a shelf
- A mounting space for the Arduino and the expansion board
- An opening for the button
- Two more openings for the LEDs
- A side opening for the data cable and USBC connection
- And mounting points for the lid hinges measured according to the hinge hole size
By doing this we not only minimize material waste, but can also power and program the Arduino without taking the box apart.
Once the enclosure has been fully modeled, export the final parts from Fusion 360 as an STL file and prepare them in your preferred slicing software. It's best to print the main enclosure and lid separately. Before printing check that the openings for the buttons, LEDs and USB cables are correctly sized for your components. The recessed electronic shelf should have enough space for the Arduino nano, expansion board and wiring.
After printing:
- Clean up any of the excess supports or material
- Test the fit of the Arduino and expansion board inside the section
- Check that the LEDs and buttons fit through their openings comfortably ( if not before reprinting, try drilling the opening bigger and filing it down )
- Check that the USBC cable can be connected to the side opening
- Align the lid and hinges before installing any electronics ( do not connect them yet, just see that they align)
It's a lot easier to make small adjustments at this stage than after everything's been wired and assembled.
Before installing the electronic components, assemble and test the circuit on its own. This makes it much easier to find wiring problems and tackle them before final assembly.
TROUBLESHOOTING
Once everything has been fully tested carefully place the electronics into the enclosure in the space designed for them. Position the Arduino and expansion board on the recessed electronic shelf, keeping enough space around them for the jumper wires. Feed the two LEDs through their openings and position the push button in its opening.
One problem that may happen is that when you press the button it may not be very sturdy. It may push back a bit into the box, if so try adding a little bit of tape to the back of the button to secure it inside the box. Also make sure the USBC Port remains accessible to the side of the enclosure. Place the servo close to the lid mechanism so its movement can be transferred to the lid without pulling tightly on its wires.
Try to keep the wiring inside the recessed section so that it does not interfere with the contents of the box or moving the lid, this also keeps the looking clean and neatly designed.
After that, align the lid with the enclosure and attach it using the hinges and screws. You might need to adjust the hinge hole sizing slightly depending on the dimensions in fusion 360.
Position the Servo so that it rotates between 60 degrees and 120 Degrees, then connect the servo arm to the moving section of the mechanism and test the movement before securing everything permanently. Adjust the degrees as necessary.
The exact position may need some adjustment depending on the dimensions of your printed parts and hinge placement. I tested the mechanism by moving it slowly during the first test to make sure nothing catches against the enclosure, and it helped with troubleshooting.
Once the lid opens and closes correctly and cleanly, secure the servo and any other components.
Run a few open and close cycles before considering the project fully finished, just to make sure that everything is running smoothly. If the servo does not respond even though the code is uploaded correctly, check that the Arduino Nano is seated properly in the expansion board and that the USBC / data connection is secure before doing anything.
If an LED doesn't light up, check the resistor and jumper wire connections. If not, replace the bulb. If the servo moves but the lid does not open or close correctly, adjust the servo position or the connection between the servo arm and Lid mechanism. Once everything works consistently, secure any remaining loose components and complete the final assembly.
And then you have a working SmartVault.