Toggle switch on digital circuits?

There's no meaningful 'no signal' input to a pin. The Arduino (or any micro-controller) can only detect 2 states: high or low, nothing else. Hence whatever signal you present to a pin it can only be detected as high or low, nothing else. A rotary encoder connected correctly presents to each of the 2 pins it is (usually) connected to either ... or ... (fill in the blanks).

If you change the wiring, say by disconnecting the 5V connection to the encoder then there isn't anything else that the Arduino could read other than ... or ... (fill in the blanks).

What will happen if you do as you suggest is that instead of a clear, defined and predictable ... or ... you will instead get an unpredictable ... or ..., but it will still only be ... or ....

If you want a switch to disable reading the encoder then it would make more sense to connect it to a different pin and check its state and only read the encoder if the switch in in whatever you define as the 'active' state.

However, I do think this is a lot of theoretical discussion about not much. I urge you to do what electronics is really good for: get an encoder and a switch and wire them up in as many different ways you can think of, write some code and see what happens. If you don't understand the results come back and ask some questions.

Oh, and please, PLEASE do not use chat GPT to write your code, it will end badly.

1 Like