Close Menu
Circuit of Things
  • Home
  • Projects
    • Raspberry Pi Projects
    • Arduino Projects
    • ESP8266 Projects
    • ESP32 Projects
    • IoT Tutorials
    • Sensors & Modules
    • IoT Basics
  • About Us
  • Get In Touch
  • 3D Print
  • Shop Now !
  • Electro Calc

Stay in the Loop!

Subscribe to get the latest IoT tutorials, Arduino projects, and electronics guides delivered straight to your inbox.

Instagram WhatsApp
  • Terms and Conditions
  • Disclaimer
  • Privacy Policy
Circuit of Things Circuit of Things
  • Home
  • Projects
    • Raspberry Pi Projects
    • Arduino Projects
    • ESP8266 Projects
    • ESP32 Projects
    • IoT Tutorials
    • Sensors & Modules
    • IoT Basics
  • About Us
  • Get In Touch
  • 3D Print
  • Shop Now !
  • Electro Calc
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, 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!

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

Arduino Projects

Relay Module with Arduino: Control High Voltage Appliances Safely

May 4, 2026
Arduino Projects

PIR Motion Sensor with Arduino: Smart Security Alarm System

May 4, 2026
Arduino Projects

LDR Light Sensor with Arduino: Auto Night Light Project

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


KSP Electronics
✓ Trusted Store
Everything for Your
Next IoT Build
Boards, sensors, modules & kits delivered fast across India.
ESP32 Arduino Sensors Modules DIY Kits
500+
Products
Fast
Delivery
★★★★★
Rated
🛒 Shop Now →
kspelectronics.in
💻
● Available for Projects
Hire Me for
IoT Projects
ESP32, LoRaWAN, cloud dashboards & custom hardware — end-to-end IoT solutions for your needs.
ESP32 LoRaWAN MQTT Arduino Cloud PCB Design
3+
Yrs Exp
20+
Projects
★★★★★
Rated
💬 Chat on WhatsApp
View services →
Top Posts

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

July 14, 2023

Relay Module with Arduino: Control High Voltage Appliances Safely

May 4, 2026

Esp8266 / NodeMCU Pinout: A Comprehensive Guide for Beginners

June 25, 2023
Follow Us
  • Telegram

Stay in the Loop!

Subscribe to get the latest IoT tutorials, Arduino projects, and electronics guides delivered straight to your inbox.

Most Popular

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

July 14, 2023

Relay Module with Arduino: Control High Voltage Appliances Safely

May 4, 2026

Esp8266 / NodeMCU Pinout: A Comprehensive Guide for Beginners

June 25, 2023
Our Picks

Relay Module with Arduino: Control High Voltage Appliances Safely

May 4, 2026

NodeMCU ESP8266 Sensor Data to ThingSpeak IoT Platform

May 4, 2026

ESP32 Firebase Realtime Database: Send and Receive Data from the Cloud

May 4, 2026

Stay in the Loop!

Subscribe to get the latest IoT tutorials, Arduino projects, and electronics guides delivered straight to your inbox.

© 2026 Circuit of Things. All Rights Reserved. Built with ❤️ for the Maker Community.

  • About
  • Privacy
X (Twitter) Instagram YouTube WhatsApp
  • Book an Appointment
  • My Bookings
  • Support Us
© 2026 Circuit of Things. Designed by Sai Preetham Koyyala.

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