Personally, I really have no issue with swearing - words are just words, but many people don’t share that view, so I understand why they did it.
The problem for me is that now, whenever someone swears, there’s a chorus of people shouting “Swear Jar!” at the person who swore. This, to me, is far more annoying than the swearing ever was.
It give me an idea though. What if the phrase “Swear Jar”, was taken more literally - a jar which swears at you when you put money in?
So, yeah, that’s the flimsy premise of this project. Read on for the full write up, or just watch the video of it in action below. (It should really go without saying that the language in the video may be unsuitable for some people..)
The Jar
As a base, I picked up one of those basic coin-counting money boxes often found that those ‘gadget shops’ which tend to open up in shopping centers selling a bunch of battery-operated plastic junk for a few weeks before they inevitably fail.
The coin mechanism is nothing special, essentially a slider which completes connections at different points to detect different coin values. there's not really anything else of value in the circuitry, it's all hidden behind epoxy blobs, so I scrapped everything else.
Audio
To provide the audio, I’m using an old MP3 player that I had in my junk bin - it’s essentially a 512MB memory stick with three control buttons and a headphone jack.
I enlisted a friend's help in trawling through movie clips on YouTube to get audio clips of profane movie quotes (this is where the previous post came from). The end result being a bunch of clips, all 3 seconds in length.
I wired up a small speaker from the junk bin. Fortunately the internal amplifier in the MP3 player was powerful enough to drive the speaker directly - as it's originally designed just for headphones, I thought it might not have sufficient power.
Controller
As this is just a novelty project, and I wanted to get it done and in the office before the swear jar idea was forgotten about, so I didn't really have time to delve too deeply into interfacing with the MP3 players circuitry. I opted to simply use a microcontroller to imitate human interaction. Conveniently, all the functionality I need from the MP3 player is obtained from just one button.
I opted for an ATTiny2313, using the arduino cores for convenience, and a relay to toggle the MP3 players button. Source code is below.
Power
Another complexity with this project is although the MP3 player doubles as a USB disk, powering it via the USB port only allows it to be used as a memory stick, and disables the MP3 playback functionality. Therefore the only other way to power the device is via it's AAA battery slot, so I required 2 power rails - 5v to drive the microcontroller, and 1.5v to power the MP3 player. This was achieved by using a 7805 to arrive at 5v for the micro, then using that 5v fed into an LM317 to provide 1.5 volts for the MP3 player. The main power input is 9v, which was originally intended to come from a battery, but at the last minute swapped for a wall supply (because I couldn't find a battery)
Block Diagram
The below shows how the different components fit together. As this is a frivolous novelty project, I'm not going to put together a full KiCad schematic - the most complex bit was the TS7805 and LM317 circuit, but there's plenty of existing documentation for those online already.
Timing is everything
The problem that quickly became evident is that the microcontroller has no feedback from the MP3 player, so cannot tell if a clip is playing, or even if the MP3 player is switched on. This is why the audio clips needed to all be the same length. There is also the issue of switching the MP3 player on, which requires a long press of the button. This is addressed in the setup function of the following code.
Code
int startPin = 2; int emptyPin = 3; int optoPin = 4; int blinkPin = 5; int isActive = 0; void setup() { pinMode(emptyPin, INPUT); pinMode(startPin, INPUT); pinMode(optoPin, OUTPUT); pinMode(blinkPin, OUTPUT); digitalWrite(optoPin, HIGH); delay(1500); digitalWrite(optoPin, LOW); } void loop() { if (digitalRead(startPin)) { isActive = 1; } else if (digitalRead(emptyPin) == HIGH) { if (isActive) { playSound(); isActive = 0; } } } void playSound() { digitalWrite(optoPin, HIGH); delay(100); digitalWrite(optoPin, LOW); delay(3200); digitalWrite(optoPin, HIGH); delay(100); digitalWrite(optoPin, LOW); delay(200); }Limitations
- The MP3 player also has an auto switch-off function that causes it to turn itself off after a short period of time. This means that if no money is put in the swear jar for a while, the next time someone does, nothing happens, and requires the power to be cycled to reboot the whole thing.
- The timing requirements are far too precise - even though all the audio clips used were 3 seconds, over time the slightest variances would add up, causing the microcontroller to lose sync with the audio.
No comments:
Post a Comment