The connections are as follows:
- VCC on the HC-SR04 to VOUT on the CPX
- TRIG on the HC-SR04 to A2 on the CPX
- ECHO on the HC-SR04 to voltage divider (one end of the two 10k resistors)
- Divided voltage (other end of the two resistors) to A1 on CPX
- GND on the HC-SR04 to GND on the CPX
- Also connect a wire from between the two resistors to GND on the CPX
Speaker + Amplifier:
- PAM8302 A+ to CPX A0
- PAM8302 A- to CPX GND
- PAM8302 Vin to CPX Vout
- PAM8302 GND to CPX GND
- Speaker to PAM8302 output pins (wire color/order doesnt matter)
Start by soldering four wires to the HC-SR04 Distance Sensor. Make your wires long enough to reach from the inside bottom of your pumpkin to the holes you cut for the sensor. For use in future pumpkins, that may be larger, give yourself a little extra length.
Cut and tin four wires for the HC-SR04 Distance Sensor.
Solder the wires to the pins of the HC-SR04.
Slide some heat shrink tubing over each pin and heat with a hot air gun for insulation.
The Echo pin on the sensor outputs a 5v signal, but the Circuit Playground Express (like many microcontrollers) is a 3.3V device. This means you'll need to divide the voltage of the Echo pin with two 10k resistors. For a more in-depth explanation of this setup, check out Kevin Walters' guide on using this sensor with a Circuit Playground Express.
Follow the circuit diagram to connect the sensor to the Circuit Playground express. Solder the wires as shown below.
In most cases, you'll need to extend the wires of your speaker to reach from the hole you cut in your pumpkin to the bottom of the pumpkin, where the Circuit Playground Express will be.
For permanent installation in a fake pumpkin: If your speaker will be inserted into its hole from the outside of the pumpkin, you'll need to feed it through this hole first before soldering it to the Circuit Playground Express.
For temporary installation in a real (or fake) pumpkin: To make it easy to move the whole project to a new pumpkin, add a 2-pin connector between the speaker and the CPX as shown.
Connect the speaker wires to the Circuit Playground Express. Since there is just one speaker in this project, it doesn't really matter which wire is positive and which is ground. Solder one wire to A0 and the other to GND on the CPX.
Plug the battery pack into your Circuit Playground Express (if locating inside) and carefully place the whole circuit inside your pumpkin. Slide the sensor into its holes and the speaker into its hole. If you kept the holes snug, the components should stay in place without additional help.
The Circuit Playground Express and battery pack will sit at the bottom of your project, and it can be helpful to stick the CPX to the battery pack with tape to keep it facing the front of the pumpkin. For a layer of diffusion, place a crumpled piece of white tissue paper or a paper towel in front of the Circuit Playground Express.
When everything is installed, just add batteries and you're ready to play with your Jack-o-Theremin!