How To Make a Simple Variable Frequency Generator Using Arduino

A frequency generator is a very handy device in electronic design, development, testing and trouble shooting. It is such a kind of device which can generate the required frequencies which can be then applied directly to the target device for testing it. There are frequency generators which can generate the required waveform like sine wave, saw tooth wave etc. but for normal applications the square wave generation with variable frequency is sufficient.How To Make a Simple Variable Frequency Generator Using Arduino
This particular project explains how to make a variable frequency generator with the help of Arduino.The Arduino is referred to as an easy prototyping platform which has been popular among both hobbyist and experts and widely used in industries as well.
Any AVR microcontroller based board which follows the standard Arduino schematic and is flashed with the Arduino bootloader can be called an Arduino board. The Arduino is open source hardware where the hardware schematic is open anybody can use those schematic to develop their Arduino board and distribute. The Arduino IDE is also open source and anybody can contribute their libraries to the Arduino.
All Arduino boards should be compatible with the Arduino IDE which can be used to program the Arduino boards. Arduino board can act as a stand-alone system with capabilities to take inputs, How To Make a Simple Variable Frequency Generator Using Arduino schematicprocess 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 boards communicates with other devices using digital input/output analog input/output standard communication ports like USART, IIC, and USB etc.
[/nextpage][nextpage title=”Description” ]There are different varieties of Arduino boards available among which one can find a board which suits the particular application. In this project the Arduino pro-mini board is used since it comes in very small in size and any kind of connectors can be soldered on its periphery according to our requirements. It is very breadboard friendly and occupies very less space of a typical breadboard.The image of the arduino pro-mini board and the arduino IDE are shown below;
Since the arduino pro-mini board has no circuitary for interfacing it with the serial port or the USB port of the PC, an external USB to TTL converter board is required to connect it with the PC. This hardware helps in programming the arduino board and also helps in the serial communication with the USB port of the PC.

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” ]


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top