Introduction: Light Box Lock

Now, you have heard of boxes that open when they detect a knock. let's make one that opens when you shine your phone LED on it!

No? really? it's actually pretty handy and can be used as a party prop or the ultimate package for a christmas gift. Don't worry. I'll grab your hand and guide you through the process of building this magical box.

DISCLAIMER: This project does work, however you should use a separate power source for the servo. keep this in mind when building this. Do as i say/write don't do what you see!

Step 1: Getting All the Things!

In order to build this amazing box of secrecy you need to have:

-An arduino microcontroller

-1000 Ohm resistor

- 1 Light Detecting resistor (LDR) can be any size or shape as long as it detects normal indoor / outdoor light

- 1 9V battery or powerbank to power your arduino (you can also use your laptop to power it and read the serial communicator.)

- 1 microservo or motor that is capable accurate movement

- 1 completely custom and awesome box with a hinged lid

- 1 some spare metal

- 1 piece of wood cut like the pictures above suggest (either figure saw or lasercut)

And lastly but most importantly:

- 1 gaint roll of duct tape

Links to be added later

Step 2: The Box

The box you use can basically be any box that hinges on one side.

where did i get my box? A friend of mine is a carpenter and was an awesome enough to make this box for me! I added some hinges to it and installed the lid.

If you want to know how to make a box like this (or a better one) look at this instructable: https://www.instructables.com/id/How-To-Make-A-Wooden-Box/

Step 3: Wiring It

The wiring for this little guy really isn' anything special. it uses a simple voltage divider circuit for the light sensor and an even less complicated circuit for the servo.

This is the point where my box doens't follow the directions I provide. I don't have a separate power supply for the servo so i have to use the supply points on the arduino. The problem with this is that, when the lock gets any sort of load on it, it starts to draw way to much current for the arduino causing the arduino to crash. please keep this in mind.

The solution to this is this layout. using a 6V (1A) powersupply to power the servo as shown in the 2nd image

Step 4: Coding It

Now this program switches between open and closed and uses the delay(); command in the arduino IDE. It would be better to use a program that uses the millis(); command but it would also make it a bit more of a nightmare to code it.

The code lives here in text but you can also download the .ino file here

/* - The Flashbox v1.0.0 - */

/* * Author: Frank Tuk * Date op upload: 9-1-2018 * Please feel free to use this program in your products * *

/Servo related #include Servo lockservo; // adding a servo to the program called: LockServo //Connection variables int servo = 9; // Pin used to tell the servo what position to go to. int sens = A0; // Pin used to measure the value of our light sensor.

//variables for the program. int sensval = 0; // This variable is used to store the value of the light sensor. int sensval_old = 0; // You guessed it, this one is used to store previous values. boolean state = false;// Saves the state of the lock, switches it between false and true (true being open and false being closed) int val = 10; boolean servoState = false;

void setup() { Serial.begin(9600); //Starting the serial monitor so we can look inside the arduino's brain. pinMode(servo, OUTPUT); //making sure the pin for the servo knows that it needs to output. pinMode(sens, INPUT); //turning the sensor into an actual sensor lockservo.attach(servo); // Tells the arduino to what pin our servo is connected

// Now, to ensure that the box knows where it's at. lockservo.write(165); delay(1000); lockservo.write(10); }

void loop() { sensval_old = analogRead(sens); Serial.println(""); Serial.print("Measuring..."); Serial.println(sensval_old); delay(500); if (sensval_old > 700){ state = !state; servoState = !servoState; sensval = analogRead(sens); Serial.print("lock changes state at:"); Serial.println(sensval); delay(1000); } else{ delay(250); }

if ((servoState == false) && (val == 10)){ val = 165; lockservo.write(val); delay(500); Serial.println("Lock closed, closing servo"); } else if ((servoState == false) && (val == 165)){ delay(250); Serial.println("Lock closed"); } else if ((servoState == true) && (val == 165)){ val = 10; lockservo.write(val); delay(500); Serial.println("Lock open, opening servo"); } else{ delay(250); Serial.println("Lock open"); } }

Step 5: Inserting the Electronics Into the Box

Installing the servo lock and sensor into the box is quite simple.

first: screw the piece of wood for the latch lock onto the servo

second: install the servo into the block and screw this block into the bottom of the box.

third: screw the catch into the lid

I choose to dump my breadboard inside the box and have the remaining wires to the arduino go between the lid and the box. this just makes it easier to close the lid and still connect to the arduino. (you know, just to ensure that i don't lock myself out.)

Step 6: Testing It

Yes! you do have to test it. that's where i found out that i couldn't supply enough current through the arduino and should have used a separate power supply for the servo.

Why did i come across this during the assembly and not earlier? A: I was very impatient. B: the real reason.

When i tested the setup, i tested it without the lid to see what the latch was doing. When i then tested it again with the lid i found out that the servo draws more current under load.

So. be ABSOLUTELY sure that you have a completely flawless working setup to make sure you don't lock yourself out of your own box.

Step 7: Profit! and Conclusion

That's it! you are done! And man, give yourself a pat on the back because you managed to get through this instructable!

If you have any questions or comments be sure to contact me!