I wrote a simple code to count the number of pulses when the motor runs. The code just counts the number of interrupts from the encoder, but the output is very weird. Even when the motor is not running it outputs huge numbers of the range of 10000s as the number of pulses. Same case with the other motor. Is something wrong with the encoders or am i missing something? Code

  • what are you counting? ... i do not see any circuit diagram
    – jsotola
    Commented Jan 30, 2020 at 17:11
  • 2
    Please edit your question to add the sketch you're using in text format. Highlight the sketch then click the {} button to give it the correct formatting.
    – VE7JRO
    Commented Jan 30, 2020 at 17:43
  • 1
    You should use digitalPinToInterrupt(pin) instead of directly passing the interrupt number (0 should be correct, though). The reason for those readings you get when the motor isn‘t running could be that the interrupt pin is floating. Try pinMode(encoder_in, INPUT_PULLUP);.
    – Sim Son
    Commented Jan 30, 2020 at 19:43


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.