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 refered to as open source hardware and 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.Since the Arduino board can act as a stand-alone system it should have 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 can communicate with other devices using digital input/output analog input/output standard communication ports like USART, IIC, and USB etc.
A microcontroller based system sometimes controls other devices by simply generating pulses of certain frequencies and duty cycle. This normally happens when the connected device has no processors inside it like in the case of LED display system or motor driving system using PWM based circuits or any kind of switching system. This particular project demonstrates how simple is to code the Arduino board to generate the square waves of any required frequency.
The working of this project is explained based on the Arduino pro-mini board and the IDE version 1.0.3 for windows. The advantage of this board is that it comes in very small in size; 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.
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.
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 IDE provides two functions 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;
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 );
The parameter pin_numbershould be provided with the number of the pin at which the square wave is required to be generated. As an example to generate the square wave in a pin number 8 the first parameter provided in the function call should be 8.
The second parameter of the function is the frequency which should be provided with the required frequency in Hertz. As an example to generate a square wave of 1 KHz the second parameter in the function call should be equal to 1000.
When the square wave need to be generated only for a particular duration then the required duration in milliseconds should be provided as the third parameter. If the square wave need to be generated until it is stopped by the noTone() function then the third parameter can be avoided in a function call. 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 );
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;
The code then generates three different frequencies 10Hz, 100Hz and 1Khz using the function tone() for a duration of 10 seconds. The duration is actually generated with the help of delay() function and the wave is stopped using the function noTone() after the delay() returns. The code also glows an LED connected to the pin number 8 using the functions pinMode() and digitalWrite(). The details of the functions pinMode(), digitalWrite() and 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.
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.
For more detail: How To Generate Square Wave Using Arduino