Here I want to show how to send a steer motor commands, so it turns for a given amount of degrees in one direction. For this I use the 28BYJ-48 stepper and the ULN2003 controller. Both are available for under 5€.
I've made a scale, so I can see when the stepper is active.
It is a unipolar 5V stepper motor, which can due to the controller also be driven by 12V. Such steppers are in common use in smaller devices. If you want to built a little driving robot, this stepper could be a good solution.
After the motors output there is a gearbox. It's transmission should have a ratio of 64:1, but in reality it's 63.68395:1. The torque is for this size really good, and the maximum number of revolution per minute is about 15.
The motor is driven by 4 coils, whichs are activated in a different order, so the motor turns. In the datasheet you can see that you can run it with half-step-method. What here happens you can see in the table below.
Due to the half-step-sequence you have 8 different conditions. This allows a better positioning with a higher torque. I use exactly that in my code in the function setStepper().
Thanks to the small ULN2003 controller the motor can be used on any 5V-microcontroller. I use it on the Arduino Uno or Nano. On the circuit board you can see 4 LEDs. The show which coil is currently active. Furthermore there is an on/off jumper on is. If you want to activte the motor by software, this could be done here with an optocoupler or a relais.
The controller should be supplied with an external power supply. Therefor you can use one with 5V or 12V and 1A on the supply pins. It should not be supplied with the +5V pin from the Arduino because the stepper needs a huge amount of power. When you supply it the ground pin must be the same on the power supply, the motor controller and the Arduino.
I recommend to supply the Arduino on its Vin pin and the motor controller with +12V from the same battery (or any other power supply). So you can use everything with ony one supply.
There are four signal pins on the ULN2003 (IN1, IN2, IN3, IN4). They are used to control the motor.
I have connected them in the following order with the Arduino:
You can change them or set them to any pin you want, just make sure you also change them in the code.
As always: GitHub.
In Set_One_Stepper.ino you can send the Arduino the amount of steps the motors shall turn via the serial montor. You can send positive and negative numbers, so the motor turns positive or negative.
You can determine if the sent number is interpreted as steps or as degrees. One step is not one degree! Here math kicks in:
- One full step (all 8 cycles) results in 5.625° on the output of the motor.
- So one round on the gearbox's input are 64 volle Steps.
- The ratio of the gearbox was 63.68395:1, that means: 4076 steps for one round on the output of the gearbox.
- Now you have the recalculate the steps to full steps. So you get 509.5 full steps per revolution on the output.
- So one degree on the gearbox output are 1.4153 steps.
boolean rotateInDeg = true;
Is the above shown variable set to true the number value from the serial monitor is recalculated to degrees. If you send e.g. 360 as number the motor turns one full round.
int delaySteps = 1000;
The delay is responsible for the speed. The smaller it is the faster turns the motor. 1000 microsseconds are the shortest pause, if you go lower the motor wont work propperly, because the inertia of mass is too high for the changig of active coils.
The "turning" is due to the changing activity of the coils. In setStepper() do exactly that with the help of the table from above.
Unfortunately one degree are 1.4153 full steps. That way you will get an error of rounding when you turn the stepper. If you want to turn the stepper 360 degrees you have to run 509.5 full steps. Your stepper can't go a half step. This error could be solved when you add an abort condition in the for loop. But then you have to remember where it stopped, and start from that point again.
If you want to use two steppers just open the file Set_Two_Stepper.ino. Here the function setStepper() contains the second stepper as well.
I haven't seen it in ordinary libraries, that you can really use two steppers at the same time. There one steppers runs only when the other is not. That results in a choppy behavior.
If you do it my way you can actually use two steppers together at the same time.
Both programs that I have shown above are "dumb". You cannot set the scales needle to a certain point on the scale. If you want to a point you have to go there via + or - and a number value via the serial monitor.
Goto_Position.ino does this for you. In the serial monitor you just have to send the target position and the needle will turn as long until it's destination has been arrived. Note that you can now only send a degree-value in the range of 0 to 359.
At the program start the current position will be set to zero. Is the needle on any other point it isn't correct.
Questions and comments: deloarts.wordpress.com