Go Down

Topic: Arduino rain noise generator, anyone? (Read 400 times) previous topic - next topic

louwin

I have trouble staying asleep. So I have paid for an App on my iPad that simulates rain noise. I switched off the thunder option as I'm only interested in the random rain noises.

This has been a good solution and has improved my sleeping butis a terrible a misuse of an iPad.

I wondered if anyone had written a sketch (and is willing to share)  using an Arduino to generate rain noises. I don't really want to playback a 10 hour WAV file off micro SD or such nor repeated playback of a snippet from memory.... Just switch it on, have a sleep and switch it off in the morning....

I have Unos, Megas, Dues and Nanos. I have ordered a couple of small speakers. I don't want any fancy options or controls. A volume control would be nice but not really necessary.
 
Idealy I would love to just use a Nano and a speaker but am not averse to using a transistor.
I have searched this forum and YouTube etc but haven't found a solution that just uses this minimum componentry. I would prefer not using a sound chip.

I am a retired programmer so would be happy to write the code myself but am clueless where to even start.

Thanks in anticipation   :)
Newbie, bought a Uno because I had a $10 Paypal voucher  :)

I live in Perth, Western Australia.

Paul__B

I don't really want to playback a 10 hour WAV file off micro SD or such nor repeated playback of a snippet from memory.... Just switch it on, have a sleep and switch it off in the morning....
Since that is the simplest, fastest and probably cheapest approach and an Arduino is not required at all, I ask - why not?

jremington

Google "diy electronic rain noise generator" for simple circuitry. Some examples are discussed here.

DVDdoug

The Due has a DAC.  The Uno, Nano, and Mega don't have true-analog outputs.   You can "fake it" with the TMRpcm library, but that's actually PWM and if you don't filter it, PWM can do "nasty things" to an amplifier.

So, I'd recommend the Due, or an audio shield.   And, you might be able to find an audio shield that can loop without the Arduino.  (An audio shield just uses the Arduino as a controller and it can play sound files without it.)

White noise is "random data" and I believe digitalWrite(random(255)) in a tight loop will give you white noise.   But that's not "rain".   You can make pink noise by filtering white noise, and that's more natural sounding (less "harsh") but it's not easy to make a pink noise filter and it's still not rain.

Quote
and a speaker but am not averse to using a transistor
You can't directly-connect a regular speaker.   The minimum impedance/resistance is 125 Ohms (40mA and 5V).    You can put a resistor in series, but that will reduce the volume and it probably won't be loud enough.

You can use regular "powered" computer speakers.

You can't make a linear amplifier out of a single transistor.   There are lots of audio amplifier chips if you want to build an amplifier, or you can buy a small amplifier.

MrMark

#4
May 23, 2019, 03:34 am Last Edit: May 23, 2019, 03:35 am by MrMark
One can get white noise simply by toggling an output pin at random intervals. 

Code: [Select]
// Generate white noise by toggling audioPin at random intervals

#define audioPin 8

void setup() {
  pinMode(audioPin, OUTPUT) ;
}

void loop() {
  digitalWrite(audioPin, LOW) ;
  delayMicroseconds(random(1000,3000)) ;
  digitalWrite(audioPin, HIGH) ;
  delayMicroseconds(random(1000,3000)) ;
}

Playing this through a passive buzzer or small speaker with a 180 Ohm serial current limiting resistor is about as loud as one would need for a sleep aid.

louwin

Since that is the simplest, fastest and probably cheapest approach and an Arduino is not required at all, I ask - why not?
Because, from my experience, the microSD readers usually fail, sooner rather than later. I have 5 Dues with 5 3.2" LED screens with microSD readers inbuilt. Two of those readers have failed on me so far. And this is from the display being on for a coupla hours at a time. I expect the rain noise generator to be on 8 or 9 hours every night.
Out of curiousity, how would you run a microSD reader without an Arduino? Would one of these be enough?

https://www.ebay.com.au/itm/TF-Card-U-Disk-Mini-MP3-Player-Audio-Voice-Module-Arduino-DFPlayer-Mini-Board/

Or would you need something different?
Thanks for your response   :)
Newbie, bought a Uno because I had a $10 Paypal voucher  :)

I live in Perth, Western Australia.

wvmarle

I have had MicroSD cards fail occasionally, but never a reader. And even that's been a long while. With normal use the things are pretty reliable.

The DF Player Mini is a really cool mp3 player. It can be used standalone (it has buttons for volume and track selections), and it can drive a 3W 4Ω speaker directly. That's easily as loud as even a black rainstorm during typhoon battering our windows. It plays mp3 and a host of other sound formats.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

louwin

#7
May 24, 2019, 12:22 pm Last Edit: May 24, 2019, 12:23 pm by louwin
Thanks for your replies, one and all. Went on eBay to look at sound chips, MP3 players etc and saw a "9 sounds" box for half the price of a Due. Ordered it and now waiting on a "slow boat from China"   :)
Newbie, bought a Uno because I had a $10 Paypal voucher  :)

I live in Perth, Western Australia.

Go Up