Tutorial 10 for Arduino: Interrupts and Hardware Debouncing

New Episodes each Monday!

You can download the parts list, code, and schematics from this episode on my website: http://jeremyblum.com/2011/03/07/arduino-tutorial-10-interrupts-and-hardware-debouncing

Learn more about Timer Interrupts here:
http://jeremyblum.com/2010/09/05/driving-5-speakers-simultaneously-with-an-arduino/

This tutorial series is sponsored by element14. Check out their arduino group!
http://www.element-14.com/community/groups/arduino

Follow me on twitter: http://www.twitter.com/sciguy14

Duration : 0:19:54


Related Reading:

Incoming search terms:

Uncategorized

Be Sociable, Share!

Technorati Tags: arduino, ATMEGA, blum, button, capacitor, circuit, debounce, element14, hardware, interrupts, IR, jeremy, LED, rc, resistor, switch, Timer, Tutorial

25 thoughts on “Tutorial 10 for Arduino: Interrupts and Hardware Debouncing

  1. @Pagweb He? …
    @Pagweb He? mentioned in another video he was using EagleCad, which is free and open source.

  2. Shouldn’t you have …
    Shouldn’t you have another 10k resistor in series with the switch? As drawn, when you push the switch the capacitor leads are connected with 0 ohms, so your RC time constant calculation doesn’t apply here. Your debounce appeared to work for the few times you tried it only because the time spent bouncing slowed down the cap discharge enough. You should? actually add a 10k between the switch and one of the cap leads. Or am I seeing it wrong? Thanks for your help.

  3. “we could use an …
    “we could use an else if, same some processing time” no, you MUST use an else if, otherwise it will change the value to red, then check if its red, then change it to yellow, then check if its yellow, then change it to green. so the function will always end with the value being? green. you disapoint me sir.

  4. I’m also curious if …
    I’m also curious if you would be able to treat the characters you’re reading in from the SD card as strings, then append or concatenate them into one big string in a variable, then convert that to an integer instead of the power of tens style method you used??

  5. could this have …
    could this have been done without interrupts using loops? like a while loop to loop while the button is in the open state? just curious, I’m sure it’s? much less efficient doing it that way (if it’s actually possible)

  6. Hey, my interrupt …
    Hey, my interrupt will trigger on the rising edge (as programmed) which is what I wanted. However, as soon as I inserted some codes to enable my motors in? the main loop, the interrupt signal from my photo interrupter tends to interrupt far more times than it should. It is supposed to interrupt when the infra-red is being blocked by an object once at 0-1 rising edge, but it is triggering like 100+ times when i run a paper to block the infra-red on the photo interrupter.

  7. Could you use …
    Could you use something like an Op-amp instead of a Smitt trigger? Of course that wouldn’t invert? the signal.. but would convert the signal to a square wave right?

  8. you have a dog …
    you have a dog barking at about 10 minutes.

    Your tutorial series have really helped me do? a high school project.

  9. @sciguy14 Oh yes, …
    @sciguy14 Oh yes, you’re right. I? even remember that delay() and delayMicroseconds() don’t work inside an ISR. But you can do those things: detachInterrupt() (maybe in c to be faster), flip your variable and then store the time inside another global variable. So later on in the loop() you could check how much time has passed and attach the interrupt again to the pin. Not the best but in lack of place (schmitt trigger and cap are’nt that small) it’s okay for a manually pushed buttton i think.

  10. @theblackfluid That …
    @theblackfluid That sounds reasonable, but it goes against? common practice for an interrupt anyways. All other system functions are suspended within an interrupt, so even if you could do a delay, you shouldn’t. You should enter the interrupt, do something simple (like flip a global variable) then get out as fast as possible.

  11. Your hardware …
    Your hardware debounce is nice? but isn’t it possible to call detachInterrupt() as first thing in your interrupt function and then, after a delay, attach it again to the pin?

  12. @CIPHERJAY Well it …
    @CIPHERJAY Well it didn’t cause it to stop? – it’s just that’s only printing it out in relatively long intervals, so you never see the value change in the terminal window.

  13. @sciguy14 I have a …
    @sciguy14 I have a problem. Basically i noticed that there was a slight change in the code in that you have included the two serial lines. I went back to tutorial 2 and to my? surprise the line: Serial.println(digitalRead(switchPin));
    caused the bouncing of the signal to stop. I would like to understand why this is the case. Also, erroneous reading are still occurring now that I deleted that line from the code..

  14. Is pin 1 on the …
    Is pin 1 on the trigger? connected to the yellow wire and pin 2 connected to PWM 2?

  15. @CIPHERJAY You can …
    @CIPHERJAY You can make this work without? the trigger. You just need to invert your logic in software.

  16. Hey, does anyone …
    Hey, does anyone know where to get the Schmitt trigger chip from a? UK based seller? Thanks!

  17. Will the Arduino …
    Will the Arduino still set the interrupt flag if the interrupt is tripped while detached? Or do? I have to clear the flag before reattaching to prevent the ISR from running right away? Thanks!

  18. @sh3r1ly That …
    @sh3r1ly That shouldn’t happen unless you’re disabling interrupts in your while loop. What are you doing in the? loop?

  19. Hey Jeremy,
    I’m …

    Hey Jeremy,
    I’m having trouble using interrupts with while-loops. My ISR stops interrupting when my while loop is working; it seems like the ISR is? waiting for the while-loop to finish. Do you have any advice on how to fix this problem?

Leave a Reply