element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum How can I attach four separate buttons to a single interrupt?
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 12 replies
  • Answers 4 answers
  • Subscribers 393 subscribers
  • Views 1762 views
  • Users 0 members are here
  • interrupt
  • multiple_buttons
  • low power
  • atmega328
  • arduino
Related

How can I attach four separate buttons to a single interrupt?

bwarren97
bwarren97 over 9 years ago

I'm working on a project that I've been pondering for almost a year, and I have been prototyping it with my Arduino Mega 2560 (my Arduino mini died, so the 2560 is all I have at the moment) for the past two weeks, but I've hit a snag.

 

Here's a little breakdown: I have four buttons I want on the final product. I have each button defined as pins in my script.

I want the ATMEGA to power down when I press one of these buttons, or after a set amount of time being idle. Then, I want to be able to press any one of my buttons to power it back on again.

 

Since my final product is going to use an ATMEGA328 instead of a 2560, that means I can really only use one of the two interrupts (right?) to wake the chip. It also simplifies my software quite a bit if I can use one pin to power the buttons and detect that a button was pressed, and the other pins to detect which button was pressed. So I've set up my buttons so that the wake pin is pulled high, and the button pins are pulled low, and when I press a button, theoretically, the wake pin goes low and the button pin goes high. Doesn't happen. The wake pin does go low, but the button pin doesn't go high, and I can't figure out why. Even if I remove the pull-down resistor, it doesn't work.

 

Does anyone have any ideas?

  • Sign in to reply
  • Cancel

Top Replies

  • dougw
    dougw over 9 years ago +3 suggested
    There are several ways to solve this - if I understand it correctly. One way is to use double pole switches, where one pole on each switch drives a corresponding button pin, and the other poles are all…
  • bwarren97
    bwarren97 over 9 years ago in reply to Robert Peter Oakes +3
    Yes. I just now made the changes to my script and it works exactly as it should. I thank everyone for the suggestions!
  • bwarren97
    bwarren97 over 9 years ago in reply to dougw +2
    I like the double-pole switch idea, but I like the diode idea better. Is this what you were talking about? I labeled the lines that would connect to the microcontroller
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago

    First of, if you are driving the bottom of a button low and the top is to another pin that is an input with a pull up, then I would simply look for that pin going low and use it to trigger the interrupt.

     

    Now if you want the MPU to be asleep then output all bottom pins of the switches to low so that any one of them being pressed will pull the input pin low, then the ISR will scan the pins quickly by having only one button low at a time to determine the one that is pressed

     

    You can't balance a pull up on one side of a switch and a pull down on the other and hope they're going to swap states when the button is pressed, at best the voltage will go to a mid and undetermined voltage which is not good. you need a solid pull to zero volts by using the pin as an output

     

    I hope that helps you out

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • dougw
    0 dougw over 9 years ago

    There are several ways to solve this - if I understand it correctly.

    One way is to use double pole switches, where one pole on each switch drives a corresponding button pin, and the other poles are all connected in parallel to the wake pin.

    Another way is to use diodes so that button pins are only affected by one button, but the wake pin is sensitive to all buttons.

    Doug

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago in reply to dougw

    Ah, its been so long, YES dougw, that is a much simpler option

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gihu
    0 gihu over 9 years ago in reply to Robert Peter Oakes

    I like the dougw proposal. Making an and gate with diodes with an internal pull-up for the interrupt input, and each katode to each input.

    Just be carefull of a very important thing, Vf of the diode must be less than 0.3Vcc, it should not be a problem for 5V or even 3.3V, but I can be for lower voltages.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 9 years ago in reply to gihu

    Isn't that an or gate?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gihu
    0 gihu over 9 years ago in reply to Jan Cumps

    Hi Jan

     

    If you use internal pull-up resistors, you make the interrupt when input is low, the normal status for the inputs is high, and as soon as you have a low at any input, you have a low in the interrupt:

    1  1 -> 1

    1  0 -> 0

    0  1 -> 0

    0  0 -> 0

    That's an and gate.

    You can use diodes in a or-gate way, connecting all the katodes to the interrupt pin (and each anode to each input pin), but then the interurpt should be active by high, instead of low, and you have to use external pull down resistors, instead of internal pull-up, of course, the inputs should work also with pull down resistors in this case, where as soon as you get a high at any input, you will have a high at the interrupt.

    0 0 -> 0

    0 1 -> 1

    1 0 -> 1

    1 1 -> 1

    That's an or gate

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gihu
    0 gihu over 9 years ago in reply to Jan Cumps

    I know I am not a very good at explaning.

    Maybe an image it is better:

    Diode Logic Gates

    image

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 9 years ago in reply to gihu

    You are correct.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • bwarren97
    0 bwarren97 over 9 years ago in reply to dougw

    I like the double-pole switch idea, but I like the diode idea better.

     

    Is this what you were talking about?

    61d8e69c91.png

    I labeled the lines that would connect to the microcontroller

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 9 years ago in reply to bwarren97

    The junction between each switch and its diode would go to an input pin, that pin would be set with a pullup. Int0 would also be an input with pullup.

     

    When any button is pressed, the respective pin would also go low but through the diodes, the INT0 pin will also go low. Well mostly low less the diode drop, but still enough to be registered as a zero and trigger the interrupt

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube