# Controlling Stepper or DC motor with L298 or L293 and getting operation similar to Servo for 6 dof arm

I will be using 1:4 gear ratio and thus will require a motor with a continuous 360 motion and a high torque for efficient functioning. Servo motors with continuous rotation and high torque are very expensive and rare, so my choice has boiled down to DC Motor and stepper motor. However I have not completely understood the way to configure them for a robotic arm. I don't want to use rotary encoders, as installing a potentiometer or hall effect sensor on the shaft will be cumbersome and inaccurate due to vibration. Is there a way one could move a DC motor or stepper motor to a particular angle with IC/modules like l293d or other motor drivers?

• You can't possibly control the shaft angle for a DC motor (unless they are equipped with rotary encoders), that too for a precise operation like a robotic arm. Yes, stepper motors can be used with micro-stepping to get a desired arm angle. Using a stepper motor driver would be more efficient instead of an H-bridge driver like this as pointed out here. – Kartik Madhira Aug 5 '18 at 17:37
• If there is enough force on the arm to prevent a stepper motor from moving, the controller will think the arm is in a different position than it is in reality. Without some form of feedback, the controller will have bad ideas about the angles. Not all the time, but perhaps enough that problems will occur. With steppers, a limit switch on either end of the position might be enough. Though I think a rotary encoder would take less room. – NomadMaker Aug 5 '18 at 20:20
• Can’t you install an optical rotary encoder on the DC or stepper motor shaft? – SteveO Aug 6 '18 at 1:06
• I don't mean to be rude, but why do you think that a rotary encoder would be inaccurate due to vibration? I've found that a properly installed encoder is very sturdy. – NomadMaker Aug 6 '18 at 9:54
• @NomadMaker According to me there are two problems with rotary encoders , I will be using Raspberry Pi so ADC circuit would be involved and I would have to change the design of the robotic arm to accommodate the rotary encoder to make the installation sturdy enough. – Sam Aug 6 '18 at 11:17

You can't control shaft angle of the DC motor without any feedback from it. Servos made for RC models or robots just do the thing - they utilize a potentiometer or rotary encoder to measure shaft angle and control it, mostly with PID regulator.

You can utilize stepper motor for Your task, as these motors are mainly used in the angular manner of control. For that, better than L293D will be dedicated stepper motor driver, like A4988 or DRV8825 (I don't know how large Your robotic arm will be, so these are just example drivers).

If You will choose DC motor over the stepper motor, mind that servos' mechanisms have much higher gear ratio than 1:4 in order to gain torque from a small DC motor.

EDIT: There is also a problem with holding the position of the stepper motor, common in CNC machines, 3D printers etc. Stepper motors can move (almost) freely, when there is no holding current applied. Therefore, when a machine is turned on, every motor has to find its origin. It is usually done by placing a switch on the minimum or the maximum position of the joint. The process of finding origin of the machine is called Homing.

Check out here how it is done by a 3D printer- You can see here a movement of the axis towards the switch. When the switch is hit, it is recognized by the software as reaching the minimum of the axis, thus zeroing joint's position.

Moreover, there is also a way of sensorless homing by measurement stepper motor current draw. For example, TMC2208 (and also TMC2130 and TMC2100) stepper motor drivers are capable of doing that. When the joint mechanically reaches its constraint, the driver knows it by measuring, that the motor is drawing more current than normally. It also sets diag1 pin to high (if it is properly configured), allowing external electronics to detect machine's home position.

These drivers are also very silent and give smoother motor movement in comparison with previously mentioned ones. You can check the difference in sound here.

• I have doubt regarding this .( using stepper motor driver) For example , I move the stepper motor shaft to 30 degree and now I input angle 60 degrees the stepper motor would move by 90 from the initial position according to me . So to correct this I would have to alter the code and save the earlier position and subtract it right ? – Sam Aug 6 '18 at 11:19
• I updated my answer according to Your comment. – Szczepan Aug 6 '18 at 12:37
• You said "Stepper motors can move (almost) freely, when there is no holding current applied" . Does this mean that when the robotic arm is stationary it has no strength ? – Sam Aug 6 '18 at 18:50
• No. When the robot is turned off (and stepper motor drivers too) it can move almost freely. Turning on the drivers and setting them as active (on the example drivers above EN set to high) makes the motors hold themselves with the holding current applied by the drivers. However, remember, that when You'll pass the holding/moving torque limit, your stepper motor will lose steps. You can read more about losing steps here. – Szczepan Aug 7 '18 at 6:46
• Could you please clarify the " turning on the drivers and setting them high " part ? – Sam Sep 9 '18 at 5:10

You can't do position control without position feedback.

You need position feedback. Your comments regarding why you're not going to use position feedback ("cumbersome and inaccurate due to vibration") are totally inaccurate. There is no vibration unless you don't mount the equipment correctly. It's not any more cumbersome than anything else.

If you want to do position control, you're going to put a position sensor somewhere.

How well you want to do position control, how accurate you want it to be, how long you want the startup/homing routine to be, those are all questions for you the designer to answer. Being lazy now and choosing to slap a limit switch on because you can't be bothered to actually look at rotary encoders means you get to wonder for the life of your robot arm whether the arm is actually in the position you think it is.

"Isn't there a way one could move a DC motor or stepper motor to a particular angle with IC/modules like l293d or other motor drivers."

You can command an incremental position change. You cannot verify the final position.

• Thank you for the detailed answer. But if I use Rotary Encoders where would I fit the gears ? And if I use potentiometer as rotary encoder can I use it to sense angles more than 360 as I would be using 1:4 gear ratio . – Sam Aug 6 '18 at 18:55
• @Sam - Does the arm actually move continuously, or just 0-360? You can put the encoder on the arm and not the motor, if you want. Also, does the motor actually rotate continuously, or just 0-(4*360)? You can also get multi-turn potentiometers. You could attach an encoder to a wheel and have that "ride" on the motor shaft or arm cuff, but they also make encoders that are designed to fit over shafts. Or you could also just buy a motor that comes with an encoder. – Chuck Aug 6 '18 at 19:24
• Is Homing possible with encoders particularly with motors that come with an encoder ? – Sam Aug 7 '18 at 15:18
• @Sam Homing is just a procedure where you try to locate a particular position (the "home" position). Most incremental encoders will have a reference index you can use to home. You can also do homing with an external signal, like a limit switch, but you won't know what the current arm angle is without an encoder. You should check the data sheet for the motor and look specifically for an "index" position or Z signal. – Chuck Aug 7 '18 at 16:15
• The motors that come pre installed with encoders .How can I use their encoders ? And do I need to buy Driver module for these motors ? – Sam Aug 9 '18 at 6:29