Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
technoesolution
Published © CC BY-NC-SA

Control Servomotor Using Potentiometer & Arduino Uno

In this tutorial I'll show you how to control rotational angle of servomotor using potentiometer & Arduino, So let's get started.

BeginnerFull instructions provided30 minutes5,212
Control Servomotor Using Potentiometer & Arduino Uno

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Circuit Diagram

Follow the circuit diagram for making connection.

Arduino To Servomotor Connection :-

5V - VCC

GND - GND

D11 - PWM

Arduino TO Potentiometer :-

5V - 1st Pin

A0 - 2nd Pin

GND - GND

Servomotor Pinouts

Code

Arduino Code

C/C++
Copy following code & Upload to arduino.
// Hello friends welcome to "TECHNO-E-SOLUTION"
// Here is a code for control servomotor using Potentiometer


#include <Servo.h>

Servo myservo;

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup() {
  myservo.attach(11);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  val = analogRead(potpin);            
  val = map(val, 0, 1023, 0, 180);     
  myservo.write(val);                  
  delay(15);                           
}

Credits

technoesolution
23 projects • 15 followers
Youtuber | Electrical Engineer | Electronics Lover | Article Writer | Project Developer |

Comments