Used during creative makers sound activity to show electronic ways of making sound.

IMG_7949.jpeg

Breadboard with both photodiodes and buttons.  Photodiodes in 3D printed piece can be triggered with music box strip.

Breadboard with both photodiodes and buttons. Photodiodes in 3D printed piece can be triggered with music box strip.

Breadboard with buttons and RP2040 module to send serial strings.

Breadboard with buttons and RP2040 module to send serial strings.

Here is one way to produce sounds in response to button pushes and light changes. The button is attached directly to a microcontroller input pin on one side and to ground on the other (right side of figure). The microcontroller is set up with in an internal input pullup resistor so that the input is normally high and goes low when the button is pressed.

Circuits for microcontroller input of button presses and phototransistor responses to light.

Circuits for microcontroller input of button presses and phototransistor responses to light.

For the phototransistor (left side of figure), the input pin is left floating - no internal resistor attached. In low light, little current flows through the phototransistor, and the input voltage is high. With light input, the current increases and pulls the input down. Note that an internal resistor would not allow this to work.

To create sounds, I’ve written code for the microcontroller to send serial strings, using the print() function, when inputs go low.

The computer is running local python code, using Thonny if desired, to recognize strings and play wav files, using the pygame library.