How to use Rotary Encoder with Arduino

Поделиться
HTML-код
  • Опубликовано: 24 ноя 2024

Комментарии • 71

  • @JohnMcCormick-f8f
    @JohnMcCormick-f8f Месяц назад +4

    I have looked at several Rotary Encoder Video and you are the only one that explains that you need to use the Falling Edge of the CLK Signal to determine the direction of the encoder. Thank You Soooooo Much! You Rock!

    • @chadrummer
      @chadrummer Месяц назад

      x2

    • @marios_ideas
      @marios_ideas  Месяц назад +1

      Thanks.Means a lot to me. Consider supporting my channel:)

  • @kasia2240
    @kasia2240 6 месяцев назад +4

    This was the best explanation about Rotary Encoder I have found!

  • @souley_garage
    @souley_garage Год назад +11

    Thanks for this video and explanation. The « hesitation » you can see from « falling » trigger mode might be induced by some electrical rebound when contacts are opened/closed. Put a small 10nF between GND and CLK and GND and DT it should solve it :)

    • @tinyjudoka6024
      @tinyjudoka6024 11 месяцев назад

      This worked beautifully thank you very much :D

    • @zeepichashbrown4676
      @zeepichashbrown4676 8 месяцев назад

      bro I genuinely love you

    • @vinny142
      @vinny142 Месяц назад

      And swap to RISING edge so the capacitor doesn't give you the exact same problem when it slowly discharges by leaking.

  • @Vandebilt
    @Vandebilt 7 месяцев назад

    Very good educational explaination. I finally understand how it works. I'm currently building a router lift and I will continue to try to connect a Stepper Driver and Stepper motor to make the rotations work correctly with absoule values (together with momentary push buttons) and fine tune the router bit with a rotary encoder in millimeters which would be displayed on a LCD or OLED screen. Thanks for an excellent video.

  • @garylarson3751
    @garylarson3751 10 месяцев назад

    Great Video...Would never have thought of using that kind of logic between the two pins with one interrupt handler.

  • @duanebeyer950
    @duanebeyer950 Год назад +7

    I found this on Google. "FALLING triggers an interrupt when the signal changes from HIGH to LOW. LOW fires the interrupt for the ENTIRE time the signal remains LOW. So, if your ISR returns while the signal is LOW, the ISR will immediately be called again, after executing only a single instruction back in the foreground task."
    I think what it is saying is with falling, if you have a bounce issue, it may false trigger, but if you force it to "LOW" then the bounce will be ignored. I believe that is what they are saying.
    UPDATE: Actually, after reading this and some other stuff a few more times, I think I have it wrong. So I am in the same place as you, not really sure why LOW is working better in this situation.

    • @marios_ideas
      @marios_ideas  Год назад +1

      EXACTLY:) I was digging myself and couldn't find reasonable answer

    • @gs051233
      @gs051233 Год назад +1

      I think the ISR execution condition of >5ms since last interrupt makes the LOW mode work. This is because when the signal is LOW, the interrupts fires with the clock frequency, which is much faster than 5ms. Therefore, when not turning, ISR is not doing anything despite being fired all the time when the signal pin is low. When the signal pin is high, ISR is not fired anyway, so when rotating and passing from high to low, the >5ms execution time is fulfilled.

  • @Majk369
    @Majk369 2 года назад +6

    exactly what ive been looking for. Thumbs up👍

    • @marios_ideas
      @marios_ideas  Год назад

      My pleasure:) like the video and subscribe to my channal. Also consider supporting it.

  • @o.z.hamzah1707
    @o.z.hamzah1707 9 месяцев назад +1

    The skip in the digital count is probably caused by bouncing. A "debounce" circuit using CMOS 4093 Schmitt trigger ICs is better that having capacitors to ground - of course, this adds a layer of complexity, but it's doable. I am trying to use your Arduino code with a linear encoder (home-built) rather than a rotary switch for my application. Great easy to follow video and super graphics. Thanks.

    • @rickhunt3183
      @rickhunt3183 4 месяца назад

      I think the use of a 4093 for signal debouncing is a great idea, so much, that I just ordered 50 of them. I know that might sound excessive, but when I want to build a project I don't like waiting for parts. I like to get busy right away so I believe in keeping an inventory on hand. I hope you'll have a great day.

  • @mans4104
    @mans4104 2 года назад +3

    The best explanation ever.👍

    • @marios_ideas
      @marios_ideas  2 года назад

      Thanks:) Please give video a like if you enjoyed it

  • @youssefmostafa5788
    @youssefmostafa5788 7 месяцев назад

    Awesome, nice explanation and great way of displaying the code

  • @josephgitau280
    @josephgitau280 Год назад +2

    good explanation bro. ive found it easy than ever

    • @marios_ideas
      @marios_ideas  Год назад

      Thanks:) Give this video a like then:) Also If you want to see future content like this subscribe and set the neotification not to miss my upcoming videos. There are also ways you can support my channel if you choose to:)

  • @SMK5025
    @SMK5025 Месяц назад

    Great video, I have a much better understanding of encoders. Looking forward to using in a new project. Thank You!!

    • @marios_ideas
      @marios_ideas  Месяц назад

      Glad the video was helpfull. Consider supporting my channel

  • @chadrummer
    @chadrummer Месяц назад

    finally i understood. a lot of thanks.

  • @queenidog1
    @queenidog1 3 месяца назад

    very good video. Well explained, good visuals.

  • @markusbFPV
    @markusbFPV Месяц назад

    I think you have to check in code if the shaft was turned a full click in the same direction. Example: First CLK goes low (interrupt trig) and DT is still high. When DT goes low you know the specific direction you turn, but first you wait for CLK to go high again and then check for DT to go high. When that happens you change your counter. And vice versa for the other direction. I got this principle to work with help from chatGPT but the code was much more advanced. After implementing this it worked great but it was only an example when I learned about rotary encoders so the extra code did not matter to me.

    • @vinny142
      @vinny142 Месяц назад

      "I think you have to check in code if the shaft was turned a full click in the same direction."
      You don't have to, because CLK will only change if the shaft is rotating and DT will show the direction.

    • @markusbFPV
      @markusbFPV Месяц назад

      @@vinny142 Im sorry, this was an explanation to the jumping numbers you demonstrated on the 7-seg display. I noticed it to when testing the encoder in a sketch and found that if the shaft is moved slightly in the wrong direction this happens. And this happened to me every time I got a new grip of the encoder wheel. Thats why I coded the number to increase only after a full "tick".
      I suppose there are lots of different ways to get this to work.
      Thanks for the video!

  • @plamenpetkov7132
    @plamenpetkov7132 Год назад +1

    erratic behaviour is coming from contact bouncing. The simplest solution is to add caps to GND.

  • @vinny142
    @vinny142 Месяц назад

    The LOW setting should not work at all, unless... you simply have the wires hooked up the wrong way round and you're triggering on the DT line.

  • @vijaysulakhe5605
    @vijaysulakhe5605 Месяц назад

    Good Explanation , Thanks.

  • @bahaajobs
    @bahaajobs 11 месяцев назад

    This is very informative, thank you so much for the video and explanation

  • @francoisdastardly4405
    @francoisdastardly4405 9 месяцев назад

    Absolutely perfect explanation ❤❤

  • @TheUnofficialMaker
    @TheUnofficialMaker Год назад +1

    great explanation, I will try it

    • @marios_ideas
      @marios_ideas  Год назад

      Cheers:) consider supporting my channel

  • @PostalPete
    @PostalPete 8 месяцев назад

    This has been helpful but in my case I'm trying to use a mouse scroll wheel rotary encoder (which you can get from a computer mouse or buy from amazon). Setting it up in a similar fashion, I can get it to function roughly in the right direction - as I keep scrolling up or down, the counter reliably keeps increasing or decreasing as expected but sometimes it will go in the wrong direction as well. I tried experimenting with different resistors but haven't found a fix. Maybe there's something wrong with my wiring. I'm very new to this.

  • @rons7555
    @rons7555 4 месяца назад

    Thanks for this video, very helpful !

    • @marios_ideas
      @marios_ideas  4 месяца назад

      Thanks. Means a lot. Consider supporting my channel:)

  • @kvnl1037
    @kvnl1037 Год назад +1

    Useful help !

  • @Anton-wc7lb
    @Anton-wc7lb Год назад +1

    Amazing! This is great help!! :)

    • @marios_ideas
      @marios_ideas  Год назад

      Subscribe to the channal if you like this content

  • @ernandofranco8448
    @ernandofranco8448 Год назад +1

    Muito bem explicado!!!Parabéns pelo vídeo!

  • @arduinomaquinas
    @arduinomaquinas Год назад

    Great video❤loved, awesome 🇧🇷😉👏👏👏👏👏👏

  • @jumbo999614
    @jumbo999614 2 года назад +1

    great video

  • @sampetri4887
    @sampetri4887 Год назад

    Thanks!

    • @marios_ideas
      @marios_ideas  Год назад

      Thank you for your contribution:) Means a lot

  • @markgreco1962
    @markgreco1962 2 года назад

    Nice work

  • @johancoetzee6540
    @johancoetzee6540 6 месяцев назад

    Thanks

  • @salim.studio
    @salim.studio 9 месяцев назад

    What happend if i connect the DT in the CLk, and The Clk in the DT ?

    • @marios_ideas
      @marios_ideas  9 месяцев назад

      Then turning it clockwise would decrease the number and couterclocwise would increase it. So you would have opposite behaviour

  • @rezag.o.m5680
    @rezag.o.m5680 4 месяца назад

    Gold 😂

  • @lgswitch4813
    @lgswitch4813 Год назад

    good

    • @marios_ideas
      @marios_ideas  Год назад

      My pleasure:) like the video and subscribe to my channal. Also consider supporting it.

  • @liverecon769
    @liverecon769 Год назад

    Where is the code sir

  • @Scott.Farkus
    @Scott.Farkus 11 месяцев назад

    Once I move the knob on the encoder the output runs so fast I can't read it and keeps running even if I don't turn the knob anymore.
    Changed Serial.print to Serial.println and it starts a new line now, but the numbers don't change when I turn the encoder knob

    • @marios_ideas
      @marios_ideas  11 месяцев назад

      Which exact place in the video you are reffering to

    • @Scott.Farkus
      @Scott.Farkus 11 месяцев назад

      @@marios_ideas I'm referring to the code I got from the link

  • @driss25
    @driss25 Год назад

    Cd4026 et ne555 one kilo ehz

  • @egyrmexiq1
    @egyrmexiq1 Год назад

    Excellent video, very didactic.. thanks..