
In a basic Arduino sketch, if you want to take action based on the status of a digital input pin, you’d check the state of the pin repeatedly until a particular condition is met. However, as your sketches become increasingly complex, you’ll find that it’s not always the best way to do this. EngBlaze posted a pair of guides to using interrupts so that you can execute code asynchronously in Arduino sketch. Here’s the analogy they use to illustrate the difference:
Imagine you’re sitting on your couch, enjoying a frosty brew and watching a movie after a long day. Life is good. There’s only one problem: you’re waiting for an incredibly important package to arrive, and you need it as soon as possible. If you were a normal AVR program or Arduino sketch, you’d have to repeatedly stop your movie, get up, and go check the mailbox every 5 minutes to make sure you knew when the package was there.
Instead, imagine if the package was sent Fedex or UPS with delivery confirmation. Now, the delivery man will go to your front door and ring the doorbell as soon as he arrives. That’s your interrupt trigger. Once you get the trigger, you can pause your movie and go deal with the package. That’s your interrupt service routine. As soon as you’re done, you can pick up the film where you left off, with no extra time wasted. That’s the power of interrupts.
The first guide covers using hardware interrupts, such as switches and the second discusses timer interrupts, so that you don’t have to repeatedly check if a certain amount of time has passed when executing code on a particular interval. The guides are complete with code examples to give you a jumpstart on your own interrupt-driven Arduino project. [via Reddit]










A good example of interrupt use is the firmware in the repraps and makerbots. It uses interrupts to jump back and forth between running the steppers as well as receiving data and handling requests for information like temperature and location.
Hi,
this is a very good and clear explanation about timer interrupt.
It helped me to understand how interrupt work.
Thanks for the code ready for use.
Valerio
// What's Trending
Raspberry Pi Design Contest
Ten Tips for Adhesive Tape
Seventeen Sneaky Secret Hides
I Have a (Puzzling) Dream
10 Things to Connect to Your Raspberry Pi
Maker Faire: Day Two
47 Raspberry Pi Projects to Inspire Your Next Build
// What's Shared
A better way to slice a pumpkin
DIY Nerf Darts
100 Dollar Store Organization Ideas for Craft Rooms and Beyond
In the Maker Shed: Minty Boost USB Charger
Mad’s Mouse House
Lace Princess Crowns
I Have a (Puzzling) Dream
Play the Rings of a Tree Trunk Like a Record
// Most Commented
DIY Hacks & How To’s: Get Emergency Power from a Phone Line
Resin Casting: Going from CAD to Engineering-Grade Plastic Parts
Ten Tips for Screws and Screwdrivers
Ten Tips for Better Measurement
Makers on TV: Big Brain Theory
Arduino Announces New Wireless Linux Board
Is it a Hackerspace, Makerspace, TechShop, or FabLab?
Tool Review: BioLite CampStove