This article discusses the external interrupt based on the Arduino pro-mini board which is programmed using the Arduino IDE version 1.0.3 downloaded for windows. The advantage of this board is that it comes in very small in size; different kind of connectors can be soldered according to the application requirements. It is very breadboard friendly and occupies very less space of a typical breadboard. The board also provides two external interrupt pins.
The image of the Arduino pro-mini board and the screen shot of 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 PC through 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 done all the things discussed in it. The Arduino pro-mini board has two external pins namely Pin2 and Pin3 which normally acts as digital I/O pins but can be configured as interrupt pins also. An interrupt can be triggered in pin2 or pin3 using the following three basic methods
Interrupt occurs when the pin is connected to a low valued voltage (low voltage triggered)
Interrupt occurs when voltage at the pin changes from high value to a low value (falling edge triggered)
Interrupt occurs when voltage at the pin changes from low value to high value (rising edge triggered)
Interrupt occurs whenever the voltage transition occurs at the pin i.e. interrupt for both low to high and high to low transitions (state change triggered)
The interrupt pins are usually connected with pull-up or pull-down resistors depending on the triggering method used by the interrupt pin. The pull-up resistor is used when the pin uses low voltage triggering or falling edge triggering. The pull-down resistors are used when the interrupt pin uses rising edge triggering. The project uses rising edge triggering and the triggering circuitry is very simple using a push button and a pull down resistor of value 10K. The Arduino IDE provides some functions to make use of the interrupt features of the Arduino board. The code written for this project make use of functions attachInterrupt() and detachInterrupt() which can be used to enable an interrupt on either of the two external interrupt pins or disable an already enabled interrupt respectively. The details of the functions are discussed in the following section;
The function attachInterrupt() is used to enable an interrupt on either of the two external interrupt pins along with configuring the type of triggering and also assigning an ISR to be executed whenever an interrupt occurs. The function has three variables, the first one is the pin number at which the interrupt signals expected to appear and the second one is the function which can act as the ISR. The third parameter defines the method of triggering.
The prototype of the function is given as the following;
void attachInterrupt ( interrupt_pin, isr_function, trigger_method );
The return type of the function is declared as void and hence the function returns nothing. The first parameter is the interrupt pin which determines at which pin the interrupt should be enabled as mentioned below
0 for enabling the interrupt on pin2
1 for enabling the interrupt on pin3
The second parameter points to the function which should be made as the ISR. The parameter should be provided with the name of the function which is required to act as an ISR.
The third parameter defines the kind of triggering that should be enabled on the interrupt pin mentioned by the first parameter. The four different values and their details that can be applied to the third parameter are given below;
LOW to trigger the interrupt whenever the pin is low,
CHANGE to trigger the interrupt whenever the pin changes value
RISING to trigger when the pin goes from low to high,
FALLING for when the pin goes from high to low.
The function detachInterrupt() is used to disable the interrupt on either of the interrupt pin at which the interrupt is already enable by the function attachInterrupt(). The function has no return value but one parameter which is the pin number on which the interrupt should be disabled.
For example to disable the interrupt on the pin number 2 one can use the following statement;
To disable the interrupt on the pin number 3 one can use the following statement;
The code initializes the pin number 6 as output at which an LED is connected using the function pinMode() and later in the code it continuously write a value to that particular pin using the function digitalWrite() which are already discussed in a previous project on how to get started with the Arduino.
The function attachInterrupt() is used to enable the interrupt on the pin number 2 with assigning an ISR function. The pin is configured as rising edge triggered. Each times an interrupt occurs the ISR inverts the value that is continuously written to the pin number 6. There is also a condition written inside the function loop() which will continuously check a count to become greater than 10 which is incremented inside the ISR. After 10 interrupts the condition becomes true and it disables the interrupt using the function detachInterrupt().
The code also displays some text on the LCD with the help of the functions from the library <LiquidCrystal.h>. The important functions provided by the library <LiquidCrystal.h> are already used and explained 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.
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 interrupt can be triggered by pressing the push button which will make a low to high transition on the interrupt pin. The ISR runs each time the interrupt occurs and one can observe the LED changing its state from off state to on or from on state to off for the first ten key press.