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>Why don't you account for the 10K equivalent resistance of the R2R ladder when dimensioning the RC filter?</p>
<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>how can i upload this on attiny4312 ?</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>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>I have been disappointed with it.</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>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>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>
Hi there; this has been a great project so far! <br> <br>I just wanted to ask about one hiccup im having. For some reason, the signal coming out from my amp is clipped clean in half, only going up to about half the voltage it should be before just flattening off. The signal coming into the amp is nice and clean, and im fairly sure ive got everything wired up with the same components you used, although my amp is an lm386n-1; do you suppose that could be what's making the difference? I couldnt find anything different about it's specs, but I'm really just a beginner, so I wouldnt know for sure. <br> <br>Anyway, thanks for a brilliant tutorial!
Ah, my mistake actually; got confused with the AC readings from my oscilloscope. It actually is getting the full voltage from the amp, but it's still clipping. I put 3 20k resistors in series with the frequency coming from the arduino, and it's fixed the clipping, but it hardly seems an ideal solution. Is there something else I could be doing to lower the gain on the amplifier?
I too am having a clipping problem ... can you please tell me where to hook to 20k resistors to resolve this ?
what op amp are you using?
oh i see, a lm386. you should wire it up like this: <br />http://letsmakerobots.com/node/4870
<p>are the momentary sqitches normaly Open or normally closed?</p>
normally open
<p>thnx ur awesome!</p>
<p>that resistor looks like a 10k not a 20k</p><p>what do i do??</p>
<p>Hi Amanda, I made your signal generator. </p><p>Why then the output signal from the LM386 truncated vertices, in what could be the reason? Arduino itself gives the right signal and this signal LM386 spoils.</p>
<p>Hi Amanda, I see that you have an amazing 20,000 values for the sine function. Since you only have an 8-bit DAC with 256 levels, is this actually necessary. Can you explain how this adds resolution?</p>
<p>Am I right in thinking that because the frequency is set by reading the voltage at one of the analogue inputs, that there will only be 1024 steps in frequency between 1Hz and 50Khz? Is there anyway of being able to set the frequency in code?</p>
<p>any suggestions of how to implement a LCD displaying the frecuency ***FREQUENCY METER**</p>
<p>I needed a function generator for testing circuits, but couldn't afford to spend several hundred (or more) dollars. This one worked perfectly. I upgraded a few of the parts (for more accurate gain and frequency, I have a 10-turn potentiometer), and also have an option to connect an external voltage supply instead of using a battery for projects that I know will take a while. Having the 9v battery available for quick access and portability is very nice. I changed the code around just a bit so that the initial waveform is sine instead of square, and to allow a lower frequency (about 15hz). I changed freqTolerance to 1 since I upgraded the pots. I also used an actual switch for power (no reason other than just person preference). I use a lot of other equipment which has banana plug recepticals, so that is what I used here instead of a phone plug for universality. My enclosure is a 6.5&quot; x 4.5&quot; x 2.5&quot; black plastic box. All of my parts, including the enclosure and arduino were purchased on Newark for about $75.</p><p>My only concern is that it doesn't output much current, but I'm sure I can come up with something to work around that. Great project, easy to build, works great! Thanks!</p>
Fantastic instructable and really useful device produced. Any chance you can offer a kit of this?
thanks! I was actually just talking about making a shield yesterday. stay tuned, hopefully I can get it done in the next month or so.
<p>and if I wanted to add a more wave signal as would,? I need to make one but I asked to be 5 signs ... please help</p>
<p>Part number 8 needs a revision. 10.01&micro;f 50V Ceramic Disc Capacitor does not exsist. However your link points to 1000pf. Im going to build with the 1000pf.</p>
<p>any suggestions of how to implement a LCD displaying the wave parameters? all these timing interrupts may cause the lib to not function!</p>
<p>Here is my version. I made a standalone system, no shields, blog </p><p>http://black-electronics.com/blog/arduino-waveform-generator/</p>
<p>can i use this method to make a synth :)</p>
<p>yes it could be a starting point, that was my thought</p>
<p>When I open these files, all I see is a box. I don't see any of the laser cuttable panels. Could you please make these available, or, alternatively, if they are there and I'm just not able to see them, could you please show me how to access them?</p>
<p>try the .cdr, you may have to instal corel draw.</p>

About This Instructable


446 favorites


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: