zayedalam
Published © MPL-2.0

Control servo using potentiometer

Hi guys! As always, I have created a simple and a fun project by using servo and potentiometer.

BeginnerFull instructions provided287
Control servo using potentiometer

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
of any size
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Story

Read more

Schematics

Here is the schematics

Code

Here is the code

Arduino
#include <Servo.h>


 
 Servo servo_test;      //initialize a servo object for the connected servo  
                
 int angle = 0;    
 int potentio = A0;      // initialize the A0analog pin for potentiometer

 
 void setup() 
 { 
  servo_test.attach(9);   // attach the signal pin of servo to pin9 of arduino
 } 
 
 void loop() 
 { 
  angle = analogRead(potentio);            // reading the potentiometer value between 0 and 1023 
  angle = map(angle, 0, 1023, 0, 179);     // scaling the potentiometer value to angle value for servo between 0 and 180) 
  servo_test.write(angle);                   //command to rotate the servo to the specified angle 
  delay(5);             
 }  

Credits

zayedalam

zayedalam

7 projects • 1 follower

Comments