Function Generator (arduino Pro Mini)




Introduction: Function Generator (arduino Pro Mini)


this is a function generator with Arduino Pro Mini and few components that at power on start with a sawtooth of about 40
Hz and 5Vpp. Pressing one time the SWFUN button the output change to a triangular wave and pressing another time the button the output is a sine of always 40 Hz.

The LEDs means:

Blue = sawtooth

Red = triangular

Green = sinusoidal

The firmware of Arduino Pro Mini is here and require the library TimerOne.

Many thanks to the author of this article from which I was inspired.

At the PIN 9 of Arduino there is a square wave of about 32KHz . His duty cycle vary with a linear law from 0 to 1023 (10 bit DAC) and drop to zero immediatly in the sawtooth. In the triangular wave the d.c. vary from 0 to 1023 then from 1022 to 0 excluding odd values (see the code). In this mode the overall period of these two waveform is the same.

Finally the sine wave is obtained with the duty cycle depending from the math. sin function (his output is between -1 and 1) re-mapped into a 0-1023 range.

For all the waveforms the low-pass filter composed by a 10 KOhm resistor and a 100nF capacitor (with a cut-off frequency of 160 Hz about) extract the average value of the rectangular wave that is a linear function of the duty cycle of the 32KHz signal.

The push button, connected to the PIN 2 (with a pull-up of 10 KOhm) trigger the interrupt 0 of arduino that call the changemode function. This function set the general mode variable to set the proper waveform (in the loop function) and set the proper LED.

With this item you can test an oscilloscope and an audio amplifier to ear a very low frequency tone.

Of course this project is limited and you can add a frequency setting maybe up to some hundred Hz or 1 KHz.

Finally note that the schematic refer to an arduino pro mini type ATmega328 (5V, 16 MHz)

Step 1: Project Building

Not too much to say! You can solder the wires to arduino pro mini without mounting pins in bundle or use wires with female to female connectors if you just have an arduino fully mounted. The RAW pin accept a voltage up to 10V so a little square 9V battery can be used.

Of course to load the program into arduino you need the arduino IDE and a USB to serial (TTL) device like that showed in this page.

Have fun!

Be the First to Share


    • Microcontroller Contest

      Microcontroller Contest
    • Fandom Contest

      Fandom Contest
    • Crayons Challenge

      Crayons Challenge



    5 years ago

    Hi i4cc;

    The link to download the ino is broken. Could you post another one?

    Thanks a lot.


    5 years ago

    Adapted it for the ATMega368p chip running ardiuno uno, works great! was a good way to test and calibrate my scope! Now to 3d print a a case for it and make a few little script changes!

    Great little project!


    Reply 7 years ago on Introduction

    Hi prudhvi001,
    right now I 'm in train and can't test my suggestion.

    Anyway if you change the instruction:

    Timer1.pwm(PWMDAC1pin, i);

    in the case 2 (triangle) :
    Timer1.pwm(PWMDAC1pin, 1023);

    in the first occurrence and
    Timer1.pwm(PWMDAC1pin, 0);

    in the second one you should be substitute the triangular wave into a square wave.

    To add the fourth wave form at first three please wait some day to have a bit of free time. Anyway please try and tell me the result.
    See you next days