Arduino Waveform Generator by amandaghassaei
Featured
main copy copy.jpg
IMG_4724.jpg
function generator_schem.png
Screen shot 2012-11-29 at 12.32.37 PM.png
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
Drill
Hot Glue
Glue
Black diffusor material (tissue paper, plastic, etc)
 
Remove these adsRemove these ads by Signing Up

Step 1: Prepare Arduino Proto Shield

IMG_1778 1.JPG
IMG_1779 1.JPG
IMG_1781 copy.jpg
IMG_1783 copy.jpg
IMG_1782 1.JPG
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.
1-40 of 57Next »
randomnonsense11 says: Jul 29, 2012. 3:13 PM
This may seem a bit elementary, but what is the use of this?
amandaghassaei (author) says: Jul 29, 2012. 3:21 PM
lots of things, mostly testing the frequency response of circuits, response time of components... something like this:
http://www.instructables.com/id/Oscilloscope-How-To/step9/Advanced-Oscilloscope-Dual-Channel-Measurements/
anything you would need an oscillating signal to measure.
amandaghassaei (author) says: Jul 29, 2012. 3:22 PM
you could also send it to speakers to make sounds or patch it into some other audio effects- what I plan on doing with it.
janw says: Aug 6, 2012. 9:58 AM
It is a very nice project but its a bit overkill to use an arduino for a functiongenerator that will be patched in a soundgenerating system (aka a synth.)

Even if you would use a microcontroller, an attiny would be a better choice I guess (you can use your arduino to program these).

On the other hand, if you go a bit bigger and use an atmega32 you could make an entire synth with it. Have a look at the Meeblip website (meeblip.com)
flashular says: May 8, 2013. 7:59 AM
I hope not to detract from this great instructable, but if you want an arduino based audio synth you might also consider the GinSing shield ( www.ginsingsound.com ).
veden says: Apr 22, 2013. 2:01 AM
great work !! i was wondering to make arduino read a sine wave from 12VAC transformer. i want to get data every sample that been generated..can i give me idea..can u guide me pls
amandaghassaei (author) says: Apr 22, 2013. 2:34 PM
maybe something like this:
http://www.instructables.com/id/Arduino-Audio-Input/
rgabriel3 says: Apr 2, 2013. 8:00 PM
Hi Amanda,
Why you choose 20000 values on the sin function? and why the sample rate is 10000?
Thanks =]
amandaghassaei (author) says: Apr 4, 2013. 1:45 PM
the numbers actually aren't related. I chose 20000 values for the sin function bc I could fit that many numbers in the Arduino's memory and it helps to increase the resolution of the signal. I chose the 100kHz sampling rate so that I could easily reproduce signals through the audible range (~20hz to 20kHz). at 100kHz sampling rate, I can get 100/20 = 5 samples per cycle on a 20kHz signal.
Panichou says: Mar 21, 2013. 7:39 AM
Hi Amanda.
Is there a simple way to generate a sin wave from the arduino ?
I want to have a signal which contains two or three frequencies. I thought about generating a few sin wave with the arduino then multiply or sum them.

Thank you
amandaghassaei (author) says: Mar 28, 2013. 10:48 PM
yes there is code in this ible to help you do that:
http://www.instructables.com/id/Arduino-Audio-Output/
eran says: Feb 18, 2013. 9:46 PM
Hi Amanada.
thanks for writing so many wonderful tutorials, its a pleasure following your tutorials, they are clear, and well thought of!
I am building a game for kids with which we can demonstrate breaking glass in classroom.
I wanted to know if you can add directions on how to create a sine wave with a resolution of 1/10 Hz - for example ,I need to be able to tune the generator to 1000.03 Hz. should I use a second potentiometer to get better resolution? and in the Arduino code itself, what should needs to be change for the sine wave section?

thanks,

