How Rotary Encoder Works and How To Use It with Arduino

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 พ.ย. 2024

ความคิดเห็น • 271

  • @jp040759
    @jp040759 3 ปีที่แล้ว +19

    WOW. Finally I understand the rotary encoder logic. Best explanation I have run into in 10 years. Your description turned on the big light bulb on in my brain and I understand it now. The code is so simple too. THANX!!!!!

  • @ricardocalletejada6707
    @ricardocalletejada6707 3 ปีที่แล้ว +2

    This is better than searching for confusing datasheets on the website. THANK YOU A LOT

  • @fanBladeOne
    @fanBladeOne 5 ปีที่แล้ว +7

    Thanks once again for a greatly instructional video. After watching not only do you understand the principle behind it, you also have a piece of working code at the ready. Thanks alot :)

  • @globalbusinessmachines3122
    @globalbusinessmachines3122 2 ปีที่แล้ว

    You are my savior in ELECTRONICS.

  • @sub-arts128
    @sub-arts128 3 ปีที่แล้ว +2

    well done. thats the best explanation for rotary encoder i ve seen so far

  • @camilo7087
    @camilo7087 7 ปีที่แล้ว +39

    please no stop .. you explain so good

  • @slimydroid
    @slimydroid ปีที่แล้ว

    Many thanks for the clear guide on how encoders work, I found the animated graphics particularly useful.

  • @bcinsteadof3
    @bcinsteadof3 6 ปีที่แล้ว +4

    Wow, such elegant code...My overly complex code didn't work well when I spun the encoder quickly, this works flawlessly. Thanks!

    • @TheChrisey
      @TheChrisey 3 ปีที่แล้ว +1

      It's not that elegant tbh, it should be implemented with hardware comparators and interrupts

    • @jimwithheld7217
      @jimwithheld7217 5 หลายเดือนก่อน

      @@TheChrisey Agree: the example in the vid is fine
      for slow speeds, and when there is feedback, such that if a count is missed, or extra, the user will self-correct, and everything is fine. For higher speeds, you need some hardware and maybe counters, which take care of the counts, and the main software just reads the counter any time it needs the values. Some of the Microchip PIC family have a hardware module built in. A quadrature Decoder. But you can also craft with some of the "soft" progamable gates, e.g. CLB and such.
      For very high speeds, e.g. motors at thousands of RPM, you can't really just poll the pins in a loop: you need hardware assist. Or very fast interupts might get you some of the way.
      But again: the example is fine for the right kinds of slower stuff.
      Also: switch-bounce shaping on the pins can be important, so you only get 1 count per count, not many. I did not look too deep at the code to see if maybe its state always handles that OK enough. A resistor and a cap might be enough, depending on the encoder used.

  • @badbush5
    @badbush5 6 ปีที่แล้ว +2

    Fantastic! Looking at pictures of waves just didn't do it for me. This video completely cleared it up. Thank you! Subscribed.

  • @OMNI_INFINITY
    @OMNI_INFINITY ปีที่แล้ว +1

    *Thanks! Recommend making a video on controlling position of a continuous servo using a continuous rotary encoder!*

    • @HowToMechatronics
      @HowToMechatronics  ปีที่แล้ว +1

      Currently working on such a video. I will publish it next week.
      Cheers

    • @OMNI_INFINITY
      @OMNI_INFINITY ปีที่แล้ว

      Oh, thanks in advance!@@HowToMechatronics

    • @OMNI_INFINITY
      @OMNI_INFINITY ปีที่แล้ว

      Another recommendation that is likely easy is a record and playback motion robot arm using servos. Bonus points for making it a pick and place machine with OCR!@@HowToMechatronics

  • @sgtrumbi2265
    @sgtrumbi2265 5 ปีที่แล้ว +9

    Just plain and simple explanation. Great video, exactly what I was looking for. Thank you so much! 😊

  • @jaimeriquelme6727
    @jaimeriquelme6727 ปีที่แล้ว

    Thanks Mechatronics for your time and work. From Sydney all the best. 👍

  • @cdweng840
    @cdweng840 7 ปีที่แล้ว +3

    Brilliantly explained from theory to application. Well done!

  • @mrcalico7091
    @mrcalico7091 8 ปีที่แล้ว +14

    Great Job, articulate and directly to the point. Thank You!

    • @mrcalico7091
      @mrcalico7091 3 ปีที่แล้ว

      @Samir Ben This is spam

  • @waterman7733
    @waterman7733 6 ปีที่แล้ว

    your explanations are so clear, makes it easier to understand how this works. thank very much!

  • @endingalaporte
    @endingalaporte 6 ปีที่แล้ว +1

    suscribed, videos are very good, I'm studying mechanical engineering, have to choose If I want to specialise in Mechatronics, your videos help me a lot in my choice, very cool

  • @cakdham4607
    @cakdham4607 8 ปีที่แล้ว

    Awesome explaination.. Regards from Indonesia

  • @loucostello3111
    @loucostello3111 6 ปีที่แล้ว

    This guy is the greatest.

  • @SimpleHumanInNY
    @SimpleHumanInNY 2 ปีที่แล้ว +1

    Thank you 🙏

  • @256k_
    @256k_ 2 ปีที่แล้ว

    Great stuff! I was initially looking at some library to handle this but it’s so easy thanks to your explanation I’ll just handle it myself

  • @jeffbeck6501
    @jeffbeck6501 6 ปีที่แล้ว

    Thank you. Your code worked. I thought that Kevin Darrah's code using interrupts was working for me but it was not. It was skipping all around but your code works perfectly for me with no skipping at all. How u do dat? Thanks man.

  • @vnesterov1817
    @vnesterov1817 7 ปีที่แล้ว +6

    You are the Man! Thank you: very clear and very consecutive instructions and video. Great job.

  • @LifeGeneralist
    @LifeGeneralist 3 ปีที่แล้ว +1

    Can you do a video on measuring the angle of rotation of the stepper if connected the encoder to the shaft of the stepper and if the shaft is rotated manually?

  • @antipainK
    @antipainK 3 ปีที่แล้ว

    Great video, short and to the point :)

  • @fouzaialaa7962
    @fouzaialaa7962 8 ปีที่แล้ว

    awesome seeing your videos again its been a long time since you uploaded a video !!

  • @mirkomueller3412
    @mirkomueller3412 8 ปีที่แล้ว

    Great tutorial !!! Helps me so much doing my current project. BIG THUMBS UP

  • @HellaFunnyShorts
    @HellaFunnyShorts 8 ปีที่แล้ว

    great video. simply and to the point explanation

  • @voxellab4339
    @voxellab4339 7 ปีที่แล้ว +2

    Dejan, Great video! thank you. Got it to work. If I turn the dial to quick the nema jump, not smooth and has a pause when reveres. I've tried trimming the drive board and the delay times. Any idea?, thanks again for all you great work.

  • @heshteach8212
    @heshteach8212 7 ปีที่แล้ว

    Grate job.. It was really effective for me.. thx alot and carry on..

  • @Three2NineProject
    @Three2NineProject 8 ปีที่แล้ว

    Simple and good explanation

  • @RunningRunner46
    @RunningRunner46 11 หลายเดือนก่อน +1

    Would be better if you used interrupts to accurately get only the falling edge of the output A's clock

  • @boharihamen
    @boharihamen 7 ปีที่แล้ว

    Thanks for the video. Great Job and effort to produce it.

  • @Otemaonen
    @Otemaonen 3 ปีที่แล้ว

    Very informative! Thanks!

  • @glowpon3
    @glowpon3 6 หลายเดือนก่อน

    Such a simple logic to test direction. I finally get it. Thanks so much ^,.'.,^

  • @muratcanbarut64
    @muratcanbarut64 5 ปีที่แล้ว +1

    Very good explanation

  • @karlklops3810
    @karlklops3810 7 ปีที่แล้ว

    very nice and short video keep it up 😊👍👍

  • @efrailustun
    @efrailustun 4 ปีที่แล้ว

    Great job bro, thanks for everything.

  • @m0gga
    @m0gga 7 ปีที่แล้ว +4

    Hi Dejan, thanks for sharing this helpful tutorial,I would like to use a rotary encoder to replace the menu navigation buttons in my project, your video is very useful.
    I notice that you did not appear to implement any software de-bouncing techniques to overcome the switch noise, yet your example did not appear to suffer from switch bounce. Did you use a hardware filter of some sort?
    Thanks.

    • @krallopian
      @krallopian 6 ปีที่แล้ว +1

      Yeah I was wondering about that. My encoder skips when I move it then when it clicks. So each "notch" counts as TWO. 0... 1,2... 3,4.... 5,6.... I suppose I can code accordingly but, slightly annoying.

    • @Xanty55
      @Xanty55 6 ปีที่แล้ว

      Yes, my encoder produces the same behavior.

    • @itskevscott
      @itskevscott 3 ปีที่แล้ว

      Maybe the two Serial.print() statements in the loop slow it down sufficiently that the chatter has stopped by the time it looks around again. With a faster arduino like an ESP32 the bouncing may be seen again. Havent tested it but just a thought!

  • @bekhzodkh
    @bekhzodkh 8 ปีที่แล้ว +1

    Nice and clear explanation, thanks for the video. I wonder is it possible to control the LED light intensity using this encoder?

    • @hammadahmad1137
      @hammadahmad1137 11 หลายเดือนก่อน

      Just use a potentiometer DUH

  • @RixtronixLAB
    @RixtronixLAB ปีที่แล้ว

    Nice info, thanks for sharing with us, well done :)

  • @ROBJECTS
    @ROBJECTS 2 ปีที่แล้ว

    Thank you friend!

  • @TheJavaSync
    @TheJavaSync 4 ปีที่แล้ว

    Dear Friend, pls, upload another ligh & simply tutorial like this, I loved it, Thx You !

  • @Anton-wc7lb
    @Anton-wc7lb ปีที่แล้ว

    Awesome video, thanks! :)

  • @BrijeshKhumaar
    @BrijeshKhumaar 3 ปีที่แล้ว

    Thanks that was amazing...

  • @arjunjanardhanan3301
    @arjunjanardhanan3301 8 ปีที่แล้ว

    Again nice one ! Can you make a separate video on ADXL345?

  • @dgb5820
    @dgb5820 6 ปีที่แล้ว

    Great instructional video

  • @eleobo
    @eleobo 5 ปีที่แล้ว

    which software is used to make the animation .?

  • @armaky4962
    @armaky4962 3 หลายเดือนก่อน

    Thank you very much for the information " Hugs

  • @PVCLime
    @PVCLime 4 ปีที่แล้ว

    This has to work with a teensy as well right?

  • @cdersch636
    @cdersch636 7 ปีที่แล้ว +3

    Do you know the maximum speed of the decoder? Can it turn up to 200 rounds per minute? I tested once and it was not counting correctly - so the question is - was a problem with Arduino or with the mechanic of the decoder?
    Thanks you

  • @GabrielSousa-hw4mg
    @GabrielSousa-hw4mg 6 ปีที่แล้ว

    omg you explain so good thanks

  • @requiem4adreamc
    @requiem4adreamc ปีที่แล้ว

    Can we bind a rotation to a key? For example if i turn it clockwise with every step it will press 'A'.

  • @duneeshasuloshini8567
    @duneeshasuloshini8567 5 ปีที่แล้ว

    great explanation! Thanks a lot.

  • @dawidwilk7488
    @dawidwilk7488 6 ปีที่แล้ว +4

    Your code working well but you must put it into interrupt event from rising and falling edge caused by A and B signals.

  • @apbosh1
    @apbosh1 7 ปีที่แล้ว

    great tutorial thank you.

  • @javierferrer4634
    @javierferrer4634 5 ปีที่แล้ว

    Nice video thank you!

  • @pkteguh8199
    @pkteguh8199 8 ปีที่แล้ว

    thanks for your tutorial, it helps,regards

    • @pkteguh8199
      @pkteguh8199 8 ปีที่แล้ว

      referring your tutorial,so is it possible to synchronize two surface speed of conveying belt/goods ?, since the encoder rotated by a surface speed and give the signal as a control to a motor that can produce similar surface speed to another conveyor for example, thanks for your feedback,regards

  • @asmaakter2929
    @asmaakter2929 5 ปีที่แล้ว

    If I use a magnetic encoder circuit in micrometal gear motor ...does it be work like stepper motor
    Wait for a quick reply

  • @MrAdd25
    @MrAdd25 4 ปีที่แล้ว

    thanks, the best explication!!!

  • @irfan2189
    @irfan2189 5 ปีที่แล้ว

    GOOD WORK BRO..

  • @Keith12001
    @Keith12001 7 ปีที่แล้ว

    Excellent videos, thank you

  • @SajalRajGautam
    @SajalRajGautam 8 ปีที่แล้ว

    Very helpful! Thank you so much! :)

  • @yoramstein
    @yoramstein 7 ปีที่แล้ว

    Good explanation, thank you.

  • @Sasch600xt
    @Sasch600xt 8 ปีที่แล้ว

    Thank you very much !!! Now i understand it :)

  • @hossammoghrabi1021
    @hossammoghrabi1021 7 ปีที่แล้ว

    what software you use to create these graphics and animation

  • @0sekful706
    @0sekful706 4 ปีที่แล้ว +1

    Amazing, thank's a lot!

  • @lovelyapple7167
    @lovelyapple7167 13 วันที่ผ่านมา

    what type of encoder i need to use for Cessna instrument bezels? ( similar to altimeter motive channel )

  • @bigd1266
    @bigd1266 4 ปีที่แล้ว

    You are the man!

  • @kamranalidoosti9799
    @kamranalidoosti9799 7 ปีที่แล้ว

    Thank you Dejan. You are a good teacher. Go on!

  • @thomashvnmusic
    @thomashvnmusic 8 ปีที่แล้ว

    Really helpful, thanks.

  • @AliIsmaeltyphoon
    @AliIsmaeltyphoon 4 ปีที่แล้ว

    Can it continue to increment after more than one revolution please ? Thanks for answering.

  • @salmaelasmai5065
    @salmaelasmai5065 7 ปีที่แล้ว

    thank you this was very helpful, but you didn't talk about the difference beetwen absolute and incremental encoders..

  • @minayakarimova
    @minayakarimova 4 ปีที่แล้ว

    Huge thanks

  • @sakshamsangwan6811
    @sakshamsangwan6811 6 ปีที่แล้ว

    What is the least angle it can move ?
    For example
    If I connect it to a shaft of a robotic arm will it give 30 counts with 30 degree change ?

  • @BinuMadhav.NetWork
    @BinuMadhav.NetWork 5 ปีที่แล้ว

    can you make a video of digital potentiometer x9c103 with and without Arduino? Thanks in advance

  • @airfilm_it
    @airfilm_it 6 ปีที่แล้ว

    i would like to build a wireless follow focus for cine lens, what's your suggest?

  • @denadaisicari
    @denadaisicari 5 ปีที่แล้ว

    So great, thanks!

  • @ngobachduong
    @ngobachduong 7 ปีที่แล้ว +1

    Nice explanation and animation.
    But in your code, it will be more accurate if you use interrupt function to detect the change of signal.

  • @leonidarndt
    @leonidarndt 4 ปีที่แล้ว

    where I can buy all those components?

  • @_bluespider5470
    @_bluespider5470 6 ปีที่แล้ว

    Great video!

  • @er.jugalmandal7736
    @er.jugalmandal7736 7 ปีที่แล้ว +9

    CAN U MAKE A VIDEO WITH IN MENU USING 16x2 LCD DISPLAY ???

  • @joost199207
    @joost199207 6 ปีที่แล้ว

    Great explanation, everything i needed to know.

  • @yashgokhale5238
    @yashgokhale5238 3 ปีที่แล้ว

    Thanks for uploading the video.
    For some modules above program functions only when INPUT_PULLUP is defined for CLK and DT pins

  • @Hamzakhan1o
    @Hamzakhan1o 4 ปีที่แล้ว

    i am interested in taking admission in mechatronics but everywhre i only see arduino is it a good field?

    • @Hamzakhan1o
      @Hamzakhan1o 4 ปีที่แล้ว

      i cant see other mechanical work just coding and arduino

    • @Hamzakhan1o
      @Hamzakhan1o 4 ปีที่แล้ว

      How is it even MECHAtronics when there is no or minimum Mechanics practically no lathe machining etc

  • @victorb22622
    @victorb22622 ปีที่แล้ว

    Nice video।i was just came here to know how actualy it works .i know what's it's use.i just bought like this.i know before i ordered that is used with microcontroller.i have one costly device having mebrane keyboard.there are keys up and down .though these two keys i can increase or decrease the value .i studied the matrics of membrane keypad.i gind which lines are short when i press the perticular key. I just want to replace these two keys of up and down with this rotory encoder switch.i don't want to use microcontroller because the device is costly, single mistake can spoil the system.i bought bit not tried it anyway. before i try i woyld like to understand how it works .have you any hint in this regard.please reply .
    Note :If it is the case where i have to use microcontroller ,i can do ,because i know the whole things regarding MC and script writting too.

  • @NanoIndustries
    @NanoIndustries 4 ปีที่แล้ว

    That's What I Want To Know Thanks

  • @ruffnck4637
    @ruffnck4637 4 ปีที่แล้ว

    The best one at yutub ¡

  • @tingundertaker
    @tingundertaker 7 ปีที่แล้ว

    Is rotary encoder same as resolver? Please explain or make a video about it.

  • @chloemcholoe3280
    @chloemcholoe3280 5 ปีที่แล้ว

    does it make sense to use this as an interrupt in your code or is that OP? cause if the project has other things to do i'm worried it'll miss this

  • @omsingharjit
    @omsingharjit 5 ปีที่แล้ว

    Why it need vcc and gnd if it is passive type?!

  • @werdy64
    @werdy64 8 ปีที่แล้ว +1

    Hello Dejan,
    A lot of thx for your lessons and explanation. I gonna to use this sketch for some regulator with rotary encoder. I made a copy of your sketch and everything was OK. Some time later unfortunately in the serial monitor I've got double increment and double decrement for each click of the encoder. My version my encoder went out of order. Could there any problem with arduino? What you about?

    • @joriskingma
      @joriskingma 7 ปีที่แล้ว

      Hey Werdy, I have the same issue, did you solve it? @Dejan: Thanx for the video, very helpfull!

    • @werdy64
      @werdy64 7 ปีที่แล้ว

      Hello Jiris,
      Yes. I've found solution. Like this one. There are two interruptions for Arduino UNO. You can change interruption number dependently the board model. If you need the line "encoder0Pos++" or "encoder0Pos--" could be changed for another one. For example encoder0Pos=encoder0Pos+10 or encoder0Pos=encoder0Pos-10.
      #define encoder0PinA 2
      #define encoder0PinB 3
      volatile unsigned int encoder0Pos;
      boolean A_set;
      boolean B_set;
      void setup() {
      pinMode(encoder0PinA, INPUT);
      pinMode(encoder0PinB, INPUT);
      encoder0Pos=0;
      // encoder pin on interrupt 0 (pin 2)
      attachInterrupt(0, doEncoderA, CHANGE);
      // encoder pin on interrupt 1 (pin 3)
      attachInterrupt(1, doEncoderB, CHANGE);
      }
      void loop(){
      // there should be your code
      }
      // Interrupt on A changing state
      void doEncoderA(){
      // Low to High transition?
      if (digitalRead(encoder0PinA) == HIGH) {
      A_set = true;
      if (!B_set) {
      encoder0Pos++;
      }
      }
      // High-to-low transition?
      if (digitalRead(encoder0PinA) == LOW) {
      A_set = false;
      }
      }
      // Interrupt on B changing state
      void doEncoderB(){
      // Low-to-high transition?
      if (digitalRead(encoder0PinB) == HIGH) {
      B_set = true;
      if (!A_set) {
      encoder0Pos--;
      }
      }
      // High-to-low transition?
      if (digitalRead(encoder0PinB) == LOW) {
      B_set = false;
      }
      }

  • @faiqzulazlan2029
    @faiqzulazlan2029 2 ปีที่แล้ว

    can i get this schematic diagram?

  • @shubhamdubey3585
    @shubhamdubey3585 7 ปีที่แล้ว

    Nice video buddy keep it up :)

  • @pabloflores6328
    @pabloflores6328 4 ปีที่แล้ว

    great!! can I ask you abput this topic?
    I have a encoder with 8 Cables and 1500 ppr ( A+ a- B+ b- Z+ z-). I just connect the A and B to the arduino uno with this code. But the reading speed is not enough to catch all the pulse i think.
    Do you think that an arduino Due could help me? Or based on your experience what could be the solution?
    thanks

  • @duongphamhai3367
    @duongphamhai3367 3 ปีที่แล้ว

    Hello How To Mechatronics, Keyes Rotary Encoder Module can connect to stm32f103 to control?

  • @jugnu361
    @jugnu361 8 ปีที่แล้ว

    Great Work

  • @sakirdag2976
    @sakirdag2976 5 ปีที่แล้ว

    Very good

  • @gvinodkumar4224
    @gvinodkumar4224 6 ปีที่แล้ว

    very super and good teching

  • @navtejsinghsaini4945
    @navtejsinghsaini4945 8 ปีที่แล้ว +1

    which animation tool did you use?
    Thanks

  • @dunamiscrisostomo5441
    @dunamiscrisostomo5441 5 ปีที่แล้ว +2

    2:47 that pitch tho