4
\$\begingroup\$

I have the following rotary encoder with a built in push switch:

enter image description here

http://henrysbench.capnfatz.com/henrys-bench/arduino-sensors-and-input/keyes-ky-040-arduino-rotary-encoder-user-manual/

I connect the switch pin to a regular digital input pin, putting it into input mode and looking for when does the pin go LOW (that is the pushed in state). However this is unreliable, sometimes even turning the rotary encoder triggers the switch input. Any idea how to fix this?

\$\endgroup\$
  • \$\begingroup\$ pull ups? pull downs? circuit you used? \$\endgroup\$ – Andy aka Jul 20 '17 at 7:38
  • \$\begingroup\$ I dont use anything external, just this and a pro micro. I would think that such an expensive hw should have internal pullup on the switch. \$\endgroup\$ – qlesk Jul 20 '17 at 8:03
3
\$\begingroup\$

enter image description here

As you should be able to see from the picture above, pull-up resistors are required. In addition to this the arduino sketch recommends this: -

It has no switch debounce, nor does it use interrupts. A fully developed application might need to incorporate these in order to make it robust.

So, switch debounce could be a problem too. I suspect the Arduino sketch enables internal pull-up resistors on the chip BTW. I also recommend you read through the list of comments to glean any other useful information on the application of this part.

The diagram below also tells you that "both (are) open" in certain positions and this informs you that you need pull-ups or pull-downs.

enter image description here

Why are they not fitted? Because they cannot know whether you want to fit pull-ups or pull-downs i.e. it is an application thing.

\$\endgroup\$
  • 2
    \$\begingroup\$ INPUT_PULLUP declaration for switch buttons did solve it. \$\endgroup\$ – qlesk Jul 20 '17 at 8:45
  • 1
    \$\begingroup\$ Good. Please consider formally accepting my answer. \$\endgroup\$ – Andy aka Jul 20 '17 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.