I have been searching for a simple and affordable solution to control turnouts on my model train layout using pushbuttons. Your explanation is clear and helped me decide that the Arduino together with the PCA9685 servo controller is that way to go. Thank you for that.
Excelent explaination. The only thing is that the floating ground was not placed back into the drawing, which is what makes de vudeo stand from others.
all you need is to put as many distinct(not of the same value) resistors in parallel as there are buttons and connect the buttons in series to those resistors, this will give you an unique voltage drop even if multiple buttons are pressed.
Tks for showing this method, I might use it with à attiny project. I would like to suggest to use différent resistor values for each resistor, this way, you could detect 2 buttons being
I just read that there is no guarantee that the input will survive if you provide 5V directly without a resistor to limit current. So maybe you should either add a low resistance compared to the others or an equal one and get your HIGH signal from after then. Also I think you could make it possible to press and recognize them in parallel if you cleverly choose a unique resistance to add in parallel so there will always be a different total resistance.
Excellent tutorial I would like to achieve the same thing as Kevin Chamberlain in the comments I want to use uno and pca9685 to control servo motors using this pushbutton system on the same uno. The pca9685 board will used two analogue pins in leaving 4 analogue pins available could I assign pushbuttons to these four analogue pins would this allow 4 buttons to be pressed at the same time as long as they are on different analogue pins is it possible to assign one pushbutton to each servo in the programme sketch. ThankYou very much
Thx a lot Michael!!! Great video!!! Anyway I've done it and works but the values of the analog are not so stable than in yours that are very sharp. I use the same resistors but with 9 buttons. Any help?
Thanks Pablo. If you're getting unstable results its probably either because you've got a poor ground or 5V connection or just poor connections in general. Jumpers and breadboards don't always provide a stable and reliable connection.
Good idea:; resistors, by careful math's, you could maybe do two or more buttons at the same time, I think :) something like 1000 Ohms is button 1; 2000 Ohms is button 2 and then 3000 Ohms is both buttons, (series) or what ever it is in parallel
Yes you could detect simultaneous pushes by playing around with different resistor values, you'd just need to make sure that each combination resulted in a unique resistance.
Because we're reading an analogue signal, it's not as sensitive to button bounce, but if it is a problem in your application then you could debouce the signal in the same way as it is done digitally.
is there anyway make us do this with one digital input ?? because I want for example use ESP 01 which doesn't have analog input ..... thanks in advance
There isn't any way (that I'm aware of) of connecting multiple push-buttons to a single digital input. You could, however, use a shift register to connect multiple push-buttons to substantially fewer digital inputs, typically 3 are required.
great for expanding inputs. would it be possible for you to do a tutorial using say 6 push buttons on the one analogue to move a stepper motor to six preset degrees?
It'll work for any digital sensors that have a contact or switch style output, most PIR sensors would work this way. Some digital sensors with internal circuitry might try force the output to a certain voltage or may not be compatible with a resistor being in series with the output.
Hello is it possible to connect two separate buttons that have the same functiona (down) on a fighting game controller that uses a brooks zero pi pcb, do you know about this?
If the buttons are "normally open" then just connect them in parallel and you'll have the same functionality, if they're "normally closed" then connect them in series.
Yes, this isn't a great solution if you need to handle simultaneous button pushes, but it can be done. As long as you know which keys are likely to be pressed simultaneously, you can set up a case or range for them as well. This works if you've got a few combinations you need, but if its for an entire keypad of simultaneous button options then it can get messy.
Hi, if all resistors of the divider have the same value we can detect that more than one button was pushed but can not know which ones. If you use different values for each resistor than you can also detect which specific 2 buttons were pushed
I have an arduino project that has a potentiometer on A1 which is used to produce 12 different tones. I want to convert the pot to momentary push buttons so I can play like a piano keyboard. I am thinking your example should work as a solution for me?
@@MichaelKlements Thanks for the quick reply!! The tones are actually chords with harmony note to be more precise so no I only need one at a time. Thanks again!!
Can I use resistors with a higher resistance like 1kΩ? I still have a hard time grasping how this kind of circuit works... do higher-resistance resistors use or require more energy/current?
Yes you can, the resistor values in this particular arrangement aren't all that important. They are just there to provide a load between 5V and GND. They limit the current, so a higher value resistor results in less current (effectively more efficient).
In theory you could connect up to 1024 although in practise you'd probably only be able to connect about 100 with some "margin of error" on either side of readings.
Hi, I understood everything and it's a great video! However, I don't know why, but I can't get this working! Only one button is working, all the others have the value 0 when pressed. I used the 220 Ohm resistors. Please help me, thank you in advance. Best regards.
Hi Michael, thank you for your reply. I tried with the code you have in the video description. I am sure the connections are correct. I am using Mega instead of Uno, I changed only the LED inputs codes. The LEDs works fine, because I tested it all of them. When I press the first button I only have one LED on. I don't know what is missing here. :( Thank you for your help.
If you've used only 220 ohm resistors then I assume you've connected the resistors are in method 2? If that's correct then start by displaying the raw value from the analogue input to your serial monitor and check whether you're getting a different reading for each button push. If you're getting 0 with any other button push then you've got a problem with your wiring somewhere.
This is one of the best things I came across when learning arduino. It really helps, thanks!
Glad the video helped you out!
I have been searching for a simple and affordable solution to control turnouts on my model train layout using pushbuttons. Your explanation is clear and helped me decide that the Arduino together with the PCA9685 servo controller is that way to go. Thank you for that.
That's great to hear!
Brilliant! You just saved me so much hassle with too many digital/analogue pins being used.
That's great to hear!
i've been looking for this solution for the past 5 months!!!
I'm glad to watching your video. In this video teach me practical learning. Thanks to you. Abdul Basit from Bangladesh.
Headed about this technique could not figure it out Wola here you are with the answer. THX
Your amazing….. thank you so much inspired today 👏👏👏👏👏👏
omg this is awesome, really need to watch more of your content. subscirbed, great job!
Thank you!
Excelent explaination. The only thing is that the floating ground was not placed back into the drawing, which is what makes de vudeo stand from others.
all you need is to put as many distinct(not of the same value) resistors in parallel as there are buttons and connect the buttons in series to those resistors, this will give you an unique voltage drop even if multiple buttons are pressed.
Tks for showing this method, I might use it with à attiny project. I would like to suggest to use différent resistor values for each resistor, this way, you could detect 2 buttons being
Pushed at once
Yes you could do that too
Could you make something like this, but with button on/off latch?
I just read that there is no guarantee that the input will survive if you provide 5V directly without a resistor to limit current. So maybe you should either add a low resistance compared to the others or an equal one and get your HIGH signal from after then.
Also I think you could make it possible to press and recognize them in parallel if you cleverly choose a unique resistance to add in parallel so there will always be a different total resistance.
Awesome tutorial and very clear! Thanks
thanks you're cool
Brilliant!
Excellent tutorial I would like to achieve the same thing as Kevin Chamberlain in the comments I want to use uno and pca9685 to control servo motors using this pushbutton system on the same uno. The pca9685 board will used two analogue pins in leaving 4 analogue pins available could I assign pushbuttons to these four analogue pins would this allow 4 buttons to be pressed at the same time as long as they are on different analogue pins is it possible to assign one pushbutton to each servo in the programme sketch. ThankYou very much
Thx a lot Michael!!! Great video!!! Anyway I've done it and works but the values of the analog are not so stable than in yours that are very sharp. I use the same resistors but with 9 buttons. Any help?
Thanks Pablo. If you're getting unstable results its probably either because you've got a poor ground or 5V connection or just poor connections in general. Jumpers and breadboards don't always provide a stable and reliable connection.
Good idea:; resistors, by careful math's, you could maybe do two or more buttons at the same time, I think :)
something like 1000 Ohms is button 1; 2000 Ohms is button 2 and then 3000 Ohms is both buttons, (series) or what ever it is in parallel
Yes you could detect simultaneous pushes by playing around with different resistor values, you'd just need to make sure that each combination resulted in a unique resistance.
How about multiple 3 axis buttons
is there any debouncing effects?
Because we're reading an analogue signal, it's not as sensitive to button bounce, but if it is a problem in your application then you could debouce the signal in the same way as it is done digitally.
is there anyway make us do this with one digital input ?? because I want for example use ESP 01 which doesn't have analog input ..... thanks in advance
There isn't any way (that I'm aware of) of connecting multiple push-buttons to a single digital input. You could, however, use a shift register to connect multiple push-buttons to substantially fewer digital inputs, typically 3 are required.
great for expanding inputs. would it be possible for you to do a tutorial using say 6 push buttons on the one analogue to move a stepper motor to six preset degrees?
Thanks for the suggestion Deon, I'll have a look at this. It sounds quite easy to do.
Dear brother can you help me a very small correction in my code
In theory this can work with other digital sensors right? For example a PIR sensor and pushbutton
It'll work for any digital sensors that have a contact or switch style output, most PIR sensors would work this way. Some digital sensors with internal circuitry might try force the output to a certain voltage or may not be compatible with a resistor being in series with the output.
This wouldn't let you detect two buttons being pressed at once right? It would think it's just a different button further down the chain ?
Only if the combination had a uniquely identifiable resistance as well. You’ll also need to program this in as a combination option.
Hello is it possible to connect two separate buttons that have the same functiona (down) on a fighting game controller that uses a brooks zero pi pcb, do you know about this?
Basically screw the wires of each button into the same (down) function terminal and have them both work when used separately
If the buttons are "normally open" then just connect them in parallel and you'll have the same functionality, if they're "normally closed" then connect them in series.
Everyone is impressed by this technique at first until you realise the mess that happens when you press more than 1 button at the same time.
Yes, this isn't a great solution if you need to handle simultaneous button pushes, but it can be done. As long as you know which keys are likely to be pressed simultaneously, you can set up a case or range for them as well. This works if you've got a few combinations you need, but if its for an entire keypad of simultaneous button options then it can get messy.
Hi, if all resistors of the divider have the same value we can detect that more than one button was pushed but can not know which ones. If you use different values for each resistor than you can also detect which specific 2 buttons were pushed
I have an arduino project that has a potentiometer on A1 which is used to produce 12 different tones. I want to convert the pot to momentary push buttons so I can play like a piano keyboard. I am thinking your example should work as a solution for me?
As long as you're not expecting to use the buttons simultaneously (two buttons at the same time)
@@MichaelKlements Thanks for the quick reply!! The tones are actually chords with harmony note to be more precise so no I only need one at a time. Thanks again!!
Can I use resistors with a higher resistance like 1kΩ? I still have a hard time grasping how this kind of circuit works... do higher-resistance resistors use or require more energy/current?
Yes you can, the resistor values in this particular arrangement aren't all that important. They are just there to provide a load between 5V and GND. They limit the current, so a higher value resistor results in less current (effectively more efficient).
@@MichaelKlements Ah cool, thanks for the reply!
How much buttons can i connect?
In theory you could connect up to 1024 although in practise you'd probably only be able to connect about 100 with some "margin of error" on either side of readings.
Hi, I understood everything and it's a great video! However, I don't know why, but I can't get this working! Only one button is working, all the others have the value 0 when pressed. I used the 220 Ohm resistors. Please help me, thank you in advance. Best regards.
Hi Patricia,
Have you tried working through the write-up linked in the video description? Are you sure that your 5V and GND connections are correct?
Hi Michael, thank you for your reply. I tried with the code you have in the video description. I am sure the connections are correct. I am using Mega instead of Uno, I changed only the LED inputs codes. The LEDs works fine, because I tested it all of them. When I press the first button I only have one LED on. I don't know what is missing here. :( Thank you for your help.
If you've used only 220 ohm resistors then I assume you've connected the resistors are in method 2? If that's correct then start by displaying the raw value from the analogue input to your serial monitor and check whether you're getting a different reading for each button push. If you're getting 0 with any other button push then you've got a problem with your wiring somewhere.
I did the method 2 with 220 Ohms resistors. I will check again the wires :) Thank you.
Why I just learned this after years of Arfuino projects... I feel so dumb rn...
i want to push 96 button at the same time 🤣(arduino full piano😎)
Haha, you’d have to look at multiplexing the inputs then
This is stupid, why do you need resistors for EACH pushbutton???
the resistors knock down the voltage to give different analog input