Open box

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

  1. Attach the shield onto the top of the Arduino board.
  2. Using a separate breadboard, connect a 1M ohm resistor to analog pin A0 and GND.
  3. Connect a piezo speaker across the separate breadboard gap, connect one leg to analog pin A0 and the other to GND.
  4. Assemble OpenBox kit but leave the rear cover unassembled.
  5. Turn the servo by hand until the end. Turn it by hand to the position of 90 degrees, fixing the rod-shaped arm along the servo.
  6. Tie a thread to the servo. Pull it through the hole in the middle plate and tie the other end to the lid.
  7. Connect the servo to D9.
  8. Place your Arduino inside the box. Paste the piezo to the inner wall of the box.
  9. Connect Arduino to the computer and load the example ‘OpenBox’. Knock on the piezo to make sure the servo moves.
  10. Connect the 9V battery with a power plug to the Arduino power socket before you assemble the rest of the walls.

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 and lidOpener.
  • 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(), if sensor.knocked() is true, 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.