This week, I designed a box with a very sleepy and angry man in the box. If you open the box and let in the light, he will scream at you.
Making the box
I lasercut the parts for a box with a hinge.
I glued the box lid together for more security. The rubber band just keeps everything together as it dries.
Making the speaker
Connecting the speaker directly to the Arduino produces a very very low sound because the ItsyBitsy cannot provide the current necessary to produce a loud sound. This means I need to amplify the sound!
I first use a wave generator as my amplifier. I connected the Arduino’s audio output on A0 to the input port of the wave generator and then plugged up the output of the amplifier to the speaker.
And here’s how it sounds!
Building my own amplifier with an op-amp
Using an LM386 chip, I got to making my own amplifier.
I soldered up a potentiometer as well which allows me to control the volume of the sound.
Here’s how it sounds:
As you can see, it sounds pretty awful. The reason there’s so much distortion is because there’s a lot of noise on the output ground and not enough capacitors to filter out the unwanted noise. Let’s fix that.
A better amplifier
Here’s how the new amp sounds:
Much much better sounding.
The code
I decided to use digitalio rather than analog because I wanted the box to scream whenver it detected any light, 0 or 1, no particular threshold.
import time
import audioio
import board
import digitalio
button = digitalio.DigitalInOut(board.A1)
button.switch_to_input(pull=digitalio.Pull.UP)
wave_file = open("LoudYell.wav", "rb")
wave = audioio.WaveFile(wave_file)
audio = audioio.AudioOut(board.A0)
while True:
print("Waiting for button press to continue!")
while not button.value:
audio.play(wave)
while audio.playing:
pass
print("Done!")
The Final Result
I switch the button with a photoresistor so that it screams when it detects light.
When voltage threshold (about 1.72 v) is hit, the box screams!