I am trying to make a device which will turn a turn key with a servo.

However, I want it to stop turning the turn key if the resistance is too great (meaning it is locked and will not ever turn).

How do I do this? Would I just tell it to turn and then have it turn back after a time (because if it is locked or not it should be done within that time)?

I do not want to damage my servo by having it try to turn something that it can't turn.

I am using an Arduino Uno and the library "Servo.h". The servo being used is a Batan S1123.

4 Answers 4


It depends on what kind of failure you expect. If you're afraid the motor may break your linkage (the gears, cranks, belts, whatever you have in place), you have to react very fast, and it's only feasible with a current measurement. That would require sensing the current and reacting very quickly on over-current to be effective.

If you know for a fact that your linkage can withstand the stall torque of the motor, you just have to worry about overheating the motor. Such a protection can be done with a position sensor or a limit switch if you happen to have one. You could even implement a protection with no sensors at all: drive the motor for just long enough to do its job and then stop: either it will turn the key or it won't, but it won't overheat if stalled for a second or two.


You could either:

  1. Use a limit-switch to sense that the servo has completed it move. If it doesn't complete it a reasonable time, return it to its original position. Or,

  2. Measure the motor current by putting a low value resistor inline with the ground side of the motor's power supply. With one of the A/D pins, measure the voltage on the motor side of the resistor, which increases with motor current. You'll need to have figured out how much current the motor draws when operating normally. If the motor stalls, your controller could sense that by seeing that current increase. Pick a value (try 150%, for example) of over-current as an indicator that the motor is stalled, and return it to its original position.

The first way is easier to implement but possibly lets the motor stall while you wait for the expected move time to expire. The second way lets you detect stalling and take action immediately.

  • I don't think the limit switch solution would prevent the servo from stripping its gears if it binds before you check the switch. Option 2 would be the better avenue to explore.
    – linhartr22
    Commented Jan 17, 2019 at 17:26
  • You should understand that you control the servo with PWM pulses. The servo translates the width of the pulse to an amount of rotation. A standard servo has no means of indicating its current position. You can only tell it where you want it to be.
    – linhartr22
    Commented Jan 17, 2019 at 17:32
  • If it could strip gears, it's under-built; it shouldn't be able to damage itself under forseeable circumstances (stalling). But even then, current-sensing should give you sufficient opportunity to protect it.
    – JRobert
    Commented Jan 18, 2019 at 21:36
  • "If it could strip gears, it's under-built" - this is usually true for toys and small applications (so it's likely the OP's case as well), but not true in general. Most products where a motor is not designed to work at 0RPM (mixers, etc.) will happily strip gears when stalled, unless they have protection implemented in software. Commented Jan 21, 2019 at 13:40

The best way is use external feedback. Hall sensor for example. 200-250ms after using servo check status of hall sensor

  • Or a current sensor on the Servo power line, back off the position when you detect the current rising from the motor being stalled.
    – CrossRoads
    Commented Jan 14, 2019 at 18:23
  • Yes, that's possible. Hall seems easier
    – Pararera
    Commented Jan 14, 2019 at 18:40
  • Could you expand on how you would use a hall sensor to complete this task?
    – mikeY
    Commented Jan 14, 2019 at 20:26
  • Put little magnet on key and hall sensor near end point of key.
    – Pararera
    Commented Jan 15, 2019 at 5:16
  • Ah. So if sensor fails to detect magnet x moments after servo push has started, resistance has been encountered, stop pushing.
    – mikeY
    Commented Jan 15, 2019 at 20:04

I suggest detecting the current flowing through the servo or using a potentiometer to detect whether the servo is moving. You could also put a clutch between the servo and the key, but then you wouldn't know the angle of the key at any given time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.