Waveform generators (also called function generators) are useful for testing and debugging circuits.  I often use them to test the frequency response of electronics components like op amp and sensors.  This waveform generator is powered by an Arduino.  It outputs four waveshapes: sine, triangle, pulse, and saw, each waveshape ranges in frequency from 1Hz-50kHz.  The frequency, pulse width, and overall amplitude (gain) of the waveforms is controlled by three potentiometers.  I've also included (optional) indicator LEDs that let you know which type of wave is currently being sent to the output.

Parts List:

(4x) Mini SPST 1.5-Amp Momentary Pushbutton Switch (2 packages) Radioshack #275-1556
(8x) 10K Ohm 1/4-Watt Carbon Film Resistor  (2 packages) Radioshack #271-1335
(9x) 20K Ohm 1/4-Watt Carbon Film Resistor (2 packages)
(1x) 50K-Ohm Linear-Taper Potentiometer Radioshack #271-1716
(1x) 10K-Omh Audio-Taper Potentiometer Radioshack #271-1721
(1x) 10K-Ohm Audio Control Potentiometer with SPST Switch Radioshack #271-215
(1x) 1/8" Stereo In-Line Audio Jack Radioshack #274-274
(1x) 10.01µf 50V Ceramic Disc Capacitor Radioshack #55047551
(1x) 4.7K Ohm 1/4-Watt Carbon Film Resistor Radioshack #271-1330
(1x) 8 Pin Socket Radioshack #276-1995
(1x) LM386 Low Voltage Audio Power Amplifier Radioshack #276-1731
(2x) 220µF 35V 20% Radial-lead Electrolytic Capacitor (or anything between 200 and 300 uF) Radioshack #272-1029
(1x) Arduino Uno REV 3 Radioshack #276-128
(1x) Arduino Proto Shield Radioshack #276-140
(4x) White Super-bright LED Indicator Radioshack #55050633
(4x) 740 ohm 1/4W 5% Carbon Film Resistor (1 package) Radioshack 271-1317
(1x) 300Ohm resistor

Additional Materials:

Heat Shrink Radioshack #278-1611
22 Gauge Wire Radioshack #278-1224
Solder Radioshack #64-013
Hot Glue
Black diffusor material (tissue paper, plastic, etc)

Step 1: Prepare Arduino Proto Shield