Eran
amandaghassaei (author) says: Mar 28, 2013. 10:46 PM
you need to change this line:
frequency = freqCurrent;//new frequency- number between 0 and 1024
freqscaled = 48*frequency+1;//from 1 to ~50,000
get it so that freqscaled is in the range you want, maybe 999 to 10001Hz for values of frequency that range from 0 to 1024
also change:
int frequency;
int freqCurrent;
unsigned int freqscaled;
to
float frequency;
float freqCurrent;
float freqscaled;
that should work, let me know if you have trouble
tisla says: Mar 10, 2013. 12:36 AM
:( need some help...

im using an arduino clone. how should i connect the components to the micro controller? should i wire the PD,PB,PC to its PB, PB, PC counter part using the schematic of the clone? TIA

:(
amandaghassaei (author) says: Mar 28, 2013. 10:41 PM
yes, you should be able to find the pin connections here:
http://arduino.cc/en/Hacking/PinMapping168
tisla says: Mar 6, 2013. 3:37 PM
hi amanda, can i use the code directly to an arduino clone? atmega328 base? tia
amandaghassaei (author) says: Mar 28, 2013. 10:41 PM
yes that's fine
mausi_mick says: Mar 22, 2013. 11:56 PM
hi Amanda,

it's a wonderfull project !

i have one question:

Is the resistance (R21) between ground and the r2r-ladder 10k or 20 k.
In the schematic it is 20k, but in the description it is 10k.
I don't know, what' right ,

thanks
amandaghassaei (author) says: Mar 28, 2013. 10:38 PM
it's 20, sorry about that
http://en.wikipedia.org/wiki/Resistor_ladder
_SarahC_ says: Feb 9, 2013. 12:04 AM
How did you get the values from the python script stored, then output to the Arduino's memory to store them?

Ah - you're writing a string - and you copy and paste that into your Arduino script?

sine20000[] = [copy & pasted python output here]
amandaghassaei (author) says: Feb 16, 2013. 9:21 AM
exactly
BEYERdinamic says: Dec 21, 2012. 8:03 AM
you know if you can climb up to 5MHz frequency?
KKHausman says: Jan 15, 2013. 2:16 PM
The Arduino's own processor limits the maximum step speed, which constrains the wave frequency. The Arduino's processor frequency internally is 8MHz, while the on-board 16MHz oscillator allows each step to occur at the faster rate. If a full wave takes 16 steps, then the maximum frequency of the output (ideal) would be 1MHz but resolution of the waveform would suffer. In the provided sketch, the triangular waveform is stored in an array using (127+127) increments per cycle, so the maximum (ideal) frequency would be roughly 125kHz. In addition, the low pass filter that smooths out the wave output also constrains the operating frequency based on the discharge rate of the cap, so that the provided cap and resistor values operate under 100kHz..
jleguizamo rojas says: Jan 8, 2013. 11:19 AM
ok, so I only need change the ports right?
amandaghassaei (author) says: Jan 8, 2013. 1:41 PM
yes, do you know how? I think you will also have to change the timer setup.
jleguizamo rojas says: Jan 3, 2013. 8:36 PM
Can I make this proyect with an Arduino Mega?
amandaghassaei (author) says: Jan 4, 2013. 8:08 PM
Yes, but the code and pin connections will change.
BEYERdinamic says: Dec 21, 2012. 8:03 AM
tu sabes si se puede subir la frecuencia hasta los 5MHz?
jher-se says: Oct 31, 2012. 7:27 PM
Hi Amanda.! it's exelent you project .. I just wanna know, where I can find the full schematic.. Do you think that can help me with that ?
thank you very much..
amandaghassaei (author) says: Nov 1, 2012. 1:19 AM
thanks! the schematic is on the first step.
mkahata says: Sep 3, 2012. 12:14 AM
amanda. it is so nice instruction. i was looking interrupt for Arduino few month. but not easy to find good instruction. your's is best. thank you. i put this interrupt function to my open hardware brain wave interface project. works nice. but can not do many things in the main loop and inside of interrupt anyway. mean can not set sampling frequency to high. but that is ok for usually. also can not use Analogue write function. can use hardware interrupt then can use Analogue write but processing time problem is same. specially analog read takes time. currently processing to make document for my project. let you know then.
amandaghassaei (author) says: Sep 3, 2012. 1:46 AM
great, can't wait to see it!
CenterChannelSpeaker says: Aug 28, 2012. 3:39 PM
This is right up my alley
Shonswer says: Aug 27, 2012. 3:05 PM
I was looking a project for my electronic subject, i will try this, thanks for tutorial
mauricio 1995 says: Aug 1, 2012. 10:53 AM
mi caso es que estoy recién empezando en esto de la electrónica tengo 17 años mi pregunta o mas bien petición es si puedes mandarme el diseño de las placas y también una recomendación de con que programa puedo simularlo
amandaghassaei (author) says: Aug 6, 2012. 12:35 AM
http://www.instructables.com/id/Arduino-Waveform-Generator/step2/Enclosure/
dexterandrada says: Jul 29, 2012. 9:54 PM
Great Job!

You can actually sell some of these for people that might be interested of building one but doesn't have the time. This has many wonderful uses really!

A DIY tester is the way to go!
wgrube says: Jul 29, 2012. 7:52 PM
Nice work! Very detailed and well executed! I think I'm gonna build this...
amandaghassaei (author) says: Jul 29, 2012. 7:52 PM
nice! post a pic if you do!
Insonicbloom says: Jul 29, 2012. 6:25 AM
I just feel like this is an awfully expensive way around making a basic function generator - this one here doesn't require an Arduino board or protoboard, in fact it probably costs as much as the protoboard on it's own for everything. performs the main waveforms upto 300KHz and uses normal stripboard

it's a great instructable don't get me wrong, it's just so much overkill using a uController without including extra function such as LCD/arbitrary waveforms etc.
1-40 of 57Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!