So I have a small project that I am trying to pull off but I have a problem. I have tried to find a solution based on other people's forum questions but to avail. So I have 5 buttons and a rotary encoder, (and a Bluetooth but it doesn't matter for now.) and I want them to print their value in the console. But for the buttons instead of 1 or 0 is the phrase button x pressed. As for the rotary I don't care, I want just raw numbers. i have tried simpler codes like the tutorial for 1 button copied 5 times or something but nothing changes. The buttons are always HIGH apparently and the rotary does not change its value (it is always 0). Here is my code and photos of the wiring:
you are right I changed them to 0-4 rookie mistake.
The problem is the same tho. buttons always are high for some reason...
I have tried ezbutton, I have tried pull_up, I have tried to change the buttons to only ground and data but nothing ever changes ...
I have changed the code so many times at this point I am confused. I used the buttons on a previous iteration of the code but not on this.
The buttons are wired as the tutorial on the Arduino page. One pin has 5 volts the next to it has ground with a 10kΩ resistor and the data are on the opposite side of the ground (diagonally from the 5V).
If you are going to read the button pins directly using digitalRead() then I suggest that you remove all references to the Button library from the code as it may be using INPUT_PULLUP as the pinMode()
Sorry, but I cannot follow your description of how the buttons are wired. Please post a link to the page that you are referring to
Personally I would use INPUT_PULLUP in pinMode() to turn on the built in pullup resistor, wire the button to take the pin to GND when the button is pressed and test for LOW in the code when you want to test for a button press using digitalRead()
That way you will know exactly what the code is doing and will not need to understand or guess what the library is doing
To be honest when it was 1 button it worked fine, when I put one more its value was always read as HIGH. Then I just left one button and I wired the rotary encoder. both work fine. Then I tried to put the other buttons on and it started to read all the values as high and to not read the rotary at all. After that whatever I did just didn't work. (even when I disconnected everything and left just a button that button's value was always high...) but I am gonna follow both your instructions and start again with one button. Also @UKHeliBob I don't understand what the wiring should be. You mean this ? -> Arduino Push Button - Complete Tutorial - The Robotics Back-End
So I can see if the button is working normally, right?
I was thinking if the shit hits the fan to change all the buttons to photoresistors so I can "simulate" a touch button (I have done this in another project, not very safe since the light is always changing but It worked fine for me)
So i copy pasted the code and wired the button as you suggested the button still doesn't change its value. It is stuck on HIGH. So I took the multimeter and did a check. The results were weird cause without an arduino the measurements were 23 (on he 2000m scale) but not while I press the button, only the second I touch the 2 heads to the button. After that I put the arduino and run it I put the multimeter on the 2 ends of the button and the measurements were 170 on the 200m scale .. i think the buttons don't have enough power ?
using the Toggle library from @dlloyd and the encoder library and a simple custom class to regroup a button name and pin for a nice print out to the serial monitor