The arduino is surely the little micro controller that could. you can do so much with it! We at instructables have been having so much fun with our arduinos, we wanted to show the instructables community how to do some of the basics!

This first tutorial will go over how to make your arduino make simple sounds, and turn your arduino into mini tone generator.

Step 1: Supplies

For this tutorial you will need the following

1 small 8 ohm speaker
1 arduino board
1 push button
1 10 k resistor
some solid core wire

For my purposes, i used the adafruit protoshield to help me lay it out my stuff!
its no working on arduino uno .why?<br>
<p>Hello Instructables forum,</p><p><br>I need to trigger a VMA02 shield which would reproduce a sound, with a PIR sensor movement of Arduino.<br><br>With the provides codes,<br>I managed to activate both separately,<br>I mean, the PIR sensor activates a led,<br>and,<br>the VMA02 shield activates the recorded sounds through the bottoms.<br><br>//VMA02 code//<br>#include &lt;ISD1700.h&gt;<br>ISD1700 chip(10); // Initialize chipcorder with<br>// SS at Arduino's digital pin 10<br><br>int apc=0;<br>int vol=0; //volume 0=MAX, 7=min<br>int startAddr=0x10;<br>int endAddr =0x2DF;<br>int inInt=0;<br>void setup()<br>{<br>apc = apc | vol; //D0, D1, D2<br><br>//apc = apc | 0x8; //D3 comment to disable output monitor during record<br><br>apc = apc | 0x50; // D4&amp; D6 select MIC REC<br>//apc = apc | 0x00; // D4&amp; D6 select AnaIn REC<br>//apc = apc | 0x10; // D4&amp; D6 select MIC + AnaIn REC<br><br>apc = apc | 0x80; // D7 AUX ON, comment enable AUD<br><br>apc = apc | 0x100; // D8 SPK OFF, comment enable SPK<br><br>//apc = apc | 0x200; // D9 Analog OUT OFF, comment enable Analog OUT<br><br>//apc = apc | 0x400; // D10 vAlert OFF, comment enable vAlert<br><br>apc = apc | 0x800; // D11 EOM ON, comment disable EOM<br><br><br><br>Serial.begin(9600);<br>Serial.println(&quot;Sketch is starting up&quot;);<br>}<br>void loop()<br>{<br>char c;<br><br>if(Serial.available())<br>{<br>/* Power Up */<br>chip.pu();<br>c = Serial.read();<br>switch(c)<br>{<br>case 'A':<br>Serial.println(chip.rd_apc(), BIN);<br>break; <br>case 'Y':<br>chip.play();<br>break;<br>case 'P':<br>chip.stop();<br>delay(500);<br>break;<br>case 'E':<br>chip.erase();<br>delay(500);<br>break;<br>case 'R':<br>chip.rec();<br>break;<br>case 'F':<br>chip.fwd();<br>delay(500);<br>break;<br>case 'Z':<br>chip.g_erase();<br>delay(500);<br>break;<br>case 'I':<br>Serial.println(chip.devid(), BIN); <br>break;<br>case 'W': <br>Serial.println(apc, BIN);<br>chip.wr_apc2(apc); //<br>break;<br>case 'S': <br>Serial.println(chip.rd_status(), BIN);<br>break;<br>case '&gt;': <br>startAddr=SerialIn(); <br>Serial.print(&quot;startAddr: &quot;);<br>Serial.println(startAddr);<br>break; <br>case '&lt;': <br>endAddr=SerialIn(); <br>Serial.print(&quot;endAddr: &quot;);<br>Serial.println(endAddr);<br>break; <br>case 'y':<br>chip.set_play(startAddr,endAddr);<br>break;<br>case 'r':<br>//chip.set_erase(startAddr,endAddr);<br>//delay(500);<br>chip.set_rec(startAddr,endAddr);<br>break;<br>case 'e':<br>chip.set_erase(startAddr,endAddr);<br>delay(500);<br>break;<br><br>}<br>Serial.print(&quot;Status---&gt; &quot;);<br>Serial.print(chip.CMD_ERR()? &quot;CMD_ERR &quot;: &quot;OK &quot;);<br>Serial.print(chip.PU()? &quot;PU &quot;: &quot;NO PU &quot;);<br>Serial.print(chip.RDY()? &quot;RDY &quot;: &quot;Not_RDY &quot;);<br>Serial.print(chip.rd_status(), BIN);<br>Serial.println();<br>delay(1000);<br>}<br>}<br>int SerialIn(){<br>inInt=0;<br><br>while (Serial.available() &lt;= 0) <br>{<br>delay(300);<br>}<br>while (Serial.available()) {<br>// get the new byte:<br>char c = Serial.read(); <br>// add it to the inputString:<br>inInt = (inInt*10) + (c-48);<br>// if the incoming character is a newline, set a flag<br>// so the main loop can do something about it:<br>if (c == '\n') {<br>//stringComplete = true;<br>Serial.print(&quot;stringComplete &quot;);<br>} <br>}<br>//c = Serial.read()-48; <br>//mess(c);<br>return (inInt);<br><br>}<br>/*<br>void mess(int num){<br>Serial.print(&quot;num: &quot;);<br>Serial.println(num);<br>startAddr=(0x50*num)+0x10;<br>endAddr=(startAddr+0x50)-1;<br>Serial.print(&quot;startAddr: &quot;);<br>Serial.print(startAddr, HEX);<br>Serial.print(&quot; - endAddr: &quot;);<br>Serial.println(endAddr, HEX);<br><br>}<br>*/ <br><br><br><br>//PIR code//<br><br>/* <br>* //////////////////////////////////////////////////<br>* //making sense of the Parallax PIR sensor's output<br>* //////////////////////////////////////////////////<br>*<br>* Switches a LED according to the state of the sensors output pin.<br>* Determines the beginning and end of continuous motion sequences.<br>*<br>* @author: Kristian Gohlke / krigoo (_) gmail (_) com / <a href="http://krx.at/" rel="nofollow">http://krx.at</a><br>* @date: 3. September 2006 <br>*<br>* kr1 (cleft) 2006 <br>* released under a creative commons &quot;Attribution-NonCommercial-ShareAlike 2.0&quot; license<br>* <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/de/" rel="nofollow">http://creativecommons.org/licenses/by-nc-sa/2.0/de/</a><br>*<br>*<br>* The Parallax PIR Sensor is an easy to use digital infrared motion sensor module. <br>* (<a href="http://www.parallax.com/detail.asp?product_id=555-28027" rel="nofollow">http://www.parallax.com/detail.asp?product_id=555-28027</a>)<br>*<br>* The sensor's output pin goes to HIGH if motion is present.<br>* However, even if motion is present it goes to LOW from time to time, <br>* which might give the impression no motion is present. <br>* This program deals with this issue by ignoring LOW-phases shorter than a given time, <br>* assuming continuous motion is present during these phases.<br>* <br>*/<br><br>/////////////////////////////<br>//VARS<br>//the time we give the sensor to calibrate (10-60 secs according to the datasheet)<br>int calibrationTime = 30; <br><br>//the time when the sensor outputs a low impulse<br>long unsigned int lowIn; <br><br>//the amount of milliseconds the sensor has to be low <br>//before we assume all motion has stopped<br>long unsigned int pause = 5000; <br><br>boolean lockLow = true;<br>boolean takeLowTime; <br><br>int pirPin = 3; //the digital pin connected to the PIR sensor's output<br>int ledPin = 13;<br><br><br>/////////////////////////////<br>//SETUP<br>void setup(){<br>Serial.begin(9600);<br>pinMode(pirPin, INPUT);<br>pinMode(ledPin, OUTPUT);<br>digitalWrite(pirPin, LOW);<br><br>//give the sensor some time to calibrate<br>Serial.print(&quot;calibrating sensor &quot;);<br>for(int i = 0; i &lt; calibrationTime; i++){<br>Serial.print(&quot;.&quot;);<br>delay(1000);<br>}<br>Serial.println(&quot; done&quot;);<br>Serial.println(&quot;SENSOR ACTIVE&quot;);<br>delay(50);<br>}<br><br>////////////////////////////<br>//LOOP<br>void loop(){<br><br>if(digitalRead(pirPin) == HIGH){<br>digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state<br>if(lockLow){ <br>//makes sure we wait for a transition to LOW before any further output is made:<br>lockLow = false; <br>Serial.println(&quot;---&quot;);<br>Serial.print(&quot;motion detected at &quot;);<br>Serial.print(millis()/1000);<br>Serial.println(&quot; sec&quot;); <br>delay(50);<br>} <br>takeLowTime = true;<br>}<br><br>if(digitalRead(pirPin) == LOW){ <br>digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state<br><br>if(takeLowTime){<br>lowIn = millis(); //save the time of the transition from high to LOW<br>takeLowTime = false; //make sure this is only done at the start of a LOW phase<br>}<br>//if the sensor is low for more than the given pause, <br>//we assume that no more motion is going to happen<br>if(!lockLow &amp;&amp; millis() - lowIn &gt; pause){ <br>//makes sure this block of code is only executed again after <br>//a new motion sequence has been detected<br>lockLow = true; <br>Serial.print(&quot;motion ended at &quot;); //output<br>Serial.print((millis() - pause)/1000);<br>Serial.println(&quot; sec&quot;);<br>delay(50);<br>}<br>}<br>}<br><br><br><br><br>I need to unify both mechanisms,<br>Activate a sound triggered by the PIR sensor.<br><br>If someone can help me,<br>I would appreciate it.<br><br>If you help me to solve it,<br>I will post here a link of our website,<br>in where you will find information such as videos, to explain a technological art exhibition we are developing.<br><br>We unveil the exhibition on 20th of January.<br><br>Kind regards.</p>
Hello!!!!!<br>I want a little help. I have been given a project. I have to implement arduino in my project in such a way that speakers can play sounds of different alphabets ,fruits, vegetables etc. Please tell me how to code it in arduino
<p>Would it be better if we use the piano key frequency formula -&gt; f(n) = 2 ^ (n - 49/12) * 440 Hz, instead of defining all tones?</p>
If you put a capacitor in series with the speaker it will be much louder.
<p>what type of capacitor?</p><p>how to set up it?</p><p>thanks..</p>
<p>OK - piece of cake and very very cool ... but one thing TOTALLY escapes me... How do you 'jam out' so 'radically'!?!? The hood, the matching glasses... the rockin mouth poses! Please add instructable on this as well please, otherwise this tutorial is just not complete. :)</p>
Where did you get the 8 ohm speaker? Thanks.
consider me tuned !
Can two tones be played at the same time, and what does the resistor do? Would like to be using square waves somehow.
Yes they can,kinda choppy,and I still don't know bout the resistor, this is what iv made with the tone function, will write it up soon, ordered some relay shields the other day ,but now iv used the board, doh.
having a problem with the Pitches.h file. i can get it to work when i use the absolute path, but i can't get the relative path to work. i put the Pitches.h in the same folder as the .ino and i'm using a windows machine. anyone know why the relative path isn't working?
Well cool !&nbsp;<br> I had to assign a path in the h include. But's that prob just because I'm a noob.<br> <br> <br> #include &quot;./Pitches.h&quot;<br> <br> // notes in the melody:<br> int melody[] = { NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4 };<br> <br> // note durations: 4 = quarter note, 8 = eighth note, etc.:<br> int noteDurations[] = { 4, 8, 8, 4,4,4,4,4 };<br> <br> void setup() {<br> &nbsp; int speakerPin = 8;<br> &nbsp;<br> &nbsp; // iterate over the notes of the melody:<br> &nbsp; for ( int thisNote = 0; thisNote &lt; 8; thisNote++) {<br> <br> &nbsp;&nbsp;&nbsp; // to calculate the note duration, take one second<br> &nbsp;&nbsp;&nbsp; // divided by the note type.<br> &nbsp;&nbsp;&nbsp; //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.<br> &nbsp;&nbsp;&nbsp; int noteDuration = 700/noteDurations[thisNote];<br> &nbsp;&nbsp;&nbsp; tone( speakerPin, melody[thisNote], noteDuration );<br> <br> &nbsp;&nbsp;&nbsp; // to distinguish the notes, set a minimum time between them.<br> &nbsp;&nbsp;&nbsp; // the note's duration + 30% seems to work well:<br> &nbsp;&nbsp;&nbsp; int pauseBetweenNotes = noteDuration * 1.30;<br> &nbsp;&nbsp;&nbsp; delay( pauseBetweenNotes );<br> &nbsp;&nbsp;&nbsp; // stop the tone playing:<br> &nbsp;&nbsp;&nbsp; noTone( speakerPin );<br> &nbsp; }<br> }<br> <br> void loop() {<br> // no need to repeat the melody.<br> }
I saved the pitches defines as a .h file in the folder where the sound.ino went. <br>And included the .h file with a relative path. <br> <br>#include &quot;./Pitches.h&quot; <br> <br>That was the only way i could get it to work. <br>Thanks. <br> <br>
Would it be possible to make a sound recording and then have the speaker play the sound recording? I want my garduino to talk when he is hungry hehe.. I have a little 8ohm like the one used in this tutorial. Very cool tutorial.
I don't have any speakers, although i do have some piezo buzzers. Will one of these work instead of the speaker?<br><br>-TheWaddleWaaddle
I got my speaker from an old tv at goodwill. The TV cost 99cents and I got 2 speakers!
Yes, they will
We need some videos about this project !!!!
Yeah, we wanna hear!
Can this Arduino make sounds ala chiptunes using a fairly common SN76489? Thanks in advance
What waveform is the tone generated by the arduino?
sweet pics, dude. are those 3-D glasses?
no they r wayfarer(spicoli) shades. u can buy em in a mall at like zumiez. they r like $10
No they are 4D
Cool I'ble! I get the feeling that even I can do this. Thanks!
These pictures are too awesome!!
Thanks, this helped me out a lot!

About This Instructable




Bio: I'm a full stack web developer focusing on security and privacy.
More by frenzy:Cómo hacer una placa iluminada con teclas de un teclado Una funda para tu dispositivo, hecha de un traje de buceo Dead Drop inalámbrico 
Add instructable to: