The Shy Magic Box
![IMG_20230510_113131881_HDR (2).jpg](/proxy/?url=https://content.instructables.com/FM3/W9GK/LHXFJ24C/FM3W9GKLHXFJ24C.jpg&filename=IMG_20230510_113131881_HDR (2).jpg)
Project Made By: Katelyn H. HKU game design 1D.
This Magic treasure chest stays slightly open with an omninous red glow coming from the inside. Should one get to close however, the box will fully close and it's light will fade step away again and it will once again open.
The purpose of this design is mainly to be a fun toy. An eery red glow entices people to approach and then the box suprises them by shutting down; (the reeasong and in many cases they'll experiment why it did that, often waving their hands at it and seeing how it reacts. (Based on my playtesting at least which was really fun).
Downloads
Supplies
Electronic Compenents:
- Ultrasonic Sensor HC-SR04.
- Red LED light..
- SG90 9G micro servo motor.
- Bread or circuit board.
- 11 male to male jumper wires.
- 220 ohm resistor.
- Arduino uno R3
- USB 2.0 cable fully rated 80 ᐤC 30V.
Materials for building the mechanism inside the box and the box itself:
- 3mm thick MDF.
- Small nails and screws.
- Woodglue or PVA.
- Superglue.
- Cardboard (used for decoration so not strictly necessary).
- Two 2.5x2cm Hinges.
Tools and machinery needed to put everything together:
- Lasercutter (can be subituted by simply sawing the mdf with a woodsaw but this will give a worse finish and less stablity).
- Soldering iron and solder.
- Wire stripper.
- Hammer.
- Small Philips screwdriver.
- Computer for running the code.
Electronics
![IMG_20230424_110747376_HDR.jpg](/proxy/?url=https://content.instructables.com/FHC/H76E/LHXFJ3AG/FHCH76ELHXFJ3AG.jpg&filename=IMG_20230424_110747376_HDR.jpg)
![Screenshot 2023-05-21 220021.png](/proxy/?url=https://content.instructables.com/FSV/TG9Y/LHXFJ3AK/FSVTG9YLHXFJ3AK.png&filename=Screenshot 2023-05-21 220021.png)
![Screenshot 2023-05-21 234513.png](/proxy/?url=https://content.instructables.com/FWZ/GADD/LHXFJ81D/FWZGADDLHXFJ81D.png&filename=Screenshot 2023-05-21 234513.png)
We'll start with the electronics because it will help us determine the size of box we'd like.
Start by building and placing all relevant items according to the schematic (not the photo).
Make sure that the Ultrasonic Sensor is facing outwards away from the wires.
(See photo of my first test of building the electronics and mechanism)
Now download the Arduino IDE program, make a new sketch, connect the Arduino and the program using your USB 2.0 wire and making sure that you've selected the board you're using in the program/sketch.
Now copy the following code into the sketch:
#include <Servo.h>
const int trigPin = 3; // the pin the echo is attached to
const int echoPin = 2; // the pin the Trig is attached to
int led = 5; // the PWM pin the LED is attached to
int brightness = 120; // how bright the LED is
Servo myservo; //connnects the servo motor
float duration, distance; //These floats determine the duration and distance of the sonar waves
void setup() {
pinMode(LED_BUILTIN, OUTPUT); //Allows for the LED to be turned on and off.
myservo.attach(4); // attaches the servo on pin 4 to the servo object
pinMode(trigPin, OUTPUT); //Sets the trigPin as output for the ultrasonic sensor
pinMode(echoPin, INPUT); //Sets the echoPin as input for the ultrasonic sensor
Serial.begin(9600); //Starts the serial communication.
}
void loop() {
digitalWrite(trigPin, LOW); //Clears the trigPin
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); //Sets the trigPin on HIGH state for 10 micro seconds
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
//Determines how close an object is by converting the time in between HIGH pings to distrance in cm
duration = pulseIn(echoPin, HIGH); //Reads the echoPin, returns the sound wave travel time in microseconds
distance = (duration*.0343)/2; //Calculates the distance
Serial.print("Distance: "); //Prints the distance
Serial.println(distance);
delay(100);
analogWrite(led, brightness);
if (distance <= 30) { //If an object is within 30 cm the following wil happen:
myservo.write(90); //the servo will turn 90 degrees closing the box
digitalWrite(LED_BUILTIN, LOW); //the light will go out
delay(15); //slight delay to prevent potential problems such as jams.
} else{ //otherwise the box will stay open with the light on.
myservo.write(0);
digitalWrite(LED_BUILTIN, HIGH);
delay(15);
}
}
Test it by first pressing the verify button, if no issues arrise press the upload button and see if it works.
Troubleshoot and figure out how you want the layout of your electronics to be.
Important: Make sure that your servo motor is able to lie on it's side with the shown accesory pointed upwards at a 90 degree angle
Building the Box
![IMG_20230507_132839616_HDR.jpg](/proxy/?url=https://content.instructables.com/FFN/RJE2/LHXFJ8A6/FFNRJE2LHXFJ8A6.jpg&filename=IMG_20230507_132839616_HDR.jpg)
Now that you have your electronics ready sketch out where everything will be including a hole for the USB cord and an opening for the sensor to determine how big you want your box to be and to make the appropriate lasercutting template on the site: https://www.makercase.com/#/
I recommend making 2 open boxes with finger edge joints size 9 with 3mm thick MDF
The main box with height 100mm, depth 150mm, and lenght 250mm.
and the lid which uses height 20mm, depth 150mm, en lenght 250mm.
Before you glue everything together make sure to mark where everything will go and cut out the holes for the sensor and usb connection.
Glueing
![IMG_20230507_123952131_HDR.jpg](/proxy/?url=https://content.instructables.com/FEX/UC6Q/LHXFJCWD/FEXUC6QLHXFJCWD.jpg&filename=IMG_20230507_123952131_HDR.jpg)
![IMG_20230507_124124296_HDR.jpg](/proxy/?url=https://content.instructables.com/FDM/HVHC/LHXFJCYB/FDMHVHCLHXFJCYB.jpg&filename=IMG_20230507_124124296_HDR.jpg)
One final thing before you glue the box together:
Mark where the hinges will go on the backside and glue them on using super glue (I don't recommend using nails or screws in this case since the material is so thin).
Now you can glue the box together and place the electronics in the designated spots.
Making the Mechanism
![IMG_20230508_151555286_HDR.jpg](/proxy/?url=https://content.instructables.com/FGW/K3XC/LHXFJDQO/FGWK3XCLHXFJDQO.jpg&filename=IMG_20230508_151555286_HDR.jpg)
Now make a small wooden support (11 cm long 0.5 cm wide 0.1 cm thick) and connect it by drilling a hole the size of a nail at the bottom and top of the support. Prepare a seperate 1x1cm 0.1cm thick piece of wood and also drill a hole into the middle of it
Put a nail through the top hole of the servo accesory and the bottom hole of the support.
Put another nail through the top hole and the small wooden piece.
Glue your servo with the support and wooden piece on the bottom of the inside of the chest near the front using superglue.
Let the support hold up the lid of the box.
Congrats your Shy Magic Box is DONE! connect it following the steps in step 1 and it should open and close accordingly
Reflection and Recommendations
![IMG_20230424_104338730_HDR.jpg](/proxy/?url=https://content.instructables.com/FRH/6AJ6/LHXFJFZM/FRH6AJ6LHXFJFZM.jpg&filename=IMG_20230424_104338730_HDR.jpg)
What did I learn from this project?:
-Lasercutting and workplace safety.
-The coding of physical electronics and not just digital games (especially the Ultrasonic sensor was hard to work with).
-Soldering.
-Test and plan out your design ahead of time (which I partially did but forgot to apply to the way the servo would be attached which ended up with me using glue intstead of a more elegant solution.)
The original plan for this project was to make a minecraft Chulker box which later went on to inspire this box. I've shared some of my prototypes already but here's another (see image): this one was purely focused on the servo and sensor and I later added the LED to inspire people to approach the box.
Ways this design could be improved:
- if you wish to improve upon this design, such as making the Ultrasonic sensor less obvious I recommend covering the sides of the box with a thin cloth (it has to be thin otherwise the ultrasonic sensor won't work). This will add to the suprise factor of the Magic Box.
- Adding a little monster over the support beam as a little added flavor.
- Adding a wooden servo holder so the motor can be removed and added without ripping it out and re-glueing it.
- Spice up the box to your liking! (I wanted to make mine look more like a treasure chest but didn't get around to it.)