Arduino Function Generator: Square Wave with Variable Duty Cycle

Andy Kong
2 min readDec 23, 2020
A beautiful but expensive piece of electronic test equipment

Hi! Not everyone can afford the $2000 for a beautiful function generator like this Agilent 33210A, but everyone deserves to have basic function generation capabilities. So, today I’m going to show you how to make a basic function generator using everyone’s favorite microcontroller: an Arduino Uno!

In this post I’m going to go over some basic code, and how to set up an LED to test it out.

Hardware setup

Set up the LED+resistor with positive lead in pin 9 and the negative plugged into ground. Plug the Arduino into your computer.

Yes, I have a genuine Arduino, but knockoffs are fine too! Preferable, even, cause you can break them without feeling bad.

We’ll start with the basics:

Square Wave Generator, 50% Duty Cycle

To use this, just change blinkrate to whatever frequency you’d like the pin to output.

--

--