মূল বিষয়বস্তুতে যান
Learn/Sound & motion/Servo motors
Sound & motion · Lesson
10 min read

Servo motors

Move to exact angles with the Servo library.

What You Will Learn

  • Attach a servo
  • Write angles 0–180°
  • Power servos safely

A hobby servo contains a motor, gears and a position sensor. It reads a pulse every 20 ms: about 1 ms means 0°, 2 ms means 180°. The Servo library makes these pulses for you.

Arduino C++
#include <Servo.h>
Servo arm;
void setup() { arm.attach(9); }
void loop() { arm.write(0); delay(1000); arm.write(180); delay(1000); }
Servo follows a knobarduino-uno
Open in Lab
UNOATmega328P: The 8-bit AVR microcontroller that runs your sketch (16 MHz, 32 KB flash, 2 KB RAM).ATmega328PUSB-B: USB connection for uploading sketches and for the Serial Monitor. Also powers the board (5 V).DC jack: Barrel jack for 7–12 V from a battery pack or adapter (centre positive).ATmega16U2: Converts USB to serial for uploads and Serial.print().RESET: Restarts your sketch from the beginning (setup() runs again).L (D13): Built-in LED connected to pin 13 (LED_BUILTIN).ON: Power indicator.5 V regulator: Turns 7–12 V from VIN/jack into a steady 5 V.16 MHz: Clock source: the microcontroller runs 16 million cycles per second.ICSP: In-circuit programming header (SPI). Used to burn a bootloader; not needed for normal uploads.30%—
Note: Turn the knob to steer the servo.
Servos draw current spikes. One small SG90 on the Uno's 5V pin is fine; several or larger servos need a separate 5 V supply with GND shared with the board.

Check Your Understanding

Test what you learned in this lesson

1Which wire of an SG90 carries the control signal?