Notes About Working with Various Arduino & Netduino Microcontroller Boards

Friday, August 23, 2013

Generating Sine Waves with an Arduino Uno or Arduino Due

Lately, I've been fiddling around with an oscilloscope and wanted to generate some steady sine waves.  I have found tutorials for the Arduino Uno and Arduino Due that have been very helpful.  I have not found anything that works with the Arduino Leonardo.

Arduino Uno 

Martin Nawrath published an online tutorial for the Arduino Uno, "Arduino DDS Sinewave Generator" back in 2009. It works quite nicely. Here are my notes on the (solderless) breadboard layout for the low-pass filter that converts the PWM output to a nice smooth wave.

The numbers refer to the rows on the breadboard and the letters are the columns.

Component        From    To 
Jumper Wire      1a      (to oscilloscope) 
47nF Capacitor   1b      GND rail
270Ω Resistor    1c      GND rail
4.7mH Inductor   1d      3a
100nF Capacitor  3b      GND rail
4.7mH Inductor   3c      5a

47nF Capacitor   5b      GND rail
270Ω Resistor    5c      7a

Jumper Wire      7b     Arduino Digital 11

The potentiometer's wiper pin should be connect to the Arduino's Analog 0 (with the other pins on the potentiometer connected to the 5V & GND on the Arduino), as indicated in the tutorial.

I didn't have any inductors around, so I ordered an assortment from an Amazon merchant.  It arrived from China in less than 2 weeks. Mouser also has various types of  what they call "Fixed Inductors 4700uH" available. I have tried Mouser Part #s 434-SMCC-472J-00 and 871-B78108S1475J.  They both work fine.  

Arduino Due

On the Arduino Web site there is a nice tutorial, "Simple Waveform Genetator (sic) with Arduino Due."   It presents code that generates sine, triangle, saw-tooth, and square waves.  No external filter is required since it uses  the Due's built-in DAC. 

There is one small error in the code given that needs to b corrected.  

Change the line 

sample = constrain(t_sample, 0, oneHzSample); 


sample = constrain(sample, 0, oneHzSample);


  1. Replies
    1. Hi Abhijit -

      As noted above, you can find the fuller discussion (for the Uno) on Martin Nawrath's blog. My intention with the post above was to translate his circuit design into a layout on a breadboard. For the Due, I made only the slight change in the code (shown above). I don't want to present others' work as my own.


  2. thanks alot .........very helpful...