Pages: [1]   Go Down
Author Topic: The FartBox  (Read 818 times)
0 Members and 1 Guest are viewing this topic.
NY, USA
Offline Offline
Newbie
*
Karma: 1
Posts: 48
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have an idea for a small project. It's basically a small box that sits on your desk. It has one button:


I image that it'll sit on your desk, someone will walk up to it, see it and wonder what the button does. You press it, and it farts. A pretty funny office gag.

It's similar, I guess, to one of those "Hey, that was easy!" buttons that Staples gives away.

I designed up a circuit and it works:



I basically want it to shut off a couple of seconds after you've pressed the button. Who knows how often someone will press the button. I don't want the batteries to die after it's been on my desk for a week.

The image above doesn't show it, but I also just added an LM386 op amp to make it louder, so the circuit has to run off 5V. I really don't want to use a 9V and have to add a 7805, but I might have to to keep it small using a 9V vs several AAs.

So basically what I'm asking is, what is the best option to shut everything off? I've seen this post about powering down the Atmel, but I have the op amp to worry about. I've also seen the Pololu switch which looks awesome and might do the trick, but again, trying to keep it small.

Any ideas on how to shut this thing down after 5 seconds?

Here's the workflow and some video of it in action on my hobby blog if you want to follow along.....
http://kevinrye.net/files/fartbox.php
Logged

NY, USA
Offline Offline
Newbie
*
Karma: 1
Posts: 48
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hum, I found an interesting alternative right here in the forums using a transistor and an optocoupler. Although I don't understand the need for the optocoupler.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I've also seen the Pololu switch which looks awesome and might do the trick, but again, trying to keep it small.

The Pololu switch is a very good way to go. I needed a similar function several years ago and came up with a method to use a small single coil latching relay to perform a manual turn on/ program turn off circuit. I think I paid $1 for the relay on Ebay:

http://img25.imageshack.us/img25/563/08miq7.jpg

The user pushes the momentary push button to start power up, then the micro in it's startup puts a high on the output pin which sets the relay which maintains the power on. Any time the program wants to power off the system it just puts a low on the output pin.

Lefty
Logged

NY, USA
Offline Offline
Newbie
*
Karma: 1
Posts: 48
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That optocoupler gave me an idea. Maybe I could wire one on the output of one of the digital pins and put it in between the supply and the LM386 amplifier. Then when the Atmega turns on, it turns on the Amp. Then I might be able to just put the Atmega to sleep mode and drive pin x low, thus shutting off the op amp?

Something like this:


Of course, I realize as drawn that won't work, but you get the idea (I'm on a lunch break, time is limited). I'll have to work out the resistors and the particulars when I get home.
« Last Edit: December 04, 2012, 12:42:33 pm by ryemac3 » Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17294
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That optocoupler gave me an idea. Maybe I could wire one on the output of one of the digital pins and put it in between the supply and the LM386 amplifier. Then when the Atmega turns on, it turns on the Amp. Then I might be able to just put the Atmega to sleep mode and drive pin x low, thus shutting off the op amp?

Something like this:


Of course, I realize as drawn that won't work, but you get the idea (I'm on a lunch break, time is limited). I'll have to work out the resistors and the particulars when I get home.

I suspect you will find few opto-isolators where it's output transistor can directly support too high a current draw from the device you are trying to power, however the datasheet is your friend and has the last word on the matter. Of course you can have the opto output transistor control a higher power transistor that could handle the current you may require.

Lefty
Logged

Show Your Work
Offline Offline
Edison Member
*
Karma: 14
Posts: 1100
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's similar, I guess, to one of those "Hey, that was easy!" buttons that Staples gives away.

Staples doesn't give those buttons away.  They charged me $5.99.  Jerks!  I bought one for a similar project.  I am taking an ATTiny85 and one of these: https://www.sparkfun.com/products/9534 to play whatever is on the SD card in random order, 1 or a thousand AD4 files.  I have it on a breadboard and it works great, just haven't updated the code so it sleeps and conserves the battery correctly yet or put it into my now disassembled Easy Button.  The Easy Button is roomy once you remove their HUGE leaf spring and replace it with some smaller conventional springs.
« Last Edit: December 04, 2012, 01:17:02 pm by JoeN » Logged

I have only come here seeking knowledge. Things they would not teach me of in college.

NY, USA
Offline Offline
Newbie
*
Karma: 1
Posts: 48
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, I saw that too. I googled it earlier today after I mentioned it. I was wondering if it would be easier (cheaper) to rip the guts out and repurpose them. I was also curious to see how they did it and how they're running it off 2 AAs. It was at that point I saw that they actually cost $6. I assumed everyone at work that has one was because they got it free with a large order. I didn't think people were actually making a conscious effort to buy one. Why would you want one other than to just rip it open? To each their own I guess.
Logged

NY, USA
Offline Offline
Newbie
*
Karma: 1
Posts: 48
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I tweaked my sketch so that the Atmel powers down after it plays a fart sound.

Code:
#include //audio playback lirary
#include //for sleep
#include //for sleep
#include //for sleep
#include //optional

int buttonOne = 2; // pushbutton connected to pin 2

long randNumber;

//fart 1
const unsigned char fart1[] PROGMEM = {
///very long string of numbers……
};

//fart 2
const unsigned char fart2[] PROGMEM = {
///very long string of numbers……
};

//fart 3
const unsigned char fart3[] PROGMEM = {
///very long string of numbers...…
};

void setup()
{
pinMode (buttonOne, INPUT);
}

