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
- Arduino Uno
- SG90 servo motor
Wiring
- Orange wire → pin ~9
- Red wire → 5V rail
- 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°.