OpenBox is an open source box that contains open source electronics. Oh, and it automatically opens when you knock on it.
Materials
- 1 Arduino Uno board
- 1 Education Shield
- 1 breadboard
- 1 piezo speaker
- 1 standard servo
- 1 1M ohm resistor
- 3 jumper wires
- 1 9V battery
- 1 power plug
- Open box kit
- Masking tape
- Thread
Instructions
Code
Find the code in File>Examples>EducationShield>Block4-Robots>Projects>OpenBox
How it works
- The EducationShield and Servo libraries are included.
- The PiezoKnockSensor and Servo objects are declared,
sensor
andlidOpener
. - In
setup()
, the sensor and servo are configured and initialized. - The servo position is set to 60 degrees so that the lid is closed.
- In
loop()
, ifsensor.knocked()
istrue
, it means that a knock is detected and the servo position is set to 0 degrees to open the lid. - The program pauses for 3000 milliseconds so the lid stays open.
- The servo position is set to 60 degrees so that the lid is closed.
- The program pauses for 200 milliseconds.
- If a knock is not detected, nothing happens.
loop()
continues to loop.
Troubleshooting
- Refer to the illustration and double check your connections. Make sure the shield and jumper wires are firmly connected.
- If the lid does not open/close fully, adjust the values in
write()
to fix it. But first, adjust the angle of servo arm and the string to make sure it is long or short enough. - If the box does nothing when you knock, check the reference for debugging piezo knock sensor.
- If it is still not working, see the reference for debugging standard servo.
- Make sure the battery is connected properly so the ON LED on Arduino is on. Test with Arduino connected to the computer and 9V battery disconnected. If it works with the USB cable but not with the battery, there could be something wrong with the battery, change for another one.
Learn by doing
- Make a password knock by setting it to recognize only a certain knock pattern.
- Modify it so that it requires knocking to both open and close the box rather than automatically closing after it is opened.