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.
The image of the arduino pro-mini board and the arduino IDE are shown below;
Fig. 2: Typical Arduino Pro-Mini Board
Fig. 3: Arduino IDE Software Window
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.
Fig. 4: External USB to TTL converter board for programming Arduino and serial communication
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 written for this particular project initializes the LCD in 4 bit mode and displays some initial text in it 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 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.
Fig. 5: Output Square Waveform on CRO with circuit set up on breadboard