Skip to main content

servo

Control servo motors with precise angle positioning via PWM signals.

Overview

The servo node controls servo motors with precise angular positioning using PWM (Pulse Width Modulation) signals. Standard hobby servos rotate between 0 and 180 degrees, while continuous rotation servos use the same signal for speed and direction control. Ideal for robotics, pan/tilt cameras, valve actuators, and automated mechanical systems.

0-180°
Angle Range
50Hz
PWM Frequency
1-2ms
Pulse Width
HW PWM
Signal Type

Properties

Property Type Required Default Description
pin number Yes 18 PWM-capable GPIO pin (BCM numbering)
minPulse number No 1.0 Minimum pulse width in milliseconds (0° position)
maxPulse number No 2.0 Maximum pulse width in milliseconds (180° position)
frequency number No 50.0 PWM frequency in Hz (standard servo = 50Hz)
minAngle number No 0.0 Minimum allowed angle in degrees
maxAngle number No 180.0 Maximum allowed angle in degrees
startAngle number No 90.0 Initial angle on deploy (center position)

Inputs

msg.payload

Sets the target angle in degrees (0-180).

0 Minimum position (1.0ms pulse)
90 Center position (1.5ms pulse)
180 Maximum position (2.0ms pulse)

Outputs

Position Confirmation

Outputs current servo position with calculated pulse width.

{
  "angle": 90,
  "pulseWidth": 1.5,
  "pin": 18,
  "timestamp": 1709251200000
}

Wiring / Connection Diagram

Standard Servo to Raspberry Pi

  Raspberry Pi                   Servo Motor
  +-----------+                 +----------+
  |           |                 |  Signal  |<-- Orange/White wire
  |  GPIO 18  |----[PWM Signal]-|  (PWM)   |
  |           |                 |          |
  |  5V       |----[Power]------| VCC (+)  |<-- Red wire
  |           |                 |          |
  |  GND      |----[Ground]-----| GND (-)  |<-- Brown/Black wire
  |           |                 +----------+
  +-----------+

  Pulse Width Mapping:
  ┌─────────┬────────────┬────────────┐
  │  Angle  │ Pulse (ms) │ Duty Cycle │
  ├─────────┼────────────┼────────────┤
  │   0°    │   1.0 ms   │   5.0%     │
  │  90°    │   1.5 ms   │   7.5%     │
  │ 180°    │   2.0 ms   │  10.0%     │
  └─────────┴────────────┴────────────┘

Tip: Use an external 5V power supply for servos drawing more than 500mA. Connect grounds together between the Pi and the external supply.

Example Use Cases

Dashboard Slider Servo Control

Control servo angle from a dashboard slider widget (0-180 degrees).

slider (0-180) servo
[
  {
    "id": "angle-slider",
    "type": "slider",
    "label": "Servo Angle",
    "min": 0,
    "max": 180,
    "step": 1
  },
  {
    "id": "pan-servo",
    "type": "servo",
    "pin": 18,
    "minPulse": 1.0,
    "maxPulse": 2.0,
    "startAngle": 90
  }
]

Automated Door Lock

Use RFID input to lock/unlock a servo-driven deadbolt mechanism.

rfid function servo
[
  {
    "id": "rfid-reader",
    "type": "rfid",
    "pin": 8
  },
  {
    "id": "auth-check",
    "type": "function",
    "func": "// Authorized card UIDs
var allowed = ['A1B2C3D4', 'E5F6A7B8'];
var uid = msg.payload.uid;
msg.payload = allowed.includes(uid) ? 0 : 90;
return msg;"
  },
  {
    "id": "lock-servo",
    "type": "servo",
    "pin": 12,
    "minAngle": 0,
    "maxAngle": 90,
    "startAngle": 90
  }
]

Pan-Tilt Camera Mount

Control dual servos for pan and tilt via MQTT commands.

mqtt-in change servo (pan) / servo (tilt)
[
  {
    "id": "mqtt-camera",
    "type": "mqtt-in",
    "topic": "camera/position"
  },
  {
    "id": "pan-servo",
    "type": "servo",
    "pin": 18,
    "minAngle": 0,
    "maxAngle": 180,
    "startAngle": 90
  },
  {
    "id": "tilt-servo",
    "type": "servo",
    "pin": 12,
    "minAngle": 30,
    "maxAngle": 150,
    "startAngle": 90
  }
]

Common Use Cases

Robotics

Articulated arms, grippers, and walking mechanisms

Pan-Tilt Cameras

Surveillance and tracking camera mounts

Door Locks

Automated deadbolt and latch mechanisms

Valve Control

Proportional valve actuators for flow regulation

Related Nodes