I'm trying to design a car that follows a specific sequence based on the push button that is activated. For instance, when push button #1 is activated, sequence #1 will begin and end. I want the sequence to follow the steps: no motion in any servo motors, push button x is activated, sequence x begins and ends, no motion in any servo motors again. However, my servo motors just end up following all sequences on an infinite loop, even when I am not activating any of my push buttons. I have pasted my code down below, any help would be great!
How are the buttons wired? Is there a pulldown resistor connected to the button's input? Are the servos powered by an external supply? Post a schematic of the wiring.
The most common way to wire button switches is to wire one side to ground and the other to an input set to pinMode INPUT_PULLUP. The switch will read HIGH when not pressed and LOW when pressed. Adjust your code accordingly.
Read the how to use this forum-please read sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.
Yes, I have each button connected to a 220 resistor which is connected to its individual pin. Then on the other side, I connected all three buttons to the 3.3 V pin.
Yes, I have each button connected to a 220 resistor which is connected to its individual pin. Then on the other side, I connected all three buttons to the 3.3 V pin.
That is a bit ambiguous. Can you draw a schematic?
How to wire switches using internal pullup. 220 Ohms is pretty low value for a pulldown (if that is how it is wired). 10K is usually fine unless there is a noise problem, then a lower value may be necessary. But usually never less than about 1K.
Switches not wired right for pulldown or pullup. Pulldown resistors would go from the input to ground.
The switches should be wired to 5V. The servos will need an external power supply. An Uno 5V regulator can power maybe 1 unloaded servo. Once you try to move more than one loaded servos you are likely to have trouble. A 4 AA cell pack is a good supply for servos.
I changed the wire that connects to the 3.3V pin and I connected it to ground. Then, I changed my if statements to execute the functions when the button states are low. However, the servo motors still do not respond to the push buttons.
I put the resistors in parallel in Tinkercad and it worked then, but it still doesn't work in my actual project even though I checked that the wiring was the same. Do you have any idea why that would be the case?
aarg:
Your resistors are in series with the inputs. That will leave them "floating" when the switches are not pressed.
I tried wiring brand new buttons like this just in case I accidentally shorted the old ones, but the servo motors still do not respond to the buttons. I'll put a picture of it down below, it's kind of messy tho
groundFungus:
Fritz with wiring for tact pushbutton wired for internal pullup.