Projects / Servo pulse width reader

Servo pulse width reader

Intermediate1.2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. NANO59°

    Wire board A

    Servo on D9, knob on A0.

  2. NANO59°

    Upload the first sketch to board A

    The servo follows the knob.

  3. NANO

    Join the signal wire and the grounds

    Board A D9 to board B D2, and GND to GND.

  4. NANO

    Upload the second sketch to board B

    Open the serial monitor at 9600.

  5. NANO59°

    Turn the knob slowly

    The width climbs from about 1000 to 2000 microseconds.

  6. NANO

    Compare pulse width with angle

    Write down five points.

  7. NANO59°

    Try a second servo

    Note its range.

In short

How do you build a servo pulse width reader?

One Nano drives a servo from a knob while a second Nano listens on the same signal wire and prints the width of each pulse in microseconds. You see that an RC servo is just a one to two millisecond pulse repeated fifty times a second. You need Arduino Nano × 2, SG90 Micro Servo, Potentiometer 10 kΩ, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 70 minutes.

Level
Intermediate
Time
About 70 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Board A: servo signal (orange)Board A D9The pulse to the servo
Board A: servo redBoard A 5VServo power, a small servo only
Board A: servo brownBoard A GNDCommon ground
Board A: pot outer legsBoard A 5V and GNDKnob supply
Board A: pot middle legBoard A A0Angle setting
Board A D9Board B D2The same pulse goes to the reader
Board A GNDBoard B GNDShared ground

Code

An RC servo does not understand angles. It receives a short pulse about fifty times a second, and the length of that pulse sets the angle: about one millisecond for one end, about one and a half for the middle and about two for the other end. The file holds two sketches for two Nanos. Board A reads a knob and turns the servo, and board B shares the signal wire and a ground, and uses pulseIn to measure how long each pulse stays high. Turn the knob and watch the width climb from about 1000 to about 2000 microseconds. Use only a small servo with light movements from the Nano's 5 volts, because a stalled or heavily loaded servo can drag the supply down and reset the board. Both boards must share a ground, or the reader sees nothing. Compare the angle guess with the real angle, and try other servos, because their ranges differ a little.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

// ===== BOARD A: drives the servo from a knob =====
#include <Servo.h>
Servo servo;

void setup() {
  servo.attach(9);
}

void loop() {
  int angle = map(analogRead(A0), 0, 1023, 0, 180);
  servo.write(angle);
  delay(20);
}

/* ===== BOARD B: reads the pulse width (a separate sketch) =====
   Copy everything below into a new sketch for the second board. */
/*
const uint8_t PULSE_PIN = 2;

void setup() {
  pinMode(PULSE_PIN, INPUT);
  Serial.begin(9600);
  Serial.println("pulse (us)   angle guess");
}

void loop() {
  unsigned long us = pulseIn(PULSE_PIN, HIGH, 30000);   // length of the high pulse
  if (us > 0) {
    long angle = map((long)us, 1000, 2000, 0, 180);     // about 1 ms to 2 ms
    Serial.print(us);
    Serial.print("          ");
    Serial.println(angle);
  }
  delay(200);
}
*/

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Knob at one endA pulse near 1000 microseconds
Knob in the middleA pulse near 1500 microseconds
Knob at the other endA pulse near 2000 microseconds
Repeat rateA new pulse about every 20 milliseconds
Grounds not joinedThe reader prints nothing useful

If it does not work

Reader prints nothing

Join the grounds and check the D9 to D2 wire.

Servo jitters or board resets

Use a smaller servo or a separate battery pack with a common ground.

Widths look half or double

Check you read HIGH pulses on the right pin.

Servo does not move

Check the three servo wires.

Angle guess is off

Your servo range may differ from 1 to 2 ms.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the servo pulse width reader?

Arduino Nano × 2, SG90 Micro Servo, Potentiometer 10 kΩ, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the servo pulse width reader take to build?

About 70 minutes for a intermediate maker, in 7 steps.

How do I know the servo pulse width reader works?

Knob at one end: A pulse near 1000 microseconds. Knob in the middle: A pulse near 1500 microseconds. Knob at the other end: A pulse near 2000 microseconds.

Reader prints nothing: what should I check?

Join the grounds and check the D9 to D2 wire.

Servo jitters or board resets: what should I check?

Use a smaller servo or a separate battery pack with a common ground.

Widths look half or double: what should I check?

Check you read HIGH pulses on the right pin.

Servo does not move: what should I check?

Check the three servo wires.