Ping Pong with the AccelStepper library and two limit switches - Polling and interrupts

  Рет қаралды 31,155

Curious Scientist

Curious Scientist

4 жыл бұрын

In this video I show you two ways of using 2 limit switches to bounce the stepper motor-moved linear carriage between some arbitrary positions. I show you how to set up everything and I show you and explain both software.
Please subscribe if you found it helpful!
Check this video for wiring and further instructions:
• TB6600 and Arduino - W...
Source code:
curiousscientist.tech/blog/pi...
AccelStepper's website: www.airspayce.com/mikem/ardui...
If you want to support my work, please consider buying the parts using my affiliate links:
curiousscientist.tech/tools

Пікірлер: 130
@jabels4479
@jabels4479 2 жыл бұрын
I got this working with a different driver (DM542T), the instructions still apply and work the same way. I also really appreciate you showing how to add more functionality in the code towards the end. Like any language you don't fully understand, reading it is much easier than writing it and it helps with my syntax a great deal. I subbed and donated $20, not just for a great video but also how well your documentation is on your website.
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Hi! Yes, the principles are the same as long as the driver has the step, direction and enable pins. In fact I have a video on my channel where I show 3 or 4 different drivers running with the exact same code. You donation is very appreciated, thank you!
@zachshellouff7205
@zachshellouff7205 3 жыл бұрын
Solid code, can easily test limit switches before use. You may want to declare variables inside your ISR function as volatile rather than bool but if it works it works!
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Yes, the ISR-related variables should be volatile! Sometimes I forget it. :)
@zachshellouff7205
@zachshellouff7205 3 жыл бұрын
@@CuriousScientist yeaa I would too!
@_Error_404_Goodbye
@_Error_404_Goodbye 4 ай бұрын
Video/project idea: I’ve never yet seen anyone make a system like this that counts steps and converts them into distance traveled. For example, you want to make a small at home assembly line, and you’re cutting a lot of rods, of whatever material, at a specific length, and you want to make an automated, highly accurate measuring system using a similar layout to this. Using a homing sequence to find the point of origin (zero) then homes against the rod you want to measure. The whole system being a fixed length of possible travel, and the rod displaces however much of that possible amount of travel, the arduino could then figure out by how many steps it took between the first homing cycle (zero) and where it contacted the rod. If that makes sense? 🤔 I feel like that didn’t make much sense, but in case it did, I’m posting 😄
@CuriousScientist
@CuriousScientist 4 ай бұрын
Hi! If you check my videos, I have a well explained example on how to convert steps to linear displacement using lead screws and vice-versa. Based on that video and this example, the system you proposed could be made. However, I am not planning to make a video on it, because I don't need such equipment.
@MakerDan55
@MakerDan55 Жыл бұрын
Very helpful. Thanks 👍🏿
@CuriousScientist
@CuriousScientist Жыл бұрын
Glad I could help! Cheers!
@MakerDan55
@MakerDan55 Жыл бұрын
@@CuriousScientist you answered a lot of questions I had. I really appreciate your explanation and details about the code.
@CuriousScientist
@CuriousScientist Жыл бұрын
Great to hear! I have a great bunch of stepper motor-related videos, so if you will still need some information, please look around on my channel or on my website. I shared a lot of projects with stepper motors. And if there are still questions, just ask.
@shahidiqbal8511
@shahidiqbal8511 4 ай бұрын
good work
@CuriousScientist
@CuriousScientist 4 ай бұрын
Thanks!
@AllanWallsPhotography
@AllanWallsPhotography 2 жыл бұрын
Thanks for this video! I used this code to program a Nano that I was using with an Easy Driver to drive a 17HS4401. All I was trying to do was reverse the direction of travel at the limits of a belt driven rail. It worked flawlessly when the circuit was first powered up but within a few minutes the limit switches were bouncing so that the direction was reversed twice and the carriage got stuck. I have both of my switches wired to the NO circuit and have added a pair of 10K-ohm resistors to pull the NO circuits to ground when not being pressed. I have tried changing the motion parameters and removing the pull downs, but nothing seems to be helping. Can you think of anything else I could try? Thanks for all your excellent work!
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Hi Allan, Yes, sometimes these switches are still noisy with the extra pull-up/down resistors. One can also add an additional debouncing capacitor (100 nF is a good initial value) between the GPIO pin side of the switch and the ground. Also, we can cheat in the software by adding a "timer". This would hinder the code to enter the button-polling part for a given time period (few hundred milliseconds) after the button was pressed which would be sufficient to let the ringing of the button decay. Check your email inbox, you'll get something soon. ;)
@E2ESolutionsDIY
@E2ESolutionsDIY 4 жыл бұрын
Amazing work Dear 👍
@CuriousScientist
@CuriousScientist 4 жыл бұрын
Thank you! Cheers!
@samynwaisser376
@samynwaisser376 3 жыл бұрын
Hallo, thank you for your very good Videos. Cold you write how it is possible to change the 2. code, that the stepper is going after the use of the interrupts a limited distance. I need to run the stepper after the contakt for 15 cm. Thank You.
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Hi and thanks! I won't write the code for you for free because I am not a free support service. Also it is not that simple. You need to know the pitch of the lead screw and the stepper motor's microstepping setup to be able to convert the number of steps to cm. The steps first are converted into angle then the angle can be converted into the linear displacement of the nut.
@johnossi4234
@johnossi4234 3 жыл бұрын
What portion of code would you use to move a SPDT switch to run the stepper back and forth so that I can store two positions - a start point and an end point before the loop runs
@CuriousScientist
@CuriousScientist 3 жыл бұрын
I guess it is a 3-way switch. I would poll it or use an interrupt and move the motor according to the status of the switch. I have examples on stepper motor control based on buttons. Check my stepper motor related playlist.
@kumudayanayanajith6427
@kumudayanayanajith6427 4 жыл бұрын
Amazing work Curious Scientist. Your explanation skills are wonderful. Keep up the good work, I have some questions regarding a project. Is there a way to contact you directly? Thank you ++
@CuriousScientist
@CuriousScientist 4 жыл бұрын
Hi! Thank you for the positive words! It is better to ask the question or give the suggestion here, so others can also learn from it. If you want to go private, I have an Instagram account, you can DM me there.
@lopezborisf6612
@lopezborisf6612 4 жыл бұрын
Hey! Hello friend, I would like to know if this movement system can be replaced by an a4988 driver ... if that is possible, what modifications should be made?
@CuriousScientist
@CuriousScientist 4 жыл бұрын
Hey! The A4988 also has the step (PUL on the TB6600) and direction (DIR on TB6600) pins, so nothing is needed. Maybe, you have to connect the enable pin to high (+3.3 V). All other connection should be similar.
@cantaldo
@cantaldo 3 жыл бұрын
The wiring diagram on your other video has no limit switches. Can you tell us where to download the wiring for this system? Thanks
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Watch the video from 2:44.
@chandrkantjadhav7572
@chandrkantjadhav7572 4 жыл бұрын
Very useful video sir! Can u please provide both code?
@CuriousScientist
@CuriousScientist 4 жыл бұрын
Thanks. Maybe you want to watch the video again and read the description carefully...
@flickmew99
@flickmew99 3 жыл бұрын
this is exactly what I've been looking for, but the worst part is I have no clue about programming atm. And also I'm planning to use Raspberry pi instead of arduino
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Hi! Raspberry Pi is an overkill for this simple task. And the programming part cannot be that difficult since I explain the whole code (which is also freely available on my website) line by line. Enjoy!
@OMCanam
@OMCanam 2 жыл бұрын
Where can we see the limit switch wiring diagram ? On the other video it's mostly for the stepper. Is it supposed to work with standard SPST switch ? I am using two small OMRON V-15G-1C5-K switches and using the code provided it's not always working. Maybe because of the debouncing thingy discussed briefly ? It seems to works better in NC circuit than NO but not always reliable
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Everything is in the code. It is such a primitive circuit that it does not need a diagram. It has a + and - power (typically +5 V) connection, and it has an output that you can connect to any GPIO pins. NC and NO should not play a role as long as you have a pull-up (or pull-down) resistor on the output pin. NC and NO only plays role in the status of the GPIO pin. Also, there's a direct link to the limit switch in the description of the video. Check it.
@alberttrebla6503
@alberttrebla6503 3 жыл бұрын
Hi, thank you for your amazing work ! i'm trying to add the joystick code you used in another video ("multiple stepper motor with joystick...") to this configuration but i'm stucked mixing the flipCheck, Flipdirection and read analog loops, could you advise me ?
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Hi! I am glad that you found it useful. It is relatively simple to merge the two project. But it is unclear for me what you want exactly.
@alberttrebla6503
@alberttrebla6503 3 жыл бұрын
@@CuriousScientist super useful, i' watched your video like 50 times. I'm driving a stepper with a joystick on a signe axis (Y axis), eveything is going smoothly, clockwise, and counterclockwise thanks to your code but i can't integrate the automatic direction change when a limit switch is reached. I can add some code here : here is the part you made for driving the stepper, i took only the Yaxis part (and also the InitialValues part) : void ReadAnalog() { Analog_Y = analogRead(Analog_Y_pin); if(abs(Analog_Y-Analog_Y_AVG)>25) { stepper2.setSpeed(5*(Analog_Y-Analog_Y_AVG)); } else { stepper2.setSpeed(0); } } } and i'm trying to merge it with the part you've made that change the direction and record the previous state : void flipCheck() { if(switchFlipped == true) { //Serial.println(previousFlip); //This was just a control flag for debugging if(previousFlip == true) //If the previous flip is 1, we have positive direction { stepper.setSpeed(1500); } if(previousFlip == false) //If the previous flip is 0, we have negative direction { stepper.setSpeed(-1500); } switchFlipped = false; //We have to reset this, so in the next iteration of the loop, the code will not enter this part, only when there was a click again } } void FlipDirection() { switchFlipped = true; //we change the status to true, so the code will enter the flipCheck() function previousFlip = !previousFlip; //change the state to different from the previous - this controls the direction }
@CuriousScientist
@CuriousScientist 3 жыл бұрын
I am sorry but I am not going to troubleshoot the code for free. You have to read (polling or interrupt) the limit switch and when it gets hit, you have to change the direction. The above code is incomplete. (BTW, do not post large chunks of codes, because KZbin automatically marks them as spam).
@alberttrebla6503
@alberttrebla6503 3 жыл бұрын
@@CuriousScientist yes, of course no problem, i'm gonna keep looking into it. Anyway, thank you for your videos, they are really helpful for beginners like me and sorry for the big code spamming !
@ROCKSTAR-jp2qb
@ROCKSTAR-jp2qb Жыл бұрын
@@CuriousScientist খফহ
@semakzl4524
@semakzl4524 2 жыл бұрын
Thank you your all videos about stepper motor. I wanna ask a question again. Two limit switches are working well in code and I am adding lots of thing into my arduino code but ı wanna move the stepper motor certain distance like your other video. For example stepper motor takes 10 mm in a loop after touching limit switches and stop according to c# with serial port communication (this ditance was calculated relative the step number). I just need to add 10mm run and 1 second stop function. Bu I didnt. pls help me just show me the way.
@CuriousScientist
@CuriousScientist 2 жыл бұрын
I have examples thoroughly explained in multiple videos. Please check my stepper motor related videos more carefully.
@danielikke0691
@danielikke0691 3 жыл бұрын
How I can adjust code for Speed with potentiometer? Thank u and sorry for my eng
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Hi! Read the potmeter with an analog pin. Then, define the upper and lower speed boundaries that you will use and map the minimum and maximum output of the potmeter to these boundaries. Then you just have to update the speed whenever you read the potmeter.
@scrosby1000
@scrosby1000 3 жыл бұрын
This is almost perfect. However I need the same circuit but with 2 buttons. . Any idea how I could use the acceleration library in your code? I'm moving a pool table back and forth so it needs to be very smooth.
@CuriousScientist
@CuriousScientist 3 жыл бұрын
The limit switches are literally buttons, therefore I cannot really understand your issue. The smooth movement only depends on the values you determine for the acceleration and max speed. Or, you can use the runTo...() functions which do not have acceleration implemented and move with a slow speed. However, if you move something heavy, you might need the acceleration. As I said, check my other videos related to stepper motors. I have shared so many solutions, you can easily copy-paste together your own code from my codes.
@scrosby1000
@scrosby1000 3 жыл бұрын
@@CuriousScientist Thanks very much for the reply. The idea I have is to press button one and the pool table will move left until I let go of the button, button two does the opposite of course. I have build you circuit and it works. However your button reverse the motor. I need the buttons to simply activate the motor until released. The pool table is already on rails but moving it by hand jerks the pool balls a tad.
@CuriousScientist
@CuriousScientist 3 жыл бұрын
I answered you in the other comment, there are 2 links. They do the exact thing what you want.
@tomsawyer2160
@tomsawyer2160 Жыл бұрын
Great tutorial. Thanks for the amazing work. I have a question about the first part of your code where you use attatchInterrupt(). Is the first method non-blocking? Can I additionally add a sensor and read values from it while the stepper motor is moving? Thanks.
@CuriousScientist
@CuriousScientist Жыл бұрын
Hi and thanks! Both are non-blocking! :) The only difference is that in one case I used the interrupt, and in another case I poll the inputs. I use the runSpeed() function from the AccelStepper library which is a non-blocking function. This function can be imagined as a person that constantly looks at a stopwatch and it rings a bell when a predefined period of time passes. First, we defined the speed in the code, 1500 steps/second. This means that every 666.7 microseconds (1 s / 1500), a period passes, so our guy has to ring the bell. In "stepper motor language" this means that the code sends out a STEP pulse every 666.7 microseconds to the stepper motor driver. As long as the other task takes less time than this period, you are safe, you can do other stuff, like reading a sensor, sending a message to the computer...etc. If you slow down the motor, you have even more time to perform other tasks, and if you need a faster motor, then you have less time available. So, just keep your eye on the motor's speed and you can see if other tasks can be performed while the motor is not receiving a STEP pulse.
@tomsawyer2160
@tomsawyer2160 Жыл бұрын
​@Curious Scientist Thanks for the explaintion. I tried your code with polling and it works fine. However, when I connect it with my larger program it seems it is slowing down the program whenever stepper motor is moving. I tried to implement your code with attachIntertupt() and I could get it work. My switches are "RISING", do you think changing "FALLING" to "RISING" would be enough or do I have to change something else too? I am using Arduino MKR1000. Thanks.
@CuriousScientist
@CuriousScientist Жыл бұрын
Hi! You said you connect it to your larger program. Are you sure it is the polling that makes the stepper to slow down and not something else? (I just cannot check it right now if the polling should cause any issues). The rising and falling does what they say. So you use the one that is more suitable for your signal change. Low to high is rising, high to low is falling. Nothing else has to be changed.
@tomsawyer2160
@tomsawyer2160 Жыл бұрын
@Curious Scientist Hi, thanks for the prompt reply. The stepper motor is not slow. Actually, it works fine with polling. However, when the stepper motor is working, the software is lagging. So, it becomes unresponsive for a few seconds until the stepper motor stops. I am not sure if it is related to polling or something else, such as DS18B20 temperature sensors. That's why I also wanted to try attachInterrupt() function. I tried attachInterrupt() with rising because whenever my switches are activeted they become 1. However, the behaviour of the stepper motor is weird. It just goes back and forth continuously very fast without switches being activated. If I activate one switch, it will go one way continuously. So that's why I couldn't use attachInterrupt(). I wanted to check if it is the Arduino that makes my software slow or something else.
@tomsawyer2160
@tomsawyer2160 Жыл бұрын
@Curious Scientist I am not sure if it is relevant or not, but I forgot to mention that I am not using a mechanical switch. I am using photoelectric sensors as switches.
@caamtb4109
@caamtb4109 2 ай бұрын
Can this be done with push buttons to simulate the limit switch? I am going to use proximity sensors instead of limit switch
@CuriousScientist
@CuriousScientist 2 ай бұрын
Hi! Sure. A limit switch is just a push button anyway. Anything that causes a change on the GPIO pin can be used.
@havehalkow
@havehalkow Жыл бұрын
Is it possible to add some other methods to the Accelstepper library, like, for example, a goHome method?
@CuriousScientist
@CuriousScientist Жыл бұрын
Sure, you just have to modify the library. But I suggest not to touch the library but write the homing algorithm in your code. It is easier.
@andrewniewiara7614
@andrewniewiara7614 2 жыл бұрын
Andy Niewiara I am using Arduino, stepper motor with Tb6600 driver. I need to move the motor ¼ of a turn, delay it and come back to its original position and delay it. So far I find that the motor with same amount of movement steps will not come back to its original position. Please any help will do
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Hi! Do you use this code? If yes and it does not return to the original position, it is possible that something is wrong with the mechanism (slipping?) or the motor is undersized for the task. You haven't really described how your system looks like.
@Barry4661
@Barry4661 Жыл бұрын
I think the first code is not safe, with flip check it has potential to go the wrong direction as you program the motor just to change direction regardless which limit switch is triggered. In the 2nd code it is better: when limits switch1 is triggered, you program the direction (positive speed) so a bounce is not a problem since the direction is set to always go positive. Or am I missing something? (New to arduino, but my project is very similar to this)
@CuriousScientist
@CuriousScientist Жыл бұрын
It is unsafe if the user makes it unsafe. :) The user has to assemble the system, therefore the user has to be aware of which limit switch goes where. It is the same with the second code, if you physically mix the limit switches, you can end up with erratic behaviour too. For example, you hit the wrong limit switch and the direction does not flip. The "ultimate solution" is that when a limit switch is hit, you just simply read the current speed and then make a command to run the motor with the same speed you just read multiplied by -1, which will flip the direction automatically. In this way, it does not matter which limit switch is located at which end because both switches will flip the direction.
@a_lhimik
@a_lhimik 2 жыл бұрын
Hi, mate! Please help with the AccelStep library. I am using TB6000 driver. I need the motor stepper to move left and right automatically and there is a limit switch insurance, so that if the motor suddenly goes further, the button will return it in the opposite direction! All codes work like this but not together
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Hi! I have several videos on this topic, so please take your time and look around on my channel. I am pretty sure that you'll find what you need.
@sarljlformatik3293
@sarljlformatik3293 2 жыл бұрын
Hi, first thanks you for your work, and sorry for my english, i'm trying to do this ping pong move with delay before restart to the other direction, it's OK, but now i wolud like to implement acceleration when the moves restart, i know i should use stepper.run() instead of stepper.runSpeed() but after reading accelstepper library, i cannot figure out how do to... Maybe you could show me the way ? To illustrate, i'm making cabble car, so i dont know how many step i have from 1 side to other side, and it car vary (slipering, lenght of cabble, etc...) so i cant use the move() or moveTo() command... i'm lost...
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Hi! Your English is good, I understood everything perfectly. When you go from A → B, you can move the motor normally. After the limit switch is triggered at B, add a delay, then put the stepper.run() in a while where the condition is the state of the limit switch at A. So, the stepper motor will be moved from B →A in a while() loop using the stepper.run(), therefore, there will be acceleration. When the A switch is triggered, stop the motor.
@charliebanger
@charliebanger 3 жыл бұрын
Amazing! I have project to do, in which I am stuck in between, I want your help.
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Thanks! Ask the question here in the comments, so others can also learn from it. If it is simple enough, I can try to answer it. If it is complex, I am sorry, but I won't do it for free.
@charliebanger
@charliebanger 3 жыл бұрын
@@CuriousScientist Yes, why you will do it for free, by the way you would spend your precious time. I am ready to pay. But I want it very soon. Please reply me.
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Hi! You can always reach out to me on Instagram or via email. Go to my website (link in the description), go to the contact menu and you'll find a way to send an email to me.
@charliebanger
@charliebanger 3 жыл бұрын
@@CuriousScientist I have mailed you Sir. I am waiting for reply.
@alvintureDM
@alvintureDM Жыл бұрын
Good day Sir @CuriousScientist thanks for sharing this great vlog of yours, I am starting to learn coding in arduino, can you please tell me where can I insert the 2nd code for the 2nd stepper motor if I will setup 2 stepper motor with 2 limit switch each. Am I right that I just need to copy your whole code for the first stepper motor and paste it at the bottom and edit the pin numbers and rename the 2nd stepper motor? Your response will be very much appreciated. Thank you very much.
@CuriousScientist
@CuriousScientist Жыл бұрын
Hi! I have several videos with multiple stepper motors. Here is one example: kzbin.info/www/bejne/jpeWaquYpNV0fK8 Check it and you can see how to control two motors.
@alvintureDM
@alvintureDM Жыл бұрын
@@CuriousScientist Thank you very much Sir.
@CuriousScientist
@CuriousScientist Жыл бұрын
You're welcome!
@piotrs5616
@piotrs5616 3 жыл бұрын
Hello Very nice !!!! I Designs a similar device. I watched your KZbin video and website and it is an interesting solution. In my device, I have to hold the bed for a while. the bed goes to homing then goes the other way when it reaches endstop stops for 5 seconds and goes back to zero. I am a poor programmer trying to solve it, but after a few hours I gave up. Can you tell me what to add in the code to make it work like that? Thank you very much for help.
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Hi and thank you for your comment. The easiest solution is to add a delay to the code when you switch directions. So after the limit switch is pressed, you add a 5 second delay, then you continue the movement. This extremely simple.
@piotrs5616
@piotrs5616 3 жыл бұрын
cool I just don't know where, as I wrote, I don't quite get the coding and it will be very helpful in which line Piotr Strzelecki
@CuriousScientist
@CuriousScientist 3 жыл бұрын
@@piotrs5616 Please just watch the video from 9:40. I explain the code line by line. Based on that and my comment above, it is really easy to put everything together. That's why I spend so much time on explaining the code line by line so anyone can understand it. Pay attention to the flipCheck() function. :)
@hxi7202
@hxi7202 2 жыл бұрын
Is it possible to only use accel stepper library to move back and forth continuosly/repeatedly without the limit switches?
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Of course. I have several video examples on it. Check my stepper motor related playlist.
@hxi7202
@hxi7202 2 жыл бұрын
@@CuriousScientist Hey sorry. do you know which specific video it is, I cannot identify it
@hxi7202
@hxi7202 2 жыл бұрын
@@CuriousScientist trying to make it run continuosly with just a press of a button, just by using accelstepper library
@CuriousScientist
@CuriousScientist 2 жыл бұрын
kzbin.info/www/bejne/hpzQgaCtqZ13mKM
@5b_yogiprasetyoatokillah850
@5b_yogiprasetyoatokillah850 Жыл бұрын
Hallo, Mr. Thanks for you. But i have some problem in my project. Previously I tried on my stepper motor. it went well. and after 3 trials. limit switch not working. and the motor won't go back and forth. may i know what is the cause?. Thank you Mr.
@5b_yogiprasetyoatokillah850
@5b_yogiprasetyoatokillah850 Жыл бұрын
My name's Yogi. I'm from Indonesia student. now I'm working on my thesis. and I know about this video from my supervisor in college. please help sir. Thank You 21:41
@CuriousScientist
@CuriousScientist Жыл бұрын
Hi! Check the wiring. I can not troubleshoot your system without seeing it, sorry.
@5b_yogiprasetyoatokillah850
@5b_yogiprasetyoatokillah850 Жыл бұрын
​@@CuriousScientistokey sir. I'll check it and try. Thankyou verry much🙏
@5b_yogiprasetyoatokillah850
@5b_yogiprasetyoatokillah850 Жыл бұрын
​@@CuriousScientistThank you sir. the program is running smoothly. my first time using Arduino Mega. and now I change to Uno it runs smoothly
@CuriousScientist
@CuriousScientist Жыл бұрын
Good news, thanks for the update!
@user-hn4tg2su4d
@user-hn4tg2su4d 2 жыл бұрын
I installed the library fine, but unfortunately it did not work, can you help me solve the problem, thank you very much
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Hi! You haven't provided any information other than it is not working. I can't even guess what can be wrong. Also, I am not a free support service.
@petercohen8877
@petercohen8877 2 ай бұрын
Hello, although the motor changed direction when I pressed the switch with my finger (worked in several tests), it did not do that after I installed the switch to the setup and restarted the program. The LED of the switch circuit board was On once pressed and continued to be On when the platform continued to press against the switch but the motor just did not change direction. Tried a few times already. Have you found a good way to make it works 100% of the time?
@CuriousScientist
@CuriousScientist 2 ай бұрын
Hi! Have you watched the video or you just copied my code and used it without any thinking? I even mentioned in the video that the limit switches can bounce (send a burst of signals) which can confuse the code and the motor could continue going in the same way even after hitting a limit switch. You need to debounce the limit switches if you want something reliable.
@petercohen8877
@petercohen8877 2 ай бұрын
@@CuriousScientist I have watched your video several times. You mentioned a few times that the switch does not work all the time and perhaps we could look for something better. It has been 3 years since you made that video so I wonder if you have found a better switch or other method that would guarantee that it would work 100% of the time.
@CuriousScientist
@CuriousScientist 2 ай бұрын
I just wrote it. You need to debounce the switch.
@franz-juergendreis2913
@franz-juergendreis2913 3 жыл бұрын
Another great project of yours. But what I notice is that you rarely show circuit diagrams and detailed pictures of the cabling of your projects. It would be nice if you could send me the circuit diagram of how you wired the endstops by email or WhatsApp. I have a lot of sensors and switches and LCD to accommodate, so it gets quite tight on the Arduino Uno. I am now 65 years old and I am just starting out with the Arduino projects. Had nothing to do with electrics and electronics before. I would like to include your project to wind a pickup winder for electric guitar and electric bass. The spindle is driven by a toothed belt via a direct current motor. Using a Hall sensor, each time the DC motor makes one turn, the upper wire guide slide should be moved by one wire thickness until the end of the coil is reached. Then the direction of rotation should be changed and the whole thing goes in the opposite direction. The wire thickness, the coil width and its inner and outer diameter should be selected or entered via a menu. The number of turns per layer, the number of layers, the total turns, and possibly the total resistance should be calculated and processed accordingly in the loop sector. The menu is selected using an incremental encoder with a switch. Display is via Nokia LCD 5110. It would be great if you could help me and send me a circuit diagram (hand sketch is enough!) Of the wiring of the end stops. I will use Limit switches with the PIN's COM CN and NO.
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Hi! Thank you for your comment. The cabling is always at least explained verbally, and I also write down the connections as subtitles. Also, if you visit my website, you can see, that majority of the projects have the schematics included in the posts. If you read the other comments, I already instructed someone else to check the video at 2:44. If you watch the video carefully, I say how the limit switches are connected. Also, if you check the source code, it is literally written in the source code. There is no need for schematics for that, I think. You can also pause the video and check where the wires go. If you still cannot get it from these 3 different sources, then it is the following: VCC: red, GND: black, signal: green. Then it depends on you where to connect the signal. If you use polling, it goes with any digital pins, if you use interrupt, you have to use pin 2 or 3. In fact you can use the same pin (i.e. 2) for both switches at the same time because they are not triggered at the same time. This reduces the number of necessary pins on the Arduino. Most of my videos take at least one full day of work , but sometimes I spend weeks to research everything, test everything...etc. I buy all the stuff, build it, write the software, record the whole explanation, cut the video, upload it...etc. For free. I am actually "losing money" by making these videos. With all respect, people should at least spend that 30-60 minutes of time and watch and read everything carefully that I provide. I am not a service provider, I have a full time job and this is just my hobby that I share with other people. For some reason, many people automatically assume that I also provide support for the shared projects and serve them for free. (this last chapter was more like a "general venting" and not directed only towards you)
@salermo42
@salermo42 3 жыл бұрын
I made a similar device according to this sketch with interrupts, but I noticed one problem. If the moving part has activated the first switch and then the power is switched off, after switching on the pressed switch is ignored and the motor tries to continue moving in the same direction. Can make a correction that this is not happening? I use hall sensors as limit switches, and while the moving part between the limit switches everything works ok. TIA
@CuriousScientist
@CuriousScientist 3 жыл бұрын
If you only turn off the stepper motor driver with the limit switch and not doing anything within the code, the code is still running on the MCU. You need to handle everything inside the MCU.
@salermo42
@salermo42 3 жыл бұрын
​@@CuriousScientist Thanks or Your quick response. I power from one 12v source all. When the power is off, everything is turned off. The program starts from the beginning, but if the first switch is active at that moment, program does not register it and tries to move the moving part towards it, but is actually moving away from it, or trying to move away... I will put it on YT short video to see this situation better. YT links: kzbin.info/www/bejne/m4abpad-mZ2daZo kzbin.info/www/bejne/jnekop6kesierqM I don't have enough experience in programming to be able to modify a program to check status of the switch after plugging device into a power source. I started learning about arduino 15 -20 ago. That is why I asked if this situation could be prevented in this sketch. The only thing I was able to do was add a little pause when the moving part reached the switches in this sketch. A sudden power failure can cause the moving part to be on the switch at that point and then this problem occurs when power is back on.
@CuriousScientist
@CuriousScientist 3 жыл бұрын
Thanks for providing the videos, it is much more easy to answer the questions if I see what is wrong! So, I understand the problem, and I think it can be solved. First of all, I think the problem stems from the fact that you are using the interrupt-based code. The interrupt is looking for a falling edge from the limit switch. If you turn everything off and power up again, there is no falling edge detected because the limit switch was already in a certain state (pressed) when you restarted/powered up the circuit at the limit switch pressed state. Therefore, the code automatically assumes that the limit switch was not triggered and it goes with the default code which is the positive direction. This is why you see it going past the position of the limit switch. What I would do, at each startup, in the setup() part, I would first check if any of the limit switches are pressed in. If one of them is pressed in, then I would move the motor slowly until the press is released, and then I would let the loop() run normally. So basically it is just two while loop. The algorithm is something like while(limit1 == true) {move negative} - this is to release the switch which is pressed if you go in the positive direction. The negative is similar: while(limit2 == true) {move positive}. Also, this code has to be done before you introduce the attachInterrupt() in the setup() part of the code, so the interrupt routine will not interfere with this part.
@salermo42
@salermo42 3 жыл бұрын
@@CuriousScientist Yes, I saw in the program that it was defined to which edge it would react, I know I can't change that. I will try to add those lines, but my knowledge of sytax is still close to zero. :) If you change, I'll be happy to try, the device is ready and waiting. The only thing that came to my mind was that I might know how to add to first take a few steps in the opposite direction In the beginning, reverse direction and then continue as you wrote sketch. But this is not that good solution. I didn't use this second example with polling because I couldn't add pauses when the limit switch came up. The program would not run further when any switch is reached. He would just stop.
@CuriousScientist
@CuriousScientist 3 жыл бұрын
I might make a new version of this video with an updated code which tackles the above described issue. I cannot promise a finish date for it, but I put this issue on my to-do list, so it will be done sooner or later.
@45Concealed1911
@45Concealed1911 Жыл бұрын
I would like to make use of this code, but only have standard NC limit switches, what changes would i need to make to enable use of these?
@CuriousScientist
@CuriousScientist Жыл бұрын
Hi! NC or NO switches, it does not matter because you can always program the response for their status change in the microcontroller. NO: Normally open, so when you hit the switch the pin goes from 0 to 1. NC is the opposite, it goes from 1 to 0 when the switch is hit. You have to change the code accordingly.
@45Concealed1911
@45Concealed1911 Жыл бұрын
@@CuriousScientist thanks, this is my first real attempt at a project so i am unsure of where and what i would change in the code. Im starting to understand, nut have a ways to go
@CuriousScientist
@CuriousScientist Жыл бұрын
Maybe it is too big as a first project. Try to break it down into smaller pieces. First, try to understand how a switch behaves, then try to add the motor, then another switch. Step by step.
@45Concealed1911
@45Concealed1911 Жыл бұрын
@@CuriousScientist okay, i have the motor running, working on one switch, but all i can get it to do is pause the motor, not reverse it. My switch is only 2 wire, so i can only switch on/off not switch from + to -
@CuriousScientist
@CuriousScientist Жыл бұрын
You have to add the "third wire" yourself. You might want to read about pull-up and pull-down resistors and you'll understand how you should wire the switches.
@abrampl
@abrampl 6 ай бұрын
Jupi! I found what I need :D anyway, just use switches with reversed shmit trigger as a real thing which change state from 0 to 1 ;) what I mean is do not use software loop for check state change at pin input :D whatever
@CuriousScientist
@CuriousScientist 6 ай бұрын
No need for Schmitt trigger here because microcontrollers typically have ST inputs anyway. The 0 or 1 doesn't matter because you can handle it with software, or you can choose a pull-up, or pull-down schematic for the switches. Loop is also fine because the movements are slow, so it is enough to poll the switches. Furthermore, I also showed the interrupt method, so it is up to the user what to do.
@keshavkushwah4750
@keshavkushwah4750 2 жыл бұрын
Hi please help me to make a code for DMX stapper motor with limit switch please help me
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Hi! There are plenty of videos and freely available source codes on my KZbin channel. Watch them and learn!
@ArjunRG97
@ArjunRG97 2 жыл бұрын
What is the wiring scheme for the limit switches?
@CuriousScientist
@CuriousScientist 2 жыл бұрын
There's really no need for that because it is just so easy: they have the positive and negative voltage supply pins and the output pin. The pins of the Arduino that communicate with the switches is in the code.
@ArjunRG97
@ArjunRG97 2 жыл бұрын
@@CuriousScientist ok thank you. I'm looking at limit switches with Common, NC and NO pins rather than these PCB mounted micro-switches, so I ran into some confusion. I suppose a 2 pin connection with Common connected to 5V and NC connected to the interrupt digital pin should suffice, with no need for a pull up resistor anywhere. If you can correct any errors in my conclusion, I would be grateful.
@CuriousScientist
@CuriousScientist 2 жыл бұрын
I would always add a pull up resistor for a switch. A floating pin can cause a very funny behaviour. Maybe you can also add a capacitor. Switches should ideally be debounced.
@gadhiyabhavesh2779
@gadhiyabhavesh2779 2 жыл бұрын
I want to buy this project
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Hi! Why would you buy it? I made all the resources available on my website.
@gadhiyabhavesh2779
@gadhiyabhavesh2779 2 жыл бұрын
I dont know cordind and how to place pcb order pcb .etc
@napkin62
@napkin62 2 жыл бұрын
my very dear friend pls . i do not understand what is new to say bcze every body ask same but dear if possible provide images of circuit digram of connection with hardware ...may for every one or may be for me in email...but i know it is not possible but you take your own nobel decision as im doing same kind of project where ping pong works to safe my steeper motor ...pls sir help me one time no one after you can help me...
@CuriousScientist
@CuriousScientist 2 жыл бұрын
Hi! I have plenty of videos where I explain how to connect everything together. Please take your time and look around on my channel. You will find it. Also, all the connections are listed in the source code, you just have to read it.
@saeidkasraeian190
@saeidkasraeian190 2 жыл бұрын
hi. have you find the wiring diagram ? if not l can send you.
@saeidkasraeian190
@saeidkasraeian190 2 жыл бұрын
PUL+ , DIR+ , EN+ goes to 5volt PUL- Pin8 DIR- Pin9 EN- Pin1 limitSwitch1 Pin2 and other end to GND limitSwitch2 Pin3 and other end to GND
Homing with the AccelStepper library and a limit switch
17:09
Curious Scientist
Рет қаралды 61 М.
Big Stepper Motors with Arduino
29:43
DroneBot Workshop
Рет қаралды 1,2 МЛН
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 38 МЛН
Finger Heart - Fancy Refill (Inside Out Animation)
00:30
FASH
Рет қаралды 28 МЛН
ОБЯЗАТЕЛЬНО СОВЕРШАЙТЕ ДОБРО!❤❤❤
00:45
Chapitosiki
Рет қаралды 4,9 МЛН
Multiple stepper motors with joystick, TB6600 and the accelstepper library
33:04
Top Fifteen Mistakes People Make When Designing Prototype PCBs
12:26
Cosplay Light and Sound
Рет қаралды 141 М.
Updates for the AccelStepper library - TB6600 and Arduino
39:58
Curious Scientist
Рет қаралды 26 М.
Stepper Motors and Arduino - The Ultimate Guide
29:57
How To Mechatronics
Рет қаралды 1,1 МЛН
Control a Stepper Motor with Hall Effect Switches
28:13
DroneBot Workshop
Рет қаралды 241 М.
Mechanical  Switches are Obsolete?! Switch to a Latch Circuit! EB#53
10:36
Beginners Guide To Using Large Stepper Motors: #087
19:49
Jeremy Fielding
Рет қаралды 286 М.
Limit Switches and E-Stops, The Ultimate Guide
31:16
BuildYourCNC
Рет қаралды 25 М.
Запрещенный Гаджет для Авто с aliexpress 2
0:50
Тимур Сидельников
Рет қаралды 955 М.