Go Down

Topic: 8-bit gun sound effects without extra hardware? (Read 2 times) previous topic - next topic

polishvendetta

I'm completely new to programming in C, Arduino, and electronic circuits in general.

I'm working on a project to make a Laser Tag like game.  I have found lots of resources using the play tone function, however I was wondering if there was something that could make a gun sound effect without using any extra chips or shields.  I don't need anything real sounding but something better then a simple tone or melody would be awesome.  I'm working with a Nano 328 and trying to keep things as small as possible.

Grumpy_Mike

Without extra hardware all you get is a square wave. Do you not need hardware to drive your speaker?

However, a few cycles of random square waves sounds like a burst of noise and that is a bit like a shot. So try that.

cr0sh


Without extra hardware all you get is a square wave. Do you not need hardware to drive your speaker?

However, a few cycles of random square waves sounds like a burst of noise and that is a bit like a shot. So try that.


It sounds even better when you can vary the amplitude, from loud to soft, fairly quickly; I remember doing this on my TRS-80 Color Computer back in the day, which had a 6-bit DAC; there was a way in BASIC to get the PLAY command to output something akin to random noise, and while doing that while decrease the volume rapidly, you could get the effect of shots being fired, and even something like an explosion. I should hope something like this could be done on an Arduino, perhaps with only a modicum of external parts...
I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

sciguy

All the sounds in the following video were produced by the Arduino:
Only 2 square waves, one for the drums, the other for the melody.
arduino sequencer

So +1 for the square wave idea, including mike's suggestion for noise.  (that was how I made noise on the video)


It was a bit tricky to program, but only because I needed it to be non-blocking.  (I didn't know how to use timer interrupts yet, and I needed to continuously refresh the display.)
If you can use delay() in the sound making (meaning the arduino cannot do anything else during the sound effect), it would be really easy.
Soundcloud page: http://soundcloud.com/beefinator-2
Youtube channel: http://www.youtube.com/user/beefinator14
Old soundcloud page (ran out o

polishvendetta

#4
Jul 05, 2011, 04:47 pm Last Edit: Jul 05, 2011, 04:52 pm by polishvendetta Reason: 1
Thanks so much for the help.  Can anyone put up some sample code to create noise?  Like I said im not very adept at coding in C (im a mainframer my self) but ive gotten pretty good at adapting existing code :)

Locking up the board while a .5 second or less sound plays shouldnt be a big deal so for now delay() should work.  this would eliminate the need for a delay anyway to prevent someone from firing the tag gun too quickly.

I will likely need some kind of amplifier for the speaker as running straight from the arduino board the sound is very quiet.

Go Up