• UFRJ Nautilus

How to make a simple function generator with an Arduino

Updated: May 7

A function generator (or signal generator) is a device that generates electrical signals with different shapes, frequencies, and amplitudes. Among these shapes, square waves, triangular waves, sawtoothed waves, and sinusoidal waves are the most common that can vary the frequencies and peak-to-peak voltage. Learn here how to generate the main waves in a practical way using an Arduino.

A workbench function generator is really useful for many applications, mostly to simulate and check an electronic circuit. Its main use occurs in oscillating circuits, filters, and amplifiers.

Function generator

We use an oscilloscope to make usage signals that are being received over time. With an oscilloscope, we can look at the shape of a wave at a point of the circuit.

Osciloscópio com onda senoidal. Gerador de Funçoes
Oscilloscope with sensorial waves

There is a problem in using a signal generator: a quality device costs from $180, in other words, it has a high cost when its need for use is punctual and simple. In that case, it's possible to an Arduino works as a basic generator of functions and accessible through your PWM outputs. It allows us to make tests for simple circuits in a fast, cheap, and practical way.

See below the design of the main waveforms.

1. Square Wave:

The square wave is a digital signal that works with alternating logic levels: 1(maximum amplitude) and 0 (minimum amplitude). It is used as a time reference in clock signals and computing in the serial transmission of information on computer networks.

Reproducing this type of wave in Arduino is very simple, there is the tone() function that is responsible for the generation of square waves, just needing to make clear the output pin and the desired frequency of the signal, as can be seen in the example below with a frequency 50 Hz.

Simulation in TinkerCad
// Project 20 - Arduino as a frequency generator (square wave)

void setup() {
    Serial.begin(9600); // Starts the Serial Monitor

void loop() {
    // Prints the generated frequency on the screen
    Serial.println("the frequency is: 50 Hz");
        tone(6, 50); //define the pin in OUTPUT, and the frequency generated in the pin
        delay (2000); //Generates the frequency for 2 seconds