Summary of How To Make a Simple Variable Frequency Generator Using Arduino
Summary: This article describes building a simple variable-frequency square-wave generator using an Arduino (Arduino Pro Mini). It reads a potentiometer via analogRead on A0 to set frequency, then uses tone(pin, frequency) and noTone(pin) to produce or stop the square wave. A USB–TTL converter is used for programming the Pro Mini. The project uses standard Arduino IDE functions and hardware-compatible AVR boards.
Parts used in the Variable Frequency Generator Using Arduino:
- Arduino Pro Mini board
- USB to TTL converter board
- Potentiometer
- Connecting wires
- Breadboard or PCB for mounting
- Power supply (compatible with Arduino Pro Mini)
- Output connection (e.g., probe, jumper to target device)

process the input and then generate a corresponding output. It is through these inputs and outputs that the Arduino as a system can communicate with the environment.

The Arduino board has several digital pins which can be configured as digital I/O pins and among them some can also be used as analog output pins. There are dedicated analog input pins in most of the Arduino boards. The Arduino pro-mini board has 8 analog input pins marked as A0, A1 up to A7. In this particular project the variable pin of a potentiometer is connected at the analog input pin A0.
The Arduino IDE provides functions to access analog input and analog output of the board. The code written for this project uses the built-in function provided by the Arduino IDE namely analogRead().
analogRead()
This function can read an analog value from an analog pin mentioned in its argument and can returns that value. Suppose if there is a variable ‘var’ into which the vlue of the analog pin A0 is need to be read into, one can use the analogRead() function as shown below;
var = analogRead(A0);
The above statement will enable the built-in ADC of the arduino’s microcontroller which then converts the analog value to its 10 bit digital equivalent and then stores in the variable ‘var’. The variable ‘var’ is expected to be of the type integer.
The Arduino IDE provides certain functions to generate a square wave at a particular frequency which is make use in this project. The functions are namely tone() and noTone() for start generating a square wave at a particular frequency and to stop the square wave respectively. The details of the functions are discussed in the following section;
tone()
The function tone is used to generate a square wave at the required, with a required frequency and also for a required period of time. The function basically has three parameters of which the first one indicates the pin number at which the wave can be generated, the second one is the frequency of the square wave and the third parameter is the time duration until which the wave should continue. The prototype of the function is given as follows;
tone ( pin_number, frequency, duration );
As an example to generate a square wave at a pin number 8, with a frequency 1KHz and for a duration 5 seconds the following statement can be used.
tone ( 8, 1000, 5000 );
When the wave is required to present at the particular pin until it is stopped by the noTone() function call the following statement can be used;
tone ( 8, 1000 );
noTone()
The function noTone can be used to stop the square wave exist in the pin number at which it has been initiated by the tone() function call. The function has a parameter which is the pin number where the wave has to be stopped. As an example the function can be used to stop the wave generated at the pin number 8 as shown in the following;
noTone(8);
[/nextpage][nextpage title=”Circuit Diagram” ]
- What Arduino board is used in the project?
The Arduino Pro Mini board is used in this project. - How is the frequency controlled?
The frequency is varied by reading a potentiometer value on analog pin A0 using analogRead and using that value to set tone. - Which Arduino function generates the square wave?
The tone() function is used to generate the square wave at the required frequency. - How do you stop the generated square wave?
The noTone(pin) function is used to stop the square wave on the specified pin. - Do you need an external interface to program the Pro Mini?
Yes, a USB to TTL converter board is required to connect the Pro Mini to the PC for programming and serial communication. - Which analog pin is the potentiometer connected to?
The potentiometer variable pin is connected to analog input A0. - What does analogRead() return?
analogRead() returns a 10-bit digital equivalent of the analog input value and is typically stored in an integer variable. - Can tone() run continuously until stopped?
Yes, calling tone(pin, frequency) without a duration produces the wave until noTone(pin) is called.
