Toggle switch problems

ive recently gotten alot of toggle switches and ive just soldered wires on a few of them and checked if they work. The result was very weird. The serial monitor showed me (tough i had turned the switch of) that value was jumping back and forth. Does anyone know a solution?

Post your code and describe how they are wired.

Hi:

Some more detail on how the switch is hooked up to the Arduino would be helpful. If you have it connected to a digital port setup as an INPUT and have the switch connected to ground, or to a Logical HIGH in the “ON” state and OPEN in the OFF state then the “problem” is a floating input on the digital port . A floating digital input will report a changing condition from “signals” it is detecting on the attached wire.

Fix this by setting a pull-up resistor on the digital input port: digitalWrite(pinx, HIGH)

With that done the port will report a HIGH when the switch, to ground, is open and a LOW when it is closed. ( the switch will “bounce” when operated for a short time (<15mS or so) so you may wish to look up how to “de-bounce” the input.

D.G.

yeah i totally forgot about debouncing thanks :smiley: