Box That Opens When Scared

by acusick1 in Circuits > Arduino

43 Views, 0 Favorites, 0 Comments

Box That Opens When Scared

Screenshot 2024-04-03 at 2.00.29 PM.png

This box is designed to open and then automatically close when there is a loud noise. This no-touch operation is part of a class project

Supplies

  • Adafruit CPX
  • Arduino Servo motor
  • Arduino Servo motor horn
  • Poster board
  • Tape
  • Exacto Knife/Box Cutter
  • Three alligator clip wires

Assemble the Box

IMG_5919 Large.jpeg

Using the box cutter, cut 6 squares measuring 5" x 5" out of the posterboard. Assemble the sides and bottom of the box using tape or hot glue.


Attach the lid with tape to only ONE SIDE of the box.


The finished product should look- and open like in photo above

Coding the Servo

Screenshot 2024-04-03 at 2.09.46 PM.png

To code the Adafruit servo, start by going to the Adafruit makecode website and creating a new project.

Next to the interactive servo display, a list of functions you can use and edit to code your servo is displayed. If you cannot see the dark green "Servos" functions, install the servo package by clicking on the menu below the function menu and selecting servos.


Pull out a 'loud sound' block. Inside that block, place servo controls at 90 degrees and zero degrees with a pause in-between. This makes it so that when a loud sound plays, the servo will rotate to 90 degrees, pause, and then return to the original position.

The 'set all lights blocks' are optional, but are a good indicator on whether or not the CPX is picking up sound. You can also add other blocks and functions, such as sounds or additional functions as well.

Wiring and Connecting the Servo

IMG_5865 Large.jpeg

Using the alligator clip wires, attach the white clip to the GND, the blue clip to A1, and the purple clip to VOUT on the CPX. These wires provide a regulated amount of energy to the servo that lets it rotate the horn.


To attach the CPX to the Servo, connect the white to brown, blue to orange, and purple to red.


Depending on the colors of your wires and design of your servo, this step may take some trial and error.

Connecting Servo to Box

IMG_5918 Large.jpeg

Using the box cutter, cut a servo-sized hole on the side of the box that the lid is attached to, or the back of the box. Make sure the hole not only fits the servo but is close enough to the lid where the horn will be touching the servo when it moves.


Place the servo inside the hole, making sure the wires are on the inside and the servo horn is inside. Secure the servo in the hole using tape or hot glue.

Finalizing and Troubleshooting

FCOSTPCLUJTIOLP.png

Hopefully, once you connect the CPX and the Servo and insert the code into the CPX unit, your box will open upon hearing a loud sound.


If this is not the case, there are a few areas that may need to be checked to ensure the box functions as intended.


Wiring

  • As stated before, if the colors of your wires do not match the ones I referenced in Step 3, you may need to do some trial and error to find which alligator clip wire connects to which servo wire
  • Also, regardless of the order of your wire connections, make sure that the alligator clips are securely connected to GND, VOUT, and A1 outputs on the CPX.

Coding

  • Make sure to cross-reference your AdaFruit program with the code outlined in Step 2.
  • If you designed your program to include other functions or react to different inputs, it may be having an impact on the functionality of your code. I recommend using the built-in AdaFruit CPX simulator next to the functions menu to check that the CPX works as intended, also adding a lights function to turn on when the function works as intended, will give you a visual cue in the simulator and in real-life testing.

Box not Opening

  • Check to make sure the servo and CPX are properly connected
  • Make sure that you have attached the servo in the back of the box, close enough to the lid that it will make contact with it, and open the box when activated. Adjust position of servo as needed
  • Alternatively, there is a chance the servo may have been inserted upside-down. This makes the servo horn rotate downwards and away from the lid, rather than towards and against it. This can be remedied by repositioning the servo, or adjusting the code to rotate the horn -90 degress instead of 90 degrees.
  • Try being scarier/louder