void loop(void)
{
randNumber = random(1, 4); // random fart picker

if ((digitalRead(buttonOne) == HIGH) && (randNumber == 1)) {
playFartOne();
}

if ((digitalRead(buttonOne) == HIGH) && (randNumber == 2)) {
playFartTwo();
}

if ((digitalRead(buttonOne) == HIGH) && (randNumber == 3)) {
playFartThree();
}

if (digitalRead(buttonOne) == LOW) { //no button pressed, wait 1.5 seconds then go to sleep //2 seconds is too long between loops if you want multiple presses
delay(1500);
sleepNow();
}
}

void sleepNow(void)
{
//Set pin 2 as interrupt
attachInterrupt(1, pinInterrupt, HIGH);
delay(100);

//specify sleep mode
set_sleep_mode(SLEEP_MODE_PWR_DOWN);

// Set sleep enable bit
sleep_enable();

// go to sleep
sleep_mode();

// Upon waking up, continues from this point.
sleep_disable();
//main loop resumes
}

void playFartOne()
{
startPlayback(fart1, sizeof(fart1));
}

void playFartTwo()
{
startPlayback(fart2, sizeof(fart2));
}

void playFartThree()
{
startPlayback(fart3, sizeof(fart3));
}


void pinInterrupt(void)
{
detachInterrupt(0);
}

Now I'll just have to put something in to power down the op amp. Maybe have a digital pin throw a relay or something.
Logged

Show Your Work
Offline Offline
Edison Member
*
Karma: 14
Posts: 1100
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I tweaked my sketch so that the Atmel powers down after it plays a fart sound.

Code:
#include //audio playback lirary
#include //for sleep
#include //for sleep
#include //for sleep
#include //optional

int buttonOne = 2; // pushbutton connected to pin 2

long randNumber;

//fart 1
const unsigned char fart1[] PROGMEM = {
///very long string of numbers……
};

//fart 2
const unsigned char fart2[] PROGMEM = {
///very long string of numbers……
};

//fart 3
const unsigned char fart3[] PROGMEM = {
///very long string of numbers...…
};

void setup()
{
pinMode (buttonOne, INPUT);
}

void loop(void)
{
randNumber = random(1, 4); // random fart picker

if ((digitalRead(buttonOne) == HIGH) && (randNumber == 1)) {
playFartOne();
}

if ((digitalRead(buttonOne) == HIGH) && (randNumber == 2)) {
playFartTwo();
}

if ((digitalRead(buttonOne) == HIGH) && (randNumber == 3)) {
playFartThree();
}

if (digitalRead(buttonOne) == LOW) { //no button pressed, wait 1.5 seconds then go to sleep //2 seconds is too long between loops if you want multiple presses
delay(1500);
sleepNow();
}
}

void sleepNow(void)
{
//Set pin 2 as interrupt
attachInterrupt(1, pinInterrupt, HIGH);
delay(100);

//specify sleep mode
set_sleep_mode(SLEEP_MODE_PWR_DOWN);

// Set sleep enable bit
sleep_enable();

// go to sleep
sleep_mode();

// Upon waking up, continues from this point.
sleep_disable();
//main loop resumes
}

void playFartOne()
{
startPlayback(fart1, sizeof(fart1));
}

void playFartTwo()
{
startPlayback(fart2, sizeof(fart2));
}

void playFartThree()
{
startPlayback(fart3, sizeof(fart3));
}


void pinInterrupt(void)
{
detachInterrupt(0);
}

Now I'll just have to put something in to power down the op amp. Maybe have a digital pin throw a relay or something.

The sleep technique here could be beneficial to my sketch.  What are the includes that were removed from this code if you don't mind me asking?
Logged

I have only come here seeking knowledge. Things they would not teach me of in college.

NY, USA
Offline Offline
Newbie
*
Karma: 1
Posts: 48
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, that's weird. Didn't catch that. I copied it from my blog post. I guess anything between "<" and ">" gets parsed out when I mark stuff as "code".

It was this:
#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/io.h>

I based it on this tutorial.
Logged

St. Leonards-on-Sea, E. Sussex, UK.
Offline Offline
Sr. Member
****
Karma: 2
Posts: 301
Ancient developer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can buy radio controlled boxes that emit a farting noise. A colleague of mine brought one in where I used to work and hid it next to the coffee-making area. He activated it once when I was making a coffee, and chatting to one of the directors. He didn't say anything and I didn't tell him about it; I couldn't stop laughing. I never did find out what he thought about it, but he did look a bit annoyed.
Logged

Leon Heller
G1HSM

Show Your Work
Offline Offline
Edison Member
*
Karma: 14
Posts: 1100
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh, that's weird. Didn't catch that. I copied it from my blog post. I guess anything between "<" and ">" gets parsed out when I mark stuff as "code".

It was this:
#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/io.h>

I based it on this tutorial.

Thanks!  I am going to try this out with my similar device.
Logged

I have only come here seeking knowledge. Things they would not teach me of in college.

NY, USA
Offline Offline
Newbie
*
Karma: 1
Posts: 48
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, so I have the Atmega powering down after it plays a sound. I also wanted to op amp to power down too. I played around with trying to use a transistor as a switch to turn it off, but my 3904/3906s don't pull enough current to do it. Rather than getting fancy (and using more parts) I reached for one of the relays in my parts box. It was an easy solution. Now the Atmega throws the relay right before it powers down, cutting the supply to the LM386.



Here's a video of it in action.

Now I just need to make an enclosure for it, but that depends on what kind of batteries I want to use.
Logged

Pages: [1]   Go Up
Jump to: