Arduino Projects    |   Raspberry Pi  |     Electronic Circuits   |   Electronics Reference Design Library  |   AVR    |    PIC    |    8051    |    Electronic Projects

How To Make a Simple Variable Frequency Generator Using Arduino

Summary

Developed By: 
Ajish Alfred
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.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, 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 boards communicates with other devices using digital input/output analog input/output standard communication ports like USART, IIC, and USB etc.
How To Make a Simple Variable Frequency Generator Using Arduino

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;

Arduino

 

Arduino

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.

Arduino

It is assumed that the reader has gone through the project how to get started with the arduino and tried out all the things discussed there. 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 analogRead() is already used in the previous projects on how to use analog input and analog output of Arduino board, how to use Arduino to display sensor values, how to make dynamic sensor display using Arduino, how to save sensor values in the EEPROM of the Arduino.

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);

A previous project on how to generate square wave using the Arduino board explains more about the tone generating functions and their usage.

THE CODE

The code reads the analog value from the potentiometer connected at the analog pin A0 using the function analogRead(). The same value is then used to generate a square wave by passing the variable which stores the analog value to the function tone(). The value which is the actual frequency of the square wave is displayed in the 16*2 LCD with the help of functions provided by the library <LiquidCrystal.h>. The functions which can be used to access the LCD are already discussed in previous projects on how to interface an LCD, how to display sensor value on LCD, how to connect the LCD with the PC and how to make an LCD scrolling display.The code continue generating the wave for one second by waiting using the function delay() till the function noTone() is called. The details of the functions delay() are already discussed in the previous projects on how to get started with the Arduino board  and how to use the digital input and output of the Arduino board. The function noTone() then stops the currently generating waveform and the infinite loop does all mentioned process again and again.

When the coding is finished one can verify and upload the code to the Arduino board as explained in the project how to get started with the Arduino. The waveform can be observed using a CRO which is connected to the pin number 8 and one can find that as the potentiometer is varied the frequency is varying and the value of the currently generating frequency can be read from the LCD.

 

Circuit Diagram

Video

Code

This Code is only visible to Registered users. Please Login/Register

 

Components

Resistor Image
Resistor

Resistor is a passive component used to control current in a circuit. Its resistance is given by the ratio of voltage applied across its terminals to the current passing through it. Thus a particular value of resistor, for fixed voltage, limits the current through it. They are omnipresent in electronic circuits.

...
LEDs | Light Emitting Diode
LED
 
Light emitting diodes (LEDs) are semiconductor light sources. The light emitted...
16 x 2 LCD | 16x2 Character LCD Module
LCD

 

LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments...

Arduino Pro Mini
Arduino Pro Mini

The Arduino Pro Mini is an ATmega168 based microcontroller board. The board comes with built-in arduino bootloader. It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 8 analog inputs, an on-board resonator, a reset button, and holes for mounting pin headers....

Browse 4m+ Electronic Products


 
Pick the right product for your next design project with "Mouser Store". Mouser Electronics brings broadest range of semiconductors and electronic components from over 500 industry leading suppliers. 
 
Mouser specializes in the rapid introduction of new products and technologies for design engineers and buyers that includes semiconductors, interconnects, passives, and electro-mechanical components. Providing the best possible service with the flexibility of not requiring a minimum order and same-day shipping, Mouser has it all.
 
 
 
 
When you need the right part right now, think of Mouser
 
Thank you
Team EG

 

Inexpensive, Simple, Easy-to-Use Microcontroller Boards By Texas Instruments

Starting at $9.99 Buy Now

Starting at $17.00 Buy Now

Starting at $12.99 Buy Now

Starting at $12.99 Buy Now

 

You are here