Rotary Encoder KY40 with Interrupt

zhomeslice:
whats lighter weight than this?

you are doing it wrong:

  • The encoder uses the Manchester code. You must read A & B at the same time, otherwise you will have wrong counts due to noise, debounce...
  • pins and ports are hardcoded and can only be used with atmega328 / 168

The only reason you get a decent result with your code is because the atmega328 & arduino framework is so slow and cannot catch the noise yet. :slight_smile: But the encoder is aging & debounce will increase....

Try your code on fast Cortex MCU, for example, STM32F103xxxx or ESP8266 - you will be surprised. Ohh but you can't - pins and ports are hardcoded