The Arduino Proto Shields are a convenient way to attach circuits to an Arduino, but I like to trim them down a little bit first so they do not take up so much room in the project enclosure.   Start by trimming the pins down with a pair of wire cutters.  Next, cut off the six pin socket.  Finally, cut the sockets from the top of the board.
<p>I really like this project. I wish i could build it. But sadly the typos are so horrible you cant get any of the parts. Radio shack PN's are either wrong, or unknown. Some of the resistor values are transposed. I'm surprised its a sponsered project. Its flashy, but needs to be reengineered by any person wanting to build it.</p>
<p>Great thank-you. </p>
<p>Instead of plugging it to the detector can I plug it into my laptop microphone and listen to the waves sounds??</p>
<p>can anyone provide me with illustrated schematic please?</p>
<p>I really don't mean to offend you, but I just got 10 minutes of my time wasted, browsing through this 'instructable', just to figure that it's almost completely useless, unless I wanted to copy this thing, which I certainly don't want.</p><p>It seems kind of the wrong way around and general information is totally missing. This is much more like a presentation or some sort of making-of than an instructable.</p><p>Let me close with some kind words, sorry. You apparently did a pretty good job on that project. And I know how much effort must be in there, so take my respect.</p>
<p>Hi, </p><p>I came across your project and I got interested in building it, i checked the code and saw that it need revising, i shall add an lcd to this little project and remove the leds and 2 switches. compiling for sd1306 is out of the question so i will resort to a 16 x 2 lcd, </p><p>Keep you posted.</p>
<p>Very nicely done!</p>
<p>hi i would like to know what is the 10.01&micro;f 50V Ceramic Disc Capacitor its cermic capacitor is same function with that? because i have the 10 uf 50v ceramic one</p>
<p>Thanks for thid project.</p><p>Its very nice.</p>
<p>Hi Luis,<br>Could you please send me the code or share the file because the link that she posted I could not open it. Thank you very much for your kindness.</p>
<p>HendM, sorry I see your message now.</p><p>Here is the code</p><p>https://mega.nz/#!h0FSwATA!vxiu_BQT4qBLKSHARao4zluUT-fPTr_WdtbGhKq_n_4</p><p>Its works fine</p><p>Good luck</p>
<p>Please could anyone post the code or share the file! I can not open the zip file..Please</p>
<p>i want to make only sine wave using arduino how can i do it</p>
<p>Hello Amanda, thanks for all your project.<br>Could you suggest me the <br>difference between this way to amplificate with 2 capacitors and the <br>single capacitor application in your Analog output project? </p><p><a href="https://www.instructables.com/id/Arduino-Audio-Output/" rel="nofollow">https://www.instructables.com/id/Arduino-Audio-Outp...</a><br><br>Many thanks!</p><p>Andrea</p>
<p>Thanks for posting this nice project.</p><p>The saw does not work correctly; Error in code line 218. Should be if(t == 0) {</p><p> And if (!t) should also work.</p><p>I made the function generator with 1 button:</p><p>void checkShape() { //debounce and check states of button<br> if (digitalRead(BUTTON)==HIGH){<br> if (!debounce ) { <br> debounce = millis(); //Start debounce time<br> if (++type &gt; 4) type = 1; //New press done, check for max state<br> }else {<br> unsigned long currentMillis = millis(); //Put in temp because using milles in if below does not work<br> if ((unsigned long)(currentMillis - debounce) &gt; DEBOUNCE_TIME ) debounce = 0;<br> }<br> }else debounce = 0; //if not pressed any more reset the debounce function.<br>}</p><p>I used a Due</p><p>Have fun</p>
<p>Hii Jandemna,</p><p>I am also facing the same problem of button debouncing in Arduin Due. I have written a code for button debouncing but still not got success.</p><p>I have posted the question Forum:</p><p>If you want to refer my code please find the following link</p><p><a href="http://forum.arduino.cc/index.php?topic=393201.msg2706670#msg2706670" rel="nofollow">http://forum.arduino.cc/index.php?topic=393201.msg...</a></p><p>Thanks In advance</p>
<p>I have been seeing a few people having errors with &quot;sine20000&quot;</p><p>It has been suggested to use an earlier Arduino IDE build, but there is a simple fix for Arduino 1.6.+ </p><p>Change the first section in the code containing the sine20000 array:</p><p>from:</p><p>byte sine20000[] PROGMEM = { </p><p>to:</p><p>const byte sine20000[] PROGMEM = {</p><p>and leave everything in the brackets alone</p><p>After doing this I was able to get the program to compile without error in 1.6.7</p>
<p>I did the same, <br></p><p>const byte sine20000[] PROGMEM = { .....</p><p><br>and work good for me.. Thanks.</p>
Hey guys, i wanna ask that in above circuits the lady used 5V from arduino many times but in actual arduino has just one 5V output pin... So how to ise it multiple times? Parallel?
<p>hi, i have this error:</p><p>Arduino: 1.6.5 (Windows 7), Board: &quot;Arduino Nano, ATmega328&quot;</p><p>In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28:0,</p><p> from function_generator.ino:30:</p><p>function_generator:30: error: variable 'sine20000' must be const in order to be put into read-only section by means of '__attribute__((progmem))'</p><p>variable 'sine20000' must be const in order to be put into read-only section by means of '__attribute__((progmem))'</p><p> This report would have more information with</p><p> &quot;Show verbose output during compilation&quot;</p><p> enabled in File &gt; Preferences.</p><p>pleaseeeeee help me </p>
<p>Try using Arduino IDE 1.0.5 -- that fixed my problems for me.</p>
<p>Hello amanda .. i made this project nut when i upload the given code it gives me following error <br></p><p><br> from function_generator.ino:30:<br><br>function_generator.ino:30:18: <br> error: variable 'sine20000' must be const in order to be put into <br>read-only section by means of '__attribute__((progmem))'Can yu please help me out</p>
<p>Try using Arduino IDE 1.0.5 -- that fixed my problems for me.</p>
<p>Just now, I compiled the sketch with Arduino 1.0.6 set to Uno, and it didn't have a problem. So I can't prove I've found your answer. What board are you compiling for that gave you this error?</p><p>Sometimes I accidently type something into a sketch without knowing it, that causes it to crash. You could try reloading the sketch from the original &quot;untouched&quot; source.</p><p>The &quot;30:18&quot; in your error message means it happened on line 30, and the 18th characcter in from the left. The error message states the line should be a &quot;const&quot;, so I did that, I added the word &quot;const&quot; so the line starts with &quot;const byte sine20000&quot; instead of just &quot;byte sine20000&quot;, and again, it compiled just fine for me.</p><p>Give that a try.</p><p>&quot;const&quot; means the values in that line will not be changed, which I beleive is correct since it's only read -- over and over again -- to make the sine wave.</p>
<p>Arduino: 1.6.5 (Windows 8), Board: &quot;Arduino Uno&quot;</p><p>In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28:0,</p><p> from function_generator.ino:30:</p><p>function_generator:30: error: variable 'sine20000' must be const in order to be put into read-only section by means of '__attribute__((progmem))'</p><p>variable 'sine20000' must be const in order to be put into read-only section by means of '__attribute__((progmem))'</p><p>Please help me out!!</p>
<p>Try using Arduino IDE 1.0.5 -- that fixed the problems for me.</p>
<p>Arduino: 1.6.1 (Windows XP), Board: &quot;Arduino Uno&quot;</p><p>function_generator.ino:30:8: error: 'sine20000' does not name a type</p><p>In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28:0,</p><p> from function_generator.ino:30:</p><p>function_generator.ino: In function 'void __vector_11()':</p><p>function_generator.ino:227:31: error: 'sine20000' was not declared in this scope</p><p>Error compiling.</p><p> This report would have more information with</p><p> &quot;Show verbose output during compilation&quot;</p><p> enabled in File &gt; Preferences. </p><p>I get the following error while i compile the code in arduino IDE. I tried alot. but could't solve the problem. Would anybody please help me ?</p>
<p>Try using Arduino IDE 1.0.5 -- that fixed my problems for me.</p>
<p>After googling for &quot;Sine Wave Circuit&quot;, I was delighted to find this &quot;Arduino&quot; sine wave circuit, because I love working with Arduino and it's compatible modules. Also, the lazer cutter used here was a wonderful discovery for me too! I didn't even know there was such a thing, but now must have one to add a professional look to the projects I sell.</p><p>However, the article has room for improvement, which is the reason for this comment. Here are my suggestions:</p><p>1. The several places the text refering to &quot;300Ohm&quot;, and &quot;470Ohm&quot; need a space to make it &quot;300 ohm&quot; and &quot;470 ohm, so it doesn't look like a value ten times larger than intended.</p><p>2. One schematic shows the 300 ohm resistor and cap for the low pass filter. But the other schematic omits this circuit.</p><p>3. Although the photography is very clear, no one picture shows all the wiring where it's easy to understand everything at once. Take a look at</p><p>http://1.bp.blogspot.com/-FLaRrce1svE/VFtEWeuSL0I/AAAAAAAAANI/1GbkconjhXU/s1600/bluetoothcontrol_bb.jpg</p><p>Every wire -- and where it connects -- is easy to see in one picture. And like in this picture, I always try out my projects on a white breadboard first; for it's far easier to try out alternatives and correct mistakes where all parts plug and unplug, than it is on a project board where you have already soldered the parts permanently in place.</p><p>4. The text says, &quot;A 4.7kOhm resistor bridges pins 3 and 4 of the IC socket.&quot; Yet the schematic shows this as being a 2.2k ohm resistor. Which value is correct?</p><p>5. It would help to have a note on the pictures, explaining you can mouse-over the rectangles to pop up notes on what's inside the rectangle. I'd nearly finished the project before discovering this.</p><p>6. One such rectangle (over a straight section of wire in a schematic) says a resistor should have been here. Why not just add the resistor to the image and reload it? The note is easy to miss (and thus the need for the resistor.)</p><p>7. Another mouse-over rectangle says the color code on the resistor shown is wrong. So why not just use an art program to paint the correct colors on the resistor, and re-upload the image?</p><p>I think this is a GREAT project; exactly what I needed. But the above seven items make it hard to follow correctly. For the benefit of others, I'd LOVE to see these modifications made.</p>
<p>Hello Paul .. i made this project nut when i upload the given code it gives me following error</p><p><br> from function_generator.ino:30:<br><br>function_generator.ino:30:18: error: variable 'sine20000' must be const in order to be put into read-only section by means of '__attribute__((progmem))'</p><p>Can yu please help me out<br></p>
<p>What version of the Arduino IDE are you using? Try using 1.0.5 -- that fixed the problem for me.</p>
<p>Hi My name is anto , I am building a sig gen for a project in college. I planned to have a large array and increment by different values to give me different frequencies so that that the frequency resolution will be intergral multiples of the lowest frequency. I presumme that is what u did . My problem is that if make the array too big the lowest frequency sine wave is very distorted. the lowest frequency i can get is about 400Hz any lower it is not good. Also I dont use a timer interupt i am just using a tight loop with a quick check on PINB for button presses.</p><p>I used a ladder DAC like yours and it is smoothing out my signal without a lowpass filter. </p><p>Did you have any problems like these yourself , I would really appreciate help.</p><p>Thanks so much Anthony</p>
<p>Why don't you account for the 10K equivalent resistance of the R2R ladder when dimensioning the RC filter?</p>
<p>how can i upload this on attiny4312 ?</p>
<p>I have been disappointed with it.</p>
<p>Is there a point in storing 20000 samples? If our DAC can only represent 2^8 values? Surely 256 samples should be the maximum sample resolution? Im a bit confused. Nice project :)</p>
<p>Think of a sine wave in the x-y plane. There are only 256 y values available, because that's the resolution of the arduino's analog output pins. However, we can have as many x values as we need, to some extent.</p><p>So the question becomes what is the smallest number of x values you need for it to still look like a sin wave. The author chose 20k, but you could do more or less if you wanted to. As I see it, the only reason to do more is for higher resolution at lower frequencies, and the only reason to do less is to save storage space.</p>
<p>Hey, would it be possible to convert this project to a synthesizer dual DCO? Midi controlled and with one output for each DCO where DCO2 frequency is DCO1*detuneFactor (set by a pot on an analog pin, range +/- 1 octave so detuneFactor would have to go from 0,5 to 2)</p>
<p>hey i have to take the output of the arduino through earphones instead of speaker.. my arduino output is working pretty fine with speaker.. but i have to switch it now to earphones. can you please guide </p>
<p>The problem with earphones is that they put all that power right into your ears! Just connect a resistor in series with each earphone wire. If they are 8 ohm ear phones, a ten ohm resistor would reduce the power about in half, a 33 ohm resistor would reduce it to 1/4th as loud, etc. </p>
<p>Hello Amanda,</p><p>can i use arduino atmega2560 in place of uno???</p><p>thank you!</p>
<p>If you already have your atmega2560, just try loading the software sketch this instructable provided into your Adruino. If the the Arduino tells you it's happy with it, that should bve your answer.</p>
<p>Is there any particular reason for the 35 V rating on the 220 microF capacitors? I already have a set of 16V and was wondering if there would be any reason I couldn't use them</p>
<p>No, no reason why you cannot use your 16 V caps. I guess the 35 V volt ones was what the author had available at that moment. As a general rule: as long as the capacitor voltage rating is higher than the supply voltage of your circuit, it will be OK.</p>
<p>How can I change the R 2R resistor set for a DAC08 (<a href="http://docs-europe.electrocomponents.com/webdocs/077f/0900766b8077fe46.pdf" rel="nofollow">http://docs-europe.electrocomponents.com/webdocs/0...</a>) in order to save components? What connections do I have to do?</p><p>Thank you</p><p>Great project</p>
<p>Hi Amanada.</p><p>can i use arduino atmega2560 in olace of uno???</p><p>thanks..</p>
so im not 100 sure on the math but im short a few 10k resistors.. if I just do 2 4.7k resistors in series will that be close enough? will that just affect the amplitude a small bit?
<p>Amazing and well laid out! I look forward to making one!</p>
<p>Great work! Very well thought out and quite useful. Using an Arduino instead of a professional arbitrary waveform generator can save us a bunch of money. <br>I have one suggestion, however: add a button that, when pressed, will send just one cycle of the selected waveform in the selected configuration (one-shot trigger). </p>

About This Instructable




Bio: I'm a grad student at the Center for Bits and Atoms at MIT Media Lab. Before that I worked at Instructables, writing code for ... More »
More by amandaghassaei:OTCA Metapixel - Conway's Game of Life "9 Degrees of Freedom" IMU Twitter Controlled Pet Feeder 
Add instructable to: