How to read manually set Servo angle


I know that you can read a current angle of a servo motor using
I wonder if it would be possible to:

  1. You turn the servo motor
  2. You read the new angle.

I did some test and you can’t turn a servo while it’s “attached”. However even if you detached and turned the servo, the servo will come back to its place where it was left just before it was detached. I will give an example to make it clear.

The servo is attached and set to 0 degrees. You detach it(my_servo.detach()) and turn it to 180 degrees. You reattach it(my_servo.attach(servo_pin)) and hope that it will read 180 degrees. However what happens is that the servo turns to 0 degrees before anything happens, and then it will read 0 degree.

Here’s the test code I wrote:

#include <Servo.h>

const int servo_pin = 6;
Servo servo;

void setup(){

void loop(){

So does anyone have any idea how I could read a manually set servo angle?
Thanks in advance :slight_smile:

I wonder if it would be possible to:

  1. You turn the servo motor
  2. You read the new angle.

NO. is a rather pointless feature that tells you the number that you last sent with Servo.write() - and which you knew already.

Normal servos don't provide any feedback although you can get some that have an extra wire that allows the Arduino to measure the voltage (position) of the internal potentiometer. I can't recall if Sparkfun or someone like that sells them.


Thank you Robin for your reply. I will use a stepper motor with magnet sensor instead :slight_smile:

Being able to get the last position command sent to a servo is useful if the servo is making incremental moves. Below the servo command position is recorded when the paper clip comes in contact with the aluminum foil.