Arduino Uno Interrupt Demo with 7-Segment Display © GPL3+

This simple tutorial project shows how to program interrupts in Arduino along with 7-Segment display interfacing.

  • 1 comment
  • 4 respects

Components and supplies

About this project

This is a simple tutorial project.  It describes how to use interrupt in Arduino Uno.

The interrupt is a mechanism in which we can achieve a little multitasking and automation of microcontroller operation. The general digital input requires continuous polling of the pin. But in this method, the microcontroller is occupied in polling, thus wasting time.

This problem can be solved with interrupt. Here, the microcontroller performs is assigned task. When an interrupt occurs on a particular pin, the microcontroller stops its current operation, serves the interrupt by calling interrupt service routine, and again returns to its regular operation at a place where interrupt was called. This facilitates better use of microcontroller.

The Arduino Uno has two hardware interrupts - Pin 2 and Pin 3. We can program these pins for interrupt using the following function:

attachInterrupt(digitalPinToInterrupt(pinNumber), nameofISR, mode);

In this project, a seven-segment display is used. The seven-segment display is of common anode type. It is interfaced with Arduino via 74LS47 BCD-to-Seven Segment Display decoder IC. We can directly connect seven-segment display with Arduino, but it will use seven pins of Arduino. While using 74LS47 decoder IC requires only five pins of Arduino and it enables some facilities like blinking, which is hard to program without decoder.

The schematic diagram is as below.

Here, the power pins of IC and Arduino are not shown. But remember to connect pin-8 of 74LS47 to ground and pin-16 to +5V. Also connect Arduino's ground with IC's ground. The +5V to IC and seven-segment display can be applied from Arduino, but its better to use external power supply for overload protection of Arduino.

The circuit works as follows:

The Arduino continuously displays 0 to 9 counting on seven-segment display with 1 second delay and blinking of 500 ms off time. When the switch is pressed, it resets the count value to 0. After that, the counting continues as before. Every time the switch is pressed, it resets the count. 

Now, the 74LS47 decoder works as follows. It is a 16-pin IC. It has 4-bit BCD (Binary Coded Decimal) input - A, B, C and D (A is LSB and D is MSB), connected to Arduino's four digital pins; and 7 digital outputs (a to f), which are connected to 7 inputs (a to f) of seven-segment display via 180 ohm resistors. It has three more inputs, the detailed description of which can be found in its datasheet. Here we have used one input, RBI, to blink the display. When a low signal (logic 0, GND) is applied to RBI pin, all seven outputs will become inactive, thus turning off the seven-segment display. This can also be used to blink the display.

The seven-segment display used here is of common anode type, because the outputs of 74LS47 decoder are active low. If you use common cathode type display, the 74LS47 cannot be used. The solution is HEF4543B decoder which has active high output which are compatible with common cathode display.

Now the following video shows the working of the circuit.

Working of Circuit

The code of this circuit is attached. The code is explained in comments. Study it with the working description of the circuit.


Arduino Interrupt with 7-Segment DisplayArduino
int num = 0; // count value
void setup() {
  // put your setup code here, to run once:
  pinMode(4,OUTPUT); //four digit BCD output
  pinMode(9,OUTPUT); // RBI pin
  attachInterrupt(digitalPinToInterrupt(2), resetNum, FALLING); //Interrupt initialization
//  Here the interrupt is enabled on pin-2, the ISR function assigned is resetNum and 
//  mode is FALLING means when a falling edge occurs on pin-2, the interrupt is counted.
  digitalWrite(9,HIGH); //Set RBI to HIGH to turn ON the display

void loop() {
  digitalWrite(4,bitRead(num,0)); //display 4 BCD digits of number

  delay(1000); //1 Second Delay

  digitalWrite(9, LOW); //Turn OFF seven-segment display for blinking
  delay(500);           // 500 ms delay
  digitalWrite(9, HIGH); //Again turn ON the display
  num = num + 1; //Count next
  if(num == 10) //If count exceeds 9, reset to 0
    num = 0;

void resetNum() { //Interrupt ISR function; Called when interrupt occurs
  num = 0; //Reset count to zero
  digitalWrite(4,bitRead(num,0)); //display reset value on display


Similar projects you might like

Guess the Number With Arduino KeyPad

Project tutorial by Giovanni Gentile

  • 3 respects

Control a 7 Segment Display with a keypad!

Project tutorial by Isaac100

  • 2 respects

Launch Pad Count Down Sequence Display

Project in progress by Douglas Frey

  • 2 respects

Know the Temp of Your Home From Anywhere with Arduino Cloud!

Project tutorial by Isaac100

  • 11 respects

Safe City: A Device to Keep You Safe

Project tutorial by Patel Darshil

  • 9 respects

Water Softener

Project tutorial by moty

  • 7 respects
Add projectSign up / Login