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:

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



Posted

in

by

Comments

25 responses to “Tutorial 10 for Arduino: Interrupts and Hardware Debouncing”

  1. BusinessHugs Avatar
    BusinessHugs

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

  2. Pagweb Avatar
    Pagweb

    What program did …
    What program did you used for? the schematics?

  3. nobody1828 Avatar
    nobody1828

    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.

  4. 123456789robbie Avatar
    123456789robbie

    “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.

  5. 123456789robbie Avatar
    123456789robbie

    Y U? NO CREATE LED …
    Y U? NO CREATE LED ARRAY?!

  6. skyykloudz Avatar
    skyykloudz

    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??

  7. skyykloudz Avatar
    skyykloudz

    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)

  8. gricka31 Avatar
    gricka31

    what software? are …
    what software? are you using for the circuit diagrams?
    thanks

  9. xxang1 Avatar
    xxang1

    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.

  10. mahela1993 Avatar
    mahela1993

    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?

  11. weirdphysics Avatar
    weirdphysics

    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.

  12. theblackfluid Avatar
    theblackfluid

    @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.

  13. sciguy14 Avatar
    sciguy14

    @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.

  14. theblackfluid Avatar
    theblackfluid

    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?

  15. sciguy14 Avatar
    sciguy14

    @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.

  16. CIPHERJAY Avatar
    CIPHERJAY

    @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..

  17. sciguy14 Avatar
    sciguy14

    @CIPHERJAY correct.?
    @CIPHERJAY correct.?

  18. CIPHERJAY Avatar
    CIPHERJAY

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

  19. sciguy14 Avatar
    sciguy14

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

  20. CIPHERJAY Avatar
    CIPHERJAY

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

  21. 17171717 Avatar
    17171717

    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!

  22. sciguy14 Avatar
    sciguy14

    @redhotdaddy Link …
    @redhotdaddy Link in description. It’s on my? site.

  23. redhotdaddy Avatar
    redhotdaddy

    can you post? your …
    can you post? your code?

  24. sciguy14 Avatar
    sciguy14

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

  25. sh3r1ly Avatar
    sh3r1ly

    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