This video was featured on Hackaday.com on 3/8/2011
This tutorial was featured on the official Arduino blog on 3/9/2011
Interrupts – An extremely useful, yet often feared element of microprocessors. Interrupts allow you run a program, while still being able to react to asynchronous input from the outside world. On many platforms then can be confusing to implement, but the arduino makes it easy! In this week’s episode, I’ll show you how to use a hardware-debounced button to activate a hardware interrupt on the arduino. I’d suggest you go check out episode 2, where I initially introduced button debouncing, if you haven’t already. I won’t be covering timer interrupts in this episode, since I recently wrote an extensive blog post about using them. Enjoy the video!
EDIT: You can find a great run-down of debouncing techniques and problems here: http://www.ganssle.com/debouncing.htm (Thanks Jope)
You can download the files associated with this episode here:
Distributed under the GNU General Public (Open-Source) License.
Please Attribute and Share-Alike.













March 8, 2011 at 3:03 am
Oh my God, don’t tell me, this is the last one. It will be great, to produce more, far more. E.g. interface with sensors, other hardware, 3 wire display etc. I know, that all is on arduino.cc website, but to have it on video is far more fun… Best regards from Slovakia.
March 8, 2011 at 3:36 pm
Just going on a break. I’m hoping to bring them back soon. I have to focus on my semester right now.
March 12, 2011 at 11:54 am
Right! I am more than looking forward to see another episodes, and I am wishing You all the best with Your semester.
Pingback: Beginner concepts in electronics and Arduino - Hack a Day
March 8, 2011 at 5:33 pm
Great job. Debouncing is something everyone get bitten by early. Your tutorial is the best at explaining the problem and at explaining the hardware solution. Look forward to more tutorials after you break.
Pingback: Beginner concepts in electronics and Arduino | Boomeroo Web Resources
March 8, 2011 at 7:34 pm
Good luck with your classes!
If you ever produce other arduino videos, I look forward seeing them.
Maybe you’ll be the Forrest M. Mims III for the 21st century.
March 9, 2011 at 3:28 am
Hey Jeremy!
The series is great! It’s very informative and helpful.
Looking forward for some more of these…
I learned a LOT!
I have 2 questions please…
What about having more than 2 buttons (each connected to an interrupt pin)?
I’m sure there’s a way to connect more than 1 button to 1 interrupts (using keypads and so), am I right?
How can that be done?
The other question is if there is a way of having more than 2 interrupts (is that needed at all, once you can connect more than 1 button to an interrupt?)
I know that in some programming there is something called “interrupt extender” but don’t know more than that.
Looking forward for your answer.
Thank you very much in advance!
Golan
March 9, 2011 at 10:14 pm
The arduino uno only supports 2 external interrupts. The mega can support up to 5. If you need more, you’re probably better off using a platform that supports it natively. The The MSP430 supports interrupts on all inputs.
Pingback: Must-See Beginner Tutorials For Arduino | dev.SquareCows.com
March 9, 2011 at 11:38 am
Why is the Schmitt trigger needed? Why isn’t the capacitor smoothed input adequate for hardware debouncing?
March 9, 2011 at 10:15 pm
Technically, you can do without the schmitt trigger. I just wanted to show how it can be used to “straighten-out” a signal. Plus I wanted to invert it anyways (also for the purposes of illustration).
March 9, 2011 at 5:33 pm
Thank you for your contribution to the community. The videos in your series were of very good quality. The material from each was well presented, in an easy to follow fashion. A valuable resource indeed.
Cheers!
March 9, 2011 at 10:15 pm
thanks!
Pingback: Must-See Beginner Tutorials For Arduino | inmotion.pt
Pingback: hackaholicballa - Beginner concepts in electronics and Arduino
March 14, 2011 at 3:50 pm
Nicely done, Jeremy. As an older Engineer I appreciate you younger ones taking the time to share with us all. When I was in college we were using Watfor & Watfiv and card readers. I do a little prgramming with AutoLISP in my Engineering practice so your programing was not difficult to follow.
I have a client wanting me to put together for him a model train car that will have a turrent activated as it goes by sensors and fire a rotating “gattling gun” (nerf darts). I hope to use the Arduinos to accomplish this. Not sure about which way to go with the sensors.
Best of luck in your classes!
March 15, 2011 at 11:43 pm
Sounds like a cool project! There’s a few ways you could accomplish this. One cheap and easy way may be to use simple IR LEDs and phototransistors. The LEDs would shine on the phototransistors when the train goes by, and the train would know to start firing nerf darts.
March 15, 2011 at 9:12 pm
well first of all gotta congratulate the excellent tutorials arduino,: P I finally begin to understand electronics. I would like to make a suggestion, create a tutorial with the ethernet shield, with web interface php server for example to control the temperature and light in a room and can turn a heater.
Sorry my poor english.
March 15, 2011 at 11:43 pm
I’d love to, but I’m having trouble getting a hold of one right now. They seem to be out of stock….
Pingback: Electronics-Lab.com Blog » Blog Archive » Tutorial 10 for Arduino: Interrupts + Debouncing
March 22, 2011 at 7:35 am
Hi,
a very good guide to debouncing can be found here:
http://www.ganssle.com/debouncing.htm
March 23, 2011 at 1:00 am
Wow, that’s a superb post! Thanks for sharing it. I’m going to include it in my post above.
April 6, 2011 at 9:24 am
Man this is awesome. I am used to programming the 68HC11 microcontroller, and everything that you did here would be a gigantic chore! Setting up interrupts and keeping track of the stack, manually configuring registers and having to use jump statements to control program flow rather than loops.
I just ordered an UNO and I am waiting for delivery. This looks uber awesome. Thanks for the tutorials
April 6, 2011 at 10:28 am
I’ve recently been doing some assembly level MSP430 programming, and handling all this kinda stuff is certainly a huge pain. Gotta love the simplicity of the arduino.
June 6, 2011 at 12:26 am
Great videos! Just would like to know what specific Schmitt trigger you were using, I need to do hardware debouncing because I’m using a interrupt. What is the specific product number and where did you purchase it? Thanks in advance Jeremy!
-Scott
June 10, 2011 at 10:22 pm
It’s in the parts list linked above. However, you can actually not use the Schmitt trigger and it will still work fine.
June 13, 2011 at 10:31 pm
Thanks for the reply. I thought I needed to do hardware bouncing if I was checking a switch in an Interrupt Service Routine. Is that not true?
June 14, 2011 at 7:51 am
You do, but it will still debounce sufficiently using the resistor and capacitor without the trigger, if you want.
June 14, 2011 at 9:27 pm
Thanks Jeremy, I’ll give it a shot.
July 21, 2011 at 10:52 am
Hi About Timer interupts.
is there a chip or sorcet that givse a pulse 10 Hz to an not 10.00000001 Hz .
so that i we make a Acurit Clock ClockFunction.
outing that 10 Hz to a interrupt on a pin where the pin is connectet
?????????????????????????????????????????????????
volitail int tenthofsec=0;
volitail int secunds=0;
volitail int minuts=0;
volitail int hour=0;
void setup(){
attachinterrrupt( 0 , countTime , Fallng);
}
void loop(){
displayTime();
}
void countTime (){
tenthofsec++;
if (tenthofsec==10) {
tenthofsec=0;
secunds++;
}
// secunds
if (secunds==60) {
secunds=0;
minuts++;
}
// minuts.
// and so on…….
}
void displayTime() {
// display the time on perhaps 7 segmant display or something.
}
September 25, 2011 at 4:09 am
Hej Jeremy, many thanks for your easy anderstanding and clear way to illustrate your tutorials, I have great plesure of seeing them . But your debounce circuit migt weld a small pushbutton or reed contact because you short the capacitor , so please add a small resitor ex. 100ohm in serial with
the pushbuuton.
Best regards , and keep up your studying and show us some more in your spare time onely.
Jan
October 28, 2011 at 2:23 pm
Excellent point. Thanks Jan!
November 3, 2011 at 7:15 am
Hi Jeremy,
Great tutorials.
But i have a I2C RFID reader YHY502ATG with a pin which drops low wen i place an RFID chip in front of it.
When i use a readdigital it works perfectly. but i don’t want to check the ports everytime i loop. because there are HW interrupts
But when i connect that pin to my hardware interrupt it won’t work.
Kind regards
Johan
November 3, 2011 at 7:28 am
o btw i my hardware interrupt trigger works but the RFID reader isn’t anymore while its started from the interrupt.
November 28, 2011 at 4:27 pm
Are you sure the interrupt pin is setup correctly as an input? That might explain why the RFID stops working when hooked up to a different pin. You might also want a pull-up resistor.
November 16, 2011 at 11:31 am
Hi Jeremy – The arduino is a fantastic project and your tutorials are wonderful.
Many years ago (well over 20!) I worked on embedded systems in 8048 and 8051. It was really hard work to make them do anything at all!
I gave up that strand of my career a long time ago and I’m now coming back to it purely for FUN and really having a great time, thanks to the arduino project and your tutorials.
Thanks again
Neil
November 29, 2011 at 3:29 pm
Great tutorial Jeremy, I think this should help me with my current problem of turning on and off the +5V to a 7-segment CA display as right now it works, but not all the time. Since I don’t have a schmitt trigger, I will try just the resistor and capacitor as you have suggested to others.
December 2, 2011 at 11:34 am
Hey Jeremy, great tutorials! They definitely cleared up a lot for me. I was wondering if you by any chance know of any good tutorials for software debugging. I’m currently working on a project using two interrupts and I’m getting very bad bouncing. You should know that my software is very time sensitive. Any help would be appreciated. Thanks
December 9, 2011 at 11:18 am
Dan,
Were you able to find a solution for your bouncing issues?
Bob
December 5, 2011 at 5:48 am
Thanks for the great tutorials Jeremy! I have a problem with the hardware debouncing though… It only works when i have the serial port enabled in the code and the SerialPrint command in tne beginning of the loop to monitor the state of the button. Just like in your .pde on this tutorial. if i delete these two lines and make the code identical to that of the switch2.pde from your second tutorial, then it doesn’t work well. Do you have any idea why this happens? I don’t see why the state of the serial port should affect it…
January 2, 2012 at 6:26 pm
That is strange indeed. Are you using the same resistor and capacitor values that I used?
January 3, 2012 at 2:26 am
Yes, the values are the same, but maybe they are not correct for the specific switch i’m using. The debouncing circuit might not work properly (doesn’t actually give the switch enough time to stop bouncing), but maybe enabling serial communication puts just enough “strain” on the arduino so that there is an ever so slight delay in reading the switch that acts kind of like debouncing. I’m using a button, similar to those that are on the arduino itself. I’m thinking that I should probably find an oscilliscope and actually measure how long the bouncing lasts, so i can do the math and find appropriate resistor and capacitor values. I had tried reading the signal with an oscilliscope using a little switch from a PC case (the ones for power and reset), but it turned out that it already worked perfectly without bouncing…
January 3, 2012 at 11:53 am
It seems unlikely that adding serial would do that. Your best bet is probably to whip out an oscilloscope, as you suggested, and measure the bounce time.
December 5, 2011 at 5:59 pm
What is the program that you are using for the circuit diagrams at 10:20 in your tutorial?
January 2, 2012 at 6:27 pm
That’s CadSoft Eagle
December 9, 2011 at 11:16 am
Great work Jeremy!
Definitely the best Arduino tutorials that I have come across.
I have a question about using a piezo sensor as a vibration detector.
Here is the scenario:
Utilizing the piezo sensor that has a magnet attached to it and mounted on a sheet of metal I want to be able to detect the presence of vibration. I’d like to be able to set a range that I can use to filter out low level vibrations based on comparing the analog value to a value I set in a variable. If the sensor detects vibration within my trigger range I will increment a counter variable and compare the count to another variable.
I’d prefer to utilize an interrupt to trigger the event but I’m not sure what my best approach would be.
Should I output the piezo through a Schmitt trigger and have the output of the Schmitt trigger go to int0 or int1 and then based on voltages do my filtering?
I’ve played around with different sketches and the piezo does work the way I need it to work but I need to clean up the piezo’s output so I can work with more consistent values.
Sketches that I’ve used for testing.
http://www.arduino.cc/en/Tutorial/KnockSensor
http://arduino.cc/en/Tutorial/Calibration
Regards
Bob
January 2, 2012 at 6:28 pm
Have you tried implementing a low-pass filter to remove some of the higher-frequency noise? That might allow to care care of your issues in hardware alone. I explain one in my 14th episode.
December 11, 2011 at 9:59 pm
Jeremy,
The information you have put together is excellent and the video are very easy to understand. I am very new to the Arduino world but it seems like the information is very user friendly. With that said I would like to see if you or someone on your blog can help me with some Arduino code. Here is a brief description of what I am trying to do.
Basically I want to use the programming flexibility of the Arduino to make a dynamic analog signal conditioner. There will be two input signals V1 and V2 and they range from 0v – 5v with a center or neutral point if 2.5v. I have a motor controller that has the ability to have analog input devices like a potentiometer or an analog joystick. The input signals are 0v-5v DC with a 2.5v center point. When the analog device is calibrated correctly it is easy to achieve the 0v-5v DC.
I would like to add some of the following functions to the signal before sending it to the motor controller.
1: Change the original signal voltage to allow for adjustment like min or max setting with a 2.5v center
2: Change one axis input based on the second axis input like a limitation filter. (i.e. if axis one goes higher axis two is limited)
3: Change the original signal voltage using an acceleration or deceleration algorithm
4: Change the original signal voltage using a spike filter so that unwanted spikes are filtered out.
As an added feature I would like to be able to select the code used by changing a set of dip switches to go from one set of code to the other without uploading new code to the Arduino each time I need to change the signal condition.
I am asking for any help or suggestions for code samples or for a complete subset of code.
Thanks in advance for any help or suggestions.
January 17, 2012 at 2:27 pm
Jeremy, these are EXCELLENT!
I am new to Arduino, but have a long background in assembler programming. When the interrupt routine ends, where does the code go back to. In asm when an interrupt occurs, the current program counter (PC) is pushed to the stack. At the end of the interrupt routine if you execute a return the PC is pulled from the stack and the program picks up where it was. If you don’t want that to happen there are asm instructions to adjust the stack and you would jump to some other place you code.
I don’t know how to control the code at the end of the interrupt routine. Can you give me some guidance on this.
January 21, 2012 at 10:39 pm
As with assembly, the program will jump back to wherever it was previously in the code upon the completion of an interrupt routine. Naturally, some actions are atomic, so it might not be as easy to trace the exact stack pointer location as you can with assembly.
January 20, 2012 at 9:22 pm
Fantastic compilation of videos & your understanding of electronics ( & associated crafts ) is obviously very good.
I love everything about your presentations.
Content, manner, approach.
Good stuff!
January 21, 2012 at 10:49 pm
Thanks! Glad you’ve enjoyed them.
January 25, 2012 at 12:42 pm
Just wanted to say thanks for providing such clear and detailed tutorials. It has really helped me bridge the gap between my programming and electronics backgrounds; which until now have been completely separate. I’ve watched all of your tutorials and I can’t wait to dive in when my Uno arrives in the mail.
Quick question: Why are there only 2 external interrupts accessible through the Arduino Uno when the ATMega328 MCU supports 24?
I only ask because I plan to eventually address at least 3 interrupts through an ATTiny48 which I want to program through the Uno… But now I’m not sure if this is possible.
February 13, 2012 at 10:48 am
It just has to do with the way they decided to write the Arduino IDE. They sacrificed some functionality to make it easier to use. You can still access the interrupts by programming in C directly.
Pingback: Working of Interrupts in Atmega8L
March 24, 2012 at 10:47 am
“You can still access the interrupts by programming in C directly”
Any info on this?
April 11, 2012 at 6:02 am
Cheers for the tutorial. Well explained and got my project moving forward.
Thanks.
April 14, 2012 at 3:34 am
jeremy, great video. thing is, i don’t want to spend twenty minutes learning to hardware debounce an arduino interrupt. is there a transcript?
May 6, 2012 at 9:13 pm
I am interested in using both Interrupts – Int0 and Int1. Would the schematic be the same? Essentially, I am putting two resistors + capacitors in parallel between Vcc – 5vin on the Arduino Uno board and Gnd.
May 13, 2012 at 10:18 am
Thank you for this series. It’s been very helpful. Thankfully, I was able to cobble together a Schmitt trigger with a 555 circuit. This post [1] made that dead simple. Granted it’s more work than I originally wanted to do, but I’m glad it’s done.
[1] http://www.allaboutcircuits.com/vol_6/chpt_8/2.html