Arduino: Project 22: Control Servo with potentiometer

Hello everyone!! Welcome to this post on Arduino Projects!!
Need a short introduction to what the Arduino is then click on LINK
Check out the breadboard intro right HERE

Soo in this project I just got a microservo to turn according to the voltage across a potentiometer.

Demo:

Things Required:

  1. Arduino UNO
  2. Jumper Wires
  3. microservo
  4. 10k ohm resistor
  5. Arduino IDE on computer

Code:

View on/ Download from Github: (LINK)

#include<Servo.h>
int servopin=9;
int servopos=0;;
Servo myservo;

int potpin=A0;
int potval;

void setup() {
  pinMode(potpin, INPUT);
  myservo.attach(servopin);
  myservo.write(servopos);
  Serial.begin(9600);
}

void loop() {
  potval=analogRead(potpin);
  servopos=(180.0/1023.0)*potval;
  myservo.write(servopos);
  Serial.println(servopos);
}

Stay Tuned for upcoming posts on Arduino Projects! Want to be the first to know when a new and amazing post comes up?? Then feel free to subscribe!

Happy Learning!!

This image has an empty alt attribute; its file name is stay-tuned.gif

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: