🎃 New: 5 spooky Halloween STEM activities →

Arduino Servo Door Project: Wiring and Code

A servo motor turns to an exact angle from 0° to 180°. Use it to open and close an automatic door.

Parts you need

Wiring

  1. Orange wire → pin ~9
  2. Red wire → 5V rail
  3. Brown wire → GND rail

Arduino code

#include <Servo.h>
Servo door;

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

void loop() {
  door.write(0);     // closed
  delay(1500);
  door.write(90);    // open
  delay(1500);
}

Goal and tip

Goal: Swing the door from 0° to 90°.

Tip: Try this: open the door all the way to 180°.

Run this experiment in the free simulator