Blog

More (than 2) hardware interrupts for Arduino Uno (or nano)!

when I was building my custom light 4 touch switch panel for my smartHomeDIY I discovered Arduino uno and nano has only 2 hardware interrupts, 
luckly,after searching for a while, I found a blog that helped me to overcome this limitation.
The solution is: pin change interrupts which are supported by the Arduino uno and nano: .

Regular hardware interrupts can be registered for raising or falling or change interrupt, but the pin change interrupts, as their name suggests, are only capable to deliver interrupts when the pin senses a voltage change in any direction, if you need to know which pin was changed you will have to read all pin states (or relevant pins) to know the new state and compare it to the old state (which you have to save on you program.
a small workaround in my case was to register for 2 hardware interrupts and for the other 2 required interrupts I used the pin chagne mechanism, but there are good news, the pin change interrupts are grouped into group of pins  So I just used different group for each switch and used a counter to ignore the second interrupt - leaving me with a raising interrupt.

  • A0 to A5
  • D0 to D7
  • D8 to D13

To read more about this topic I recommend the following:

  1. The blog where I found the answer by brainy-bits
  2. The source project for the pin change lib
  3. Arduino documentation here and here and here
  4. And more info on stackexchange
  5. And on the Arduino form and on more here
  6. My open source implementation here