Home All Projects
Intermediate

How to Use Servo Motors with Arduino

This tutorial will teach you how to use servo motors with Arduino.

How to Use Servo Motors with Arduino

Components, Tools and Machines

1x Arduino UNO
🛒 Buy Now
1x Breadboard (generic)
🛒 Buy Now
1x Male/Male Jumper Wires
🛒 Buy Now
1x SparkFun Breadboard Power Supply 5V/3.3V
🛒 Buy Now
1x Servos (Tower Pro MG996R)
🛒 Buy Now

Apps and platforms

1x Arduino Web Editor
Official Site
1x Arduino IDE
Official Site

Project description

Servo motors are used for making things like:

  • Coffee mixers
  • CNC machines
  • And useless robots like this :)

What is a servo motor?

A servo motor is a motor that works in angles between 0° and 180°.

A servo motor is a motor that can only be controlled by a microcontroller like:

  • An Arduino/Genuino
  • A Raspberry Pi
  • Micro:Bit

It has a small DC motor which only needs about 35 mA. It also has some gears and a potentiometer so that it can know which angle it's on.

Components

You'll need:

  • An Arduino/Genuino (any Arduino/Genuino will do as long as it's 9th pin is a PWM pin)
  • A servo motor
  • Some jumper wires
  • 5V 1A power source (you won't need this if you are using SG90 TowerPro Servo Motor

Connections

If you are using a SG90 TowerPro Servo Motor, connect the servo motor like this:

  • Signal cable (orange one) ==> D9 on Arduino
  • Power cable (red one) ==> 5v pin on Arduino
  • Ground cable (black or brown one) ==> ground pin on Arduino

If you are not using a SG90 TowerPro Servo Motor, connect the servo motor and the power source like this:

  • Signal cable (orange one) ==> D9 on Arduino
  • Power cable (red one) ==> 5v pin of power source
  • Ground cable (black or brown one) ==> ground pin of power source
  • Ground pin of Arduino ==> ground pin of power source

What are the functions in Servo library?

These are the functions in Servo library:

Servo x;

x = the name that you'll use when calling the servo to do something.

x.attach(y);

x = the name that you'll use when calling the servo to do something.

y = the pin to attach servo.

x.write(pos);

x = the name that you'll use when calling the servo to do something.

pos = the angle that you want your servo motor to go. (it has to be something between 0° and 180°.

Code

🔒 Unlock Code

Support to get the Source Code for this project

Project Reference Code: how-to-use-servo-motors-with-arduino-5a390a-en
870 THB
PromptPay QR Code

ประเมินราคาอัตโนมัติ + Reference Code

อยากได้งานคล้ายโปรเจคนี้ ให้ AI ประเมินราคาก่อน

กรอกข้อมูลให้ครบ ระบบจะสร้างรหัสอ้างอิงและประเมินราคา/ระยะเวลาคร่าว ๆ จากรายละเอียดงาน แล้วให้กด Add LINE พร้อมพิมพ์รหัสนี้เพื่อคุยต่อ

คำถามให้ AI ประเมินแม่นขึ้น

หลังส่งฟอร์ม ระบบจะโชว์ Reference Code ให้ copy แล้วกด Add LINE เพื่อคุยต่อ ข้อมูลส่วนตัวจะไม่ถูกส่งเข้า GA4

รีวิวจากคนใช้งานจริง

รีวิวจากลูกค้าและคนที่เคยใช้งาน

ถ้าเคยสั่งงาน เคยอ่านหน้านี้แล้วได้ประโยชน์ หรือมีข้อเสนอแนะ ฝากรีวิวไว้ได้เลย

กำลังโหลดรีวิว...