Control a Stepper Motor using an Arduino and a Rotary Encoder - Tutorial - Part 1

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 มิ.ย. 2024
  • In this first part of controlling a Stepper Motor with a Rotary Encoder, we will use the 28BYJ-48 stepper with the included ULN2003 driver board. These little steppers a cheap and good to start learning about using stepper motors with an Arduino.
    In Part 2, we will use a Nema 17 motor with the EasyDriver board instead.
    Check out our tutorials page at : brainy-bits.com/tutorials/ to get the schematic and more information on this tutorial.
  • วิทยาศาสตร์และเทคโนโลยี

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

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

    Hi guys, thanks a lot for that code and all. I´m looking for exactly that for hundred years and you made it happen. I´m very glad about it. I use it for my model train to move the track in front of an engine shed. Thank you so so much and continue with your great job. Stay safe. Many greetings from Germany.

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

    I love your tutorials! They're all unique and useful.

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

    Hi, Brainy Bits, I am so sad that you are under rated tutorials mentor, all your explanation are precise, simple and easy to grasp and implement. I hope one day see a 10000000 sub. please don't let us down. thank you

  • @aprendendo.astronomia
    @aprendendo.astronomia ปีที่แล้ว

    Friend. Thanks a lot. I had been searching a lot to get rid of my analog potentiometer floating reads and this will save my life (hope so). I don’t need speed, but precision, keep simple and also portable. Thank you very much and will buy the encoder right now.

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

    by far one of the best stepper motor videos I've seen. Very in-depth explanation of the code line by line which is hard to come by! well done!

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

      Thanks Chris... Should have more videos coming soon... Thanks for watching!

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

    saw the Pebble and Subscribed instantly, great tutorial too

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

    Thanks for making such a great tutorial

  • @XpiredMilkChunks
    @XpiredMilkChunks 8 ปีที่แล้ว +2

    Thank you I am really trying to get into this you guys really helped

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

      +XpiredMilkChunks Glad our videos are helping! Thanks for the comment and watching!

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

    Hi! Great tutorials,everything well explained,without rushes.
    Ive seen all your videos, but i was (still am) looking for a multi movements of the steppers,previously saved in arduino code. This to avoid to use browsers, i.e., tell the arduino (by a string or similar) to move the stepper like this: move to 1stop,move to 2stop,move to 3stop etc. So,instead of using the encoder or a pot, to use sequencial predefined positions.
    Thanks!

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

    Great greetings from Argentina

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

    Cool this helped a lot, thanks.

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

    this looks like a very useful setup, thanks for taking the time to upload, could you please add homing and limit switch's to the code, or a video on how to include homing and limit switch's, I'm new to motors and struggling with homing and limit switch's, i need exactly your setup in this video, same motor setup/encoder, i identical but with homing and limit switch's , ive been working on it for a very long time and about to give up, any help please. thanks

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

    Hi, thanks so much for the tutorial. I have a problem where my stepper will turn fine in one direction but in the other it is unreliable and will twitch around. This is the same with this tutorial and the one for the NEMA stepper. I have tested both motors with test code and they are both good. I think it must be the encoder but I have 5 and they all act the same. Any ideas?! Thanks again.

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

    Sorry, cannot find this tutorial (nor subsequent ones relating to this first one) at that link. Is it under a different name or has it been removed. I would like to get involved more with my uno and stepper motors.

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

    Could you do a video with steppers and PID control for position?

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

    Hi ... tnx for amazing tutoral . I have a question ... can u explain me for increscent a lcd for count with this rotary encoder!?

  • @donaldhoudek2889
    @donaldhoudek2889 8 หลายเดือนก่อน

    GREAT video!

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

    awesome ! but will it work for the arduino nano ?

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

    thanks for this nice tutorial, it helps ,regards

    • @MARS-GREENH0USE
      @MARS-GREENH0USE 4 ปีที่แล้ว

      its a web link and it doesn't have a lot of help unless you have the exact parts as they do

  • @KW-ei3pi
    @KW-ei3pi 11 หลายเดือนก่อน

    Excellent tutorial. Where can I get some help with modifing the code and wiring for my project? Thanks

  • @slydog9186
    @slydog9186 2 หลายเดือนก่อน

    Thanks for such a great video.
    I have a question though; will it work with Esp 32's (Master and slave style) [Rotary Encoder: Stepper Motor]?

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

    Thanks. One question, I thought the little motor you were using was unipolar not bipolar? Maybe I'm mixed up....

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

    It's Possible to use uln2003 motor driver to control other stepper motors? Thanks!

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

    Hi! Have this encoder a little snap for accuracy? like the one in the car audio system of the volume control. Sorry for my english. Greetings from italy.

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

    thank you so much for the tutorial, can you help me to use the serial monitor of the Arduino for example with this code? thank you =)

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

    plz reply me....
    Thanks for making this video .......I have some questions regarding my project are....
    1. for NEMA 23 motor 2.8 amp which driver should I use
    2.plz can you send Arduino coading for ' if we rotate rotary encoder 30° then motor rotate 15° in opposite direction '
    3. when I rotate encoder the torque is same as on motor specifications or less??
    Thank you very much.........

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

    Could you do that same setup, but use the encoder to "start the motor in 1 direction, having it just run continually, until you push the button to stop it, or reverse the encoder? Also, the further you turn the encoder, the faster the motor spins. So 50% encoder clockwise means motor spins at 50% speed continually in the same direction? Thanks..
    Great Video

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

    what if I wanna use more than 1 stepper motor??
    lets say that for stepler motor one you have ints PinCLK, PinDT, PinSW... how would it be for then 2nd? could i name it PinCLk2, PonDT2, PinSW? and for each statement repeat twice but the second one adding 2 indicating stepper motor 2? Your answer would mean a lot.. Im new to stepper motors and Im using this stepper motors to control a robotic arm... thank you

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

    parabens Brainy exelente projeto teria como gravar as duas posições e depois fazer a leitura, e que ficasse repetindo a gravação? direita esquerda? abraço Brainy

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

    nice tutorial !!!!!!. Tell me something plz. In your video you can control the position of a stepper motor by rotating the rotary encoder. If you want continues rotation with speed control (like a potentiometer for example), can you do it with rotary encoder? . For example, you can control the position as you video. Fine. When click the rotary encoder, instead of returning back, can you use it for continues speed control ? (like a potentiometer?) thank you

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

    Hallo,
    I wanted to build an automatic grill for shashlik ... The mechanics are not a problem (and most of it is ready) but we were thinking about something that would turn it automatikly for example 1/4 turn every minute by pushing a button! But we have no clue how to program something like this...Has sombodey an idea?

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

    Sir how to run the continuous cycles like you done with rotary encoder

  • @user-ge2lt6em4r
    @user-ge2lt6em4r 6 ปีที่แล้ว

    А можно ли использовать этот sketch с платой Arduino nano? И можно ли уплравлять одним энкодором двумя шаговыми двигателями, не сразу, а по очереди?

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

    very nice site and the tutorial is gooooooood
    شكرا

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

      +Ali S.aldin Thanks for the comment and watching of course :)

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

    Hello. Very interesting video. Sorry to ask a boring question, but where do you get the gear from? I'm having trouble finding anything on Ebay/Amazon and can't seem to find it in your store?

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

      +DarkShadow753 I cut this little gear at the last minute for this video with our laser cutter. We will start offering more custom parts in our store this coming year. Thanks for the comment and watching!

  • @aprendendo.astronomia
    @aprendendo.astronomia ปีที่แล้ว

    Friend, this blue knob you put on the encoder. What is this ? Where did you find it ?

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

    Really cool thanks

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

      Thank you for the comment and for watching!

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

    is there is a possibility to remove the shock from the stepper motor. when turning the rotary encoder it is only one direction .if I turn one way, it goes well but in the other direction it is shocking and it does not go well. how can I solve this?

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

    is the rotary encoder an optical one?

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

    Did this project take long to build?

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

    Hi,- Excellent tutorial.
    Can you tell me if the USB connection on the breadboard power supply is for 5v in or out because if its for 5v in I think you would need a special USB Cable.
    I will definitely get one if I can drive it from a USB input.
    Thanks - Keep up the good work

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

      Hi, I believe these Breadboard power supply can be powered by USB, but keep in mind that a typical USB port on a computer has a 500mA limit. Or you could use a Cell Phone charger with the correct cable like you said. Thanks for your comment and for watching!

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

    is stepper motor's speed gradually decrease and then become zero or not ?

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

    How can i use this encoders in a robotic arm with those stepper motors and save the positions to after make an infinite loop ??Can you help me please ??

  • @2006razaq
    @2006razaq 7 ปีที่แล้ว

    Hi, I am controlling my stepper motor automatically from the Arduino board, but once it moves and stops where I want, It does not go back to original (home) location [after short delay]. Any help with coding please

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

    I use your code but when I turn one side it works well but in the other direction it starts to shock and does not turn around nicely. can you help me why he does so? I use a nano ivp the big arduino. the project is now taking to long hahah im working on it for 4years now and still not making progress.
    gr buas

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

    Can we change the degree?
    if I turn the encoder 90' then the stepper turn 10' only.

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

    hi I cant find 4 pin potentiometer.please somebody give a link for buy

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

    Now just replace the cheap Rotary Encoder with a normal one that does not skip steps.
    Any way to make tutorial using buttons and a way to choose direction and number of steps to choose on LCD?

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

    hey brainy bits ..please help me brother..i want to control two stepper motors exactly like that..can i control two stepper motos with one rotary encoder?i want to move the motors at same time..

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

    Nice, thanks. I think I followed all the steps but my stepper turns always in the same direction no matter which way I turn the encoder. Where am I wrong?

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

    could you provide the code for the same project but with servo instead of stepper motor?

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

    Is there a particular Arduino kit I should get to run a stepper motor like in this video? Amazon has several different brands I'm not sure what the differences are to choose one : (

    • @wavesofgrey-vb9gw
      @wavesofgrey-vb9gw 6 ปีที่แล้ว

      I got the elegoo kit which had 5 motors and 5 drivers. The driver board in this kit does nothing but increase the voltage from the arduino pins, and the leds on the side of driver show which pins (connected to motor) are getting power (which is great for learning).
      "Elegoo 5 sets 28BYJ-48 ULN2003 5V Stepper Motor + ULN2003 Driver Board for Arduino"

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

    how can i do this with servo motors?

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

    +Brainy-Bits I would like to control 3 stepper motors with different "rotary encoders" modules for each of them, and I would appreciate if you can explain me a doubt that I have, the encoder can be connect to different pins, for example I have a Arduino mega and I would like to know if I can connect to pins 24, 25 and 26, I have read the pinout of Arduino uno and I realize that the pins to which you connect the encoder in the video has something peculiar as to the type of outputs as of digital inputs (pwm pin)
    thank you very much

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

      +Billy Zamora Díaz Check out this other video we did here: th-cam.com/video/O9Pr1ZLYUmE/w-d-xo.html were I explain how to make any pin an interrupt pin so you can attach 3 Rotary encoders to an UNO board if you want, each having their own interrupt! Hope it helps! Thanks for watching!

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

    you can add two 1uF capacitor between A n GND and B n GND, and it will improve step skipping alot

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

      Hi Herantd, can you please explain how to put these capacitors into the scheme?Thanks, Martijn

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

      ccrma.stanford.edu/wiki/Images/c/c1/Encoder_filter.png

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

      I'm not so good at reading schemas where the 1uf capacitors come in between thnx

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

      Never delay inside an ISR. Period.

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

    I use this application for train turn table and working as a dream, just slow rotation to 70

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

      Love to hear that others are using these tutorials to help them with their projects! Thanks for sharing and for watching!

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

    Possible to use 2 step motor and 2 rotary encoder? And is it possible to find me the code please?

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

    I set this up, but on mine it doesn't always turn the stepper, and the lights on the driver board kind of switch around without input, I must have messed something up in the code.

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

    I was planing to the same project (without the push button turing tha same previous position) , but i notice than the driver lights stay always turned on. This mean than the motor is always on! and consume a lot of battery . how you can obviate this problem ?

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

      +Julis Lybeshari The module that comes with this Stepper motor, doesn't have a pin to put to sleep or turn it off, but I guess you could use a 5V relay to turn it off with the Arduino when it's not needed, that way it wouldn't consume any power. Hope that helps and thank you for your comment and watching :)

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

      +Brainy-Bits Many thanks. i will try.

  • @187781jason
    @187781jason 8 ปีที่แล้ว

    Can I use this setup to run a 12v stepper motor? Also is there a safer way of ensuring the rotary encoder doesn't skip or twitch when it misses the que?

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

      +jason daysh Check out our other video here: th-cam.com/video/O9Pr1ZLYUmE/w-d-xo.html i made some changes to the interrupt for the rotary encoder to make it more precise. Not perfect of course but better :) Hope it helps. Thanks for watching!

    • @187781jason
      @187781jason 8 ปีที่แล้ว

      Brainy-Bits
      Thanks for the extra info, I'm watching all your videos now and taking loads of notes. It's a great selection. Cheers :)

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

    You shouldn't use delay() inside your interrupts. You might mess up syncing with the internal clock in your code.

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

      Can you break down "the why?" - I'm not familiar with why you would or wouldn't

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

    AMIGO COMO EU FARIA PARA USAR 2 MOTORES NESSE MESMO PROJETO ? E PARABÉNS PELO VÍDEO.
    FRIEND LIKE I DO TO USE 2 ENGINES IN THE SAME PROJECT ? CONGRATULATIONS AND VIDEO.

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

    Hi!! What happend when you power off or reset the arduino when the motor is not in the 0 posicion? Does the motor save the correct 0 posicion?

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

      +Rube G No, you would have to implement some sort of Home function when the Arduino starts up, to make sure the stepper motor goes to a starting point. You can check out this video here where I talk about using limit switches : th-cam.com/video/dQuTgngoFPQ/w-d-xo.html Hope that helps and thanks for watching!

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

      +Brainy-Bits thank you greetings my friend!!

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

    Why isn't the code on brainnybits web site???

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

    Can u help me? I know how to use an enconder and a stepper but, i want to learn how to save a sequence of movements with variations of speed during 5+ minutes and use a button to repeat the actions that ive done before...

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

      The idea is a motion control... I want to use 5 motors with encoders to enter different sequences of movements, cw ccw, speed variations... Saving the movements to repeat forward and backward. Can u do a video about it?
      Tks!

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

      Thanks for the suggestion, I have though of doing something like this, recording movements and play them back... Will try to do a video on that. Thanks for watching!

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

    is it possible to get the schematics for your circuit??

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

      just found your website! thank you,

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

      +sidgarth ansac You can check here: brainy-bits.com/tutorials/ to find more information, parts used and a schematic for most of the tutorials we post on TH-cam. Thanks for watching!

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

    thx ♪♫

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

    I got this motor in a starter kit from sunfounder. They say, that i can use the 5v pin of the arduino, but the kit is really poorly made and i think, the guys from sunfounder just don't know, what they are doing. Their example code is also shit. I don't have a power supply, so what should i do?

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

      +StarTrek123456 These motor only draw 92mA current so it's ok to connect them directly to an Arduino if you want. Thanks for watching!

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

    Plz help me with circuit daigram

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

    Very beautiful and wonderful but the nicest when you speak Arabic. Hossam / Egypt

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

    greats think it very important for a beginner ARDUINO UNO programer
    my questions :
    *1st :can we use an arduino to control a real industrial machine (using a PC power supply to supply the Arduino ) ?
    *2ed : what happen when we use Arduino in an electromagnetic interferance place ......are there risques of loss informations controlling ?
    best regards frome Nouari LAZREG automation Engineer and Operation manager of AFITEX company

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

      It depends on what kind of industrial machine ( control signals required etc ) . A pc power supply has both 12V and 5V so you have the answer. A Engineer who ask "what could happen in a electromagnetic interferences" ...you a Engineer, aren't you !? Man you're askind for the "shielding"...

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

    Load cell + encoder project

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

    Could I get a copy paste of the code used? I dont find it in my Arduino files

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

      You can check out our tutorials page at : brainy-bits.com/tutorials/ to get the schematic and more information on this tutorial. Thanks for watching!

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

      @@BrainybitsCanada Can't find the code

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

    can you pass the code plis

  • @mikeulloa
    @mikeulloa 6 ปีที่แล้ว +9

    Thank you; however, this tutorial does not help. There are no shots showing which pins are connected to the devices.

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

      Hi Mike, you can find a tutorial page for most of our videos on our website here: brainy-bits.com/tutorials including a pic showing all the connections. Hope that helps and thanks for watching!

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

      www.brainy-bits.com/stepper-motor-rotary-encoder-p1/

  • @user-en1jp5ii6c
    @user-en1jp5ii6c 7 ปีที่แล้ว

    nice work, but i think if you connected the knob to a pulley by a cable and turn it you will get the same result, I m just joking thank you for your work.

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

      Hi, sorry I missed your comment a year ago... But started laughing when I read it just now :) Thanks for the laugh and for watching!

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

    arduino source code?

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

      #include "Stepper.h"
      #define STEPS 32 // Number of steps for one revolution of Internal shaft
      // 2048 steps for one revolution of External shaft
      volatile boolean TurnDetected; // need volatile for Interrupts
      volatile boolean rotationdirection; // CW or CCW rotation
      const int PinCLK=2; // Generating interrupts using CLK signal
      const int PinDT=3; // Reading DT signal
      const int PinSW=4; // Reading Push Button switch
      int RotaryPosition=0; // To store Stepper Motor Position
      int PrevPosition; // Previous Rotary position Value to check accuracy
      int StepsToTake; // How much to move Stepper
      // Setup of proper sequencing for Motor Driver Pins
      // In1, In2, In3, In4 in the sequence 1-3-2-4
      Stepper small_stepper(STEPS, 8, 10, 9, 11);
      // Interrupt routine runs if CLK goes from HIGH to LOW
      void isr () {
      delay(4); // delay for Debouncing
      if (digitalRead(PinCLK))
      rotationdirection= digitalRead(PinDT);
      else
      rotationdirection= !digitalRead(PinDT);
      TurnDetected = true;
      }
      void setup () {

      pinMode(PinCLK,INPUT);
      pinMode(PinDT,INPUT);
      pinMode(PinSW,INPUT);
      digitalWrite(PinSW, HIGH); // Pull-Up resistor for switch
      attachInterrupt (0,isr,FALLING); // interrupt 0 always connected to pin 2 on Arduino UNO
      }
      void loop () {
      small_stepper.setSpeed(600); //Max seems to be 700
      if (!(digitalRead(PinSW))) { // check if button is pressed
      if (RotaryPosition == 0) { // check if button was already pressed
      } else {
      small_stepper.step(-(RotaryPosition*50));
      RotaryPosition=0; // Reset position to ZERO
      }
      }
      // Runs if rotation was detected
      if (TurnDetected) {
      PrevPosition = RotaryPosition; // Save previous position in variable
      if (rotationdirection) {
      RotaryPosition=RotaryPosition-1;} // decrase Position by 1
      else {
      RotaryPosition=RotaryPosition+1;} // increase Position by 1
      TurnDetected = false; // do NOT repeat IF loop until new rotation detected
      // Which direction to move Stepper motor
      if ((PrevPosition + 1) == RotaryPosition) { // Move motor CW
      StepsToTake=50;
      small_stepper.step(StepsToTake);
      }
      if ((RotaryPosition + 1) == PrevPosition) { // Move motor CCW
      StepsToTake=-50;
      small_stepper.step(StepsToTake);
      }
      }
      }

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

    on the 17th line delay(1000) remove the 1000 and add 0 the motor will move continuously .

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

    How did you manage to spin it that fast? It is 4096 step in one revolution according to spec (www.instructables.com/ORIG/FQY/RHST/HMVJ7U24/FQYRHSTHMVJ7U24.pdf) and frequency 100Hz.. which makes it about 40 seconds for one revolution, that is how fast I managed to spin it.. thanks.

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

      From my understanding the library we are using runs those steppers in 4-step sequence.
      Your mention of 4096 steps per revolution is correct when the stepper is run in 8-step sequence.
      So in 8-step it will take 4096 steps for a full revolution of the shaft. But in 4-steps it will only take 2048 steps.
      That's why the stepper is running faster in this tutorial video. You can checkout our tutorial page here: brainy-bits.com/tutorials/stepper-motor-rotary-encoder-p1/ and get more information. Hope that helps and thank you for watching!

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

      Brainy-Bits, yes, I wrote driver for 8 step sequence , I remembered it gave motor extra torque. Thanks.

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

    Est-ce que je détecterais pas une tite tite micro accent québécois? :)

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

    Sir send Arduino code

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

    I like it, But I don't want to use an arduino