Close Menu
Circuit of Things
  • Home
  • About Us
  • Contact Us
  • 3D Print
  • Shop Now !
  • Projects
    • Raspberry Pi Projects
    • Arduino Projects
    • ESP8266 Projects
    • ESP32 Projects
    • IoT Tutorials
    • Sensors & Modules
    • IoT Basics
  • KSP Tools

Get Free Tutorials & Discounts!

Subscribe for the latest IoT tutorials and exclusive KSP Electronics discount codes.

Instagram WhatsApp
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
  • Contact Us
Circuit of Things Circuit of Things
  • Home
  • About Us
  • Contact Us
  • 3D Print
  • Shop Now !
  • Projects
    • Raspberry Pi Projects
    • Arduino Projects
    • ESP8266 Projects
    • ESP32 Projects
    • IoT Tutorials
    • Sensors & Modules
    • IoT Basics
  • KSP Tools
Hire us
Circuit of Things
Home»Arduino Projects»Arduino Servo Motor Control: Sweep, Potentiometer and Button Projects
Arduino Projects

Arduino Servo Motor Control: Sweep, Potentiometer and Button Projects

Sai Preetham KoyyalaBy Sai Preetham KoyyalaMay 4, 2026Updated:May 7, 2026No Comments2 Mins Read
Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
Share
Facebook Twitter LinkedIn Pinterest Email
Contents
  • Introduction
  • Components Needed
  • Wiring
  • Project 1: Sweep
  • Project 2: Potentiometer Control
  • Project 3: Button-Controlled Lock
  • Conclusion

Introduction

Servo motors are essential for robotics and automation. Unlike regular DC motors, a servo motor can be commanded to rotate to a precise angle — making it perfect for robot arms, camera gimbals, and door locks. In this tutorial, we cover three practical projects using a standard SG90 servo and an Arduino.

Components Needed

  • Arduino Uno
  • SG90 Servo Motor
  • 10k-ohm potentiometer (for project 2)
  • Pushbutton (for project 3)

Wiring

The SG90 has three wires: Red → 5V, Brown → GND, Orange (signal) → Pin 9.

Project 1: Sweep

#include <Servo.h>
Servo myServo;
void setup() { myServo.attach(9); }
void loop() {
  for (int pos = 0; pos <= 180; pos++) { myServo.write(pos); delay(15); }
  for (int pos = 180; pos >= 0; pos--) { myServo.write(pos); delay(15); }
}

Project 2: Potentiometer Control

#include <Servo.h>
Servo myServo;
#define POT_PIN A0
void setup() { myServo.attach(9); }
void loop() {
  int val = analogRead(POT_PIN);
  int angle = map(val, 0, 1023, 0, 180);
  myServo.write(angle);
  delay(15);
}

Project 3: Button-Controlled Lock

#include <Servo.h>
Servo myServo;
#define BTN_PIN 2
bool locked = true;
void setup() {
  myServo.attach(9);
  pinMode(BTN_PIN, INPUT_PULLUP);
  myServo.write(0); // Locked position
}
void loop() {
  if (digitalRead(BTN_PIN) == LOW) {
    locked = !locked;
    myServo.write(locked ? 0 : 90);
    delay(300); // Debounce
  }
}

Conclusion

Servo motors open up a world of mechanical possibilities. Combine them with sensors and you can build fully autonomous robotic systems!

Related Tutorials

  • How to Build a DIY Robotic Hand using Flex Sensors and Arduino
  • HC-SR04 Ultrasonic Sensor Arduino: Distance Measurement and Projects
  • PIR Motion Sensor with Arduino: Smart Security Alarm System
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
Previous ArticleESP32 OTA Updates: Program Your Board Over Wi-Fi with Arduino IDE
Next Article PIR Motion Sensor with Arduino: Smart Security Alarm System
Sai Preetham Koyyala
  • Website
  • Facebook
  • X (Twitter)
  • Instagram
  • LinkedIn

Hello, I am Sai Preetham Koyyala. I'm an electronics engineer by profession, a DIY enthusiast by passion. ESP32 and Arduino are the main topics of my work.

Related Posts

IoT Tutorials

How to Build a DIY Robotic Hand using Flex Sensors and Arduino

May 6, 2026
IoT Tutorials

How to Build a DIY Robotic Hand using Flex Sensors and Arduino

May 6, 2026
IoT Basics

How to Power Your Arduino & ESP32 Projects Properly

May 6, 2026
Add A Comment
Leave A Reply Cancel Reply


⚡

Circuit of Things

Free IoT tutorials & electronics projects — powered by KSP Electronics.

📸 Instagram 💬 Community
✓ Official Partner Store

Everything for Your
Next IoT Build

Boards, sensors, modules & kits — fast delivery across India.

ESP32 Arduino Sensors Raspberry Pi 3D Print
🛒 Shop KSP Electronics →
Top Posts

Raspberry Pi: How to Control a DC Motor with L298N and PWN on a Web Server

July 14, 2023

Step-by-Step Guide: Interface DHT11 and DHT22 Sensors with ESP32

May 6, 2026

Esp8266 / NodeMCU Pinout: A Comprehensive Guide for Beginners

June 25, 2023
Available for Projects

Hire Us for IoT Development

End-to-end solutions for your needs:

  • → ESP32 & Embedded Systems
  • → LoRaWAN & Cloud Dashboards
  • → Custom Hardware Design
  • → IoT Product Prototyping
View Services →

Get Free Tutorials & Discounts!

Subscribe to get the latest IoT tutorials and exclusive hardware discount codes for KSP Electronics delivered directly to your inbox.

Follow Us
  • Instagram
  • Telegram
About Circuit of Things

We are a community-driven engineering platform dedicated to IoT, Robotics, and DIY electronics tutorials.

Proudly partnered with KSP Electronics.

Quick Links
  • Home
  • ESP32 Projects
  • Arduino Projects
  • IoT Tutorials
  • Sensors & Modules
  • Shop on KSP Electronics
  • Electro Calc
Legal & Support
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
  • Contact Us
📩

Get Free Tutorials & Discounts!

Subscribe for IoT tutorials and exclusive KSP discount codes.

Subscription Form


By subscribing, you agree to our Privacy Policy. No spam, ever.

X (Twitter) Instagram YouTube WhatsApp
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
  • Contact Us
© 2026 Circuit of Things. Designed by Sai Preetham Koyyala.

Type above and press Enter to search. Press Esc to cancel.