Components and supplies
Tactile Switch, Top Actuated
Breadboard (generic)
Jumper wires (generic)
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
Serial logger
arduino
Servo with sleep mode
arduino
Serial logger
arduino
Servo with sleep mode
arduino
Downloadable files
Serial logger - Fritzing file
Serial logger - Fritzing file
Servo with sleep - Fritzing file
Servo with sleep - Fritzing file
Serial logger
Serial logger
Servo with sleep - Fritzing file
Servo with sleep - Fritzing file
Servo with sleep
Servo with sleep
Serial logger
Serial logger
Serial logger - Fritzing file
Serial logger - Fritzing file
Comments
Only logged in users can leave comments
super-admin
a year ago
Implemented in WokWi https://wokwi.com/projects/384261511063225345
Anonymous user
2 years ago
This is an ingenious solution that anyone could have imagined, but that only one of us has completed after having studied it well: my compliments!
Anonymous user
2 years ago
Fantastic!
SOUL-WARDLE
2 years ago
GOOD JOB
Anonymous user
2 years ago
I got the same idea, but I somehow can't get my head around using the INPUT_PULLUP thing. And the way I tried to do it was messy and didn't work properly. Your solution works perfectly though. Thank you very much for posting this. (I now have the idea of using a shift register to dramatically decrease the amount of pins required on the arduino). There is also one flaw in the code. When pressing 2 buttons at once it'll only detect the first press. This is because there is one debounce timer for all inputs, and not a timer per button. It depends on the application, but if multiple buttons can be pressed (or released) at the same time with both of them being handled correctly, then this should be fixed.
Svizel_pritula
2 years ago
It's not the debounce, the problem is that having one button pressed will stop the interrupt from being triggered at all. You can get around that by either doing the checking in the loop once you detect a press, or by putting a pin to INPUT once its button is pressed. Both options have flaws, through. In this case, pin change interrupts are probably the best. (See link in the introduction)
Anonymous user
2 years ago
I'm wondering if something like this could be used to detect combinations of button presses "at the same time". For explanation, any button press sets off the interrupt, mode change, and then button reading loop. The debounce time could be long enough such that a human pressing 2 buttons "at the same time" gets treated as 2 buttons pulling low by the time the button-read loop happens.
Anonymous user
2 years ago
Hello! Thanks for the project. Just wondering about: "We can easily go over all pins to find out which one triggered the interrupt." Can you explain how I could go about figuring out which pin triggered the interrupt?
Svizel_pritula
2 years ago
While there is no way to figure out for sure which one it was, but we assume it's the one that's currently pressed. In my code, I just use a for loop to go over all pins and check if they're being pulled low.
Anonymous user
2 years ago
Excellent!!!
Anonymous user
2 years ago
didn't you just used the same number of pins as in the first example?
Svizel_pritula
2 years ago
I did. I just show how to put the Arduino to sleep. I added a servo as a demo output. Adding more buttons is just a question of connecting them to spare pins and adding them to the buttonPins array.
Anonymous user
2 years ago
Thanks a Ton. Great ideal.
Anonymous user
2 years ago
This is very cool. I'm trying to use two arcade joysticks (basically 4 switches each) to emulate keypresses using an Arduino Pro Micro. For one joystick I can use pin change interrupts on PORTB, but there are only 6 pins on PORTB so I can't cover both joysticks. Would your solution be performant enough for this use case? There's a bunch of other stuff going on in my loop (or triggered from my loop) so polling does not seem to be responsive enough.
Svizel_pritula
2 years ago
Hi, I don't know what else you are doing in your loop, but generaly it shouldn't take too long to use polling. If you're doing time sensitive operations, basicaly any solution you might use to detect button presses will distupt it. This solution won't work correctly if you press multiple "buttons" at once anyway. Perhaps you can try change interrupts on multiple ports?
Anonymous user
5 years ago
This is very cool. I'm trying to use two arcade joysticks (basically 4 switches each) to emulate keypresses using an Arduino Pro Micro. For one joystick I can use pin change interrupts on PORTB, but there are only 6 pins on PORTB so I can't cover both joysticks. Would your solution be performant enough for this use case? There's a bunch of other stuff going on in my loop (or triggered from my loop) so polling does not seem to be responsive enough.
Svizel_pritula
2 years ago
Hi, I don't know what else you are doing in your loop, but generaly it shouldn't take too long to use polling. If you're doing time sensitive operations, basicaly any solution you might use to detect button presses will distupt it. This solution won't work correctly if you press multiple "buttons" at once anyway. Perhaps you can try change interrupts on multiple ports?
Anonymous user
5 years ago
Hello! Thanks for the project. Just wondering about: "We can easily go over all pins to find out which one triggered the interrupt." Can you explain how I could go about figuring out which pin triggered the interrupt?
Svizel_pritula
2 years ago
While there is no way to figure out for sure which one it was, but we assume it's the one that's currently pressed. In my code, I just use a for loop to go over all pins and check if they're being pulled low.
Anonymous user
5 years ago
I got the same idea, but I somehow can't get my head around using the INPUT_PULLUP thing. And the way I tried to do it was messy and didn't work properly. Your solution works perfectly though. Thank you very much for posting this. (I now have the idea of using a shift register to dramatically decrease the amount of pins required on the arduino). There is also one flaw in the code. When pressing 2 buttons at once it'll only detect the first press. This is because there is one debounce timer for all inputs, and not a timer per button. It depends on the application, but if multiple buttons can be pressed (or released) at the same time with both of them being handled correctly, then this should be fixed.
Anonymous user
2 years ago
I'm wondering if something like this could be used to detect combinations of button presses "at the same time". For explanation, any button press sets off the interrupt, mode change, and then button reading loop. The debounce time could be long enough such that a human pressing 2 buttons "at the same time" gets treated as 2 buttons pulling low by the time the button-read loop happens.
Svizel_pritula
2 years ago
It's not the debounce, the problem is that having one button pressed will stop the interrupt from being triggered at all. You can get around that by either doing the checking in the loop once you detect a press, or by putting a pin to INPUT once its button is pressed. Both options have flaws, through. In this case, pin change interrupts are probably the best. (See link in the introduction)
muemi03
6 years ago
Thanks a Ton. Great ideal.
Anonymous user
6 years ago
This is an ingenious solution that anyone could have imagined, but that only one of us has completed after having studied it well: my compliments!
Anonymous user
6 years ago
Excellent!!!
SOUL-WARDLE
6 years ago
GOOD JOB
Anonymous user
6 years ago
Clever method!
Anonymous user
6 years ago
Fantastic!
Anonymous user
6 years ago
didn't you just used the same number of pins as in the first example?
Svizel_pritula
2 years ago
I did. I just show how to put the Arduino to sleep. I added a servo as a demo output. Adding more buttons is just a question of connecting them to spare pins and adding them to the buttonPins array.
10 Buttons Using 1 Interrupt | Arduino Project Hub
thecodegeek
a year ago
Your solution to using multiple buttons and using one interrupt without adding a bunch of diodes is amazing. I also applaud your use of the sizeof() utility instead of hard coding the array size and using a for loop to configure the buttons. Your programming skills are commendable.