vansteenkistejoren
Published © GPL3+

Control a servo with a potentiometer!

In this tutorial you learn how to control a servo with a potentiometer.

BeginnerProtip1,411
Control a servo with a potentiometer!

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

This is how to connect all the components to the arduino or genuino UNO board

Code

Code

Arduino
Look here for the code!
#include <Servo.h>          //library for controlling a servo
const byte potMeter=A3;     //potentiometer attached to analog port A3
int potMeterValue=0;
byte rotation=0;
Servo myServo;              //name your servo

void setup() {
  myServo.attach(2);        //servo attached to digital port 2
  pinMode(potMeter,INPUT);  //potentiometer is an input=>it sends information to the computer
  Serial.begin(9600);       //start serial communication at 9600 baud
}

void loop() {
  potMeterValue=analogRead(potMeter);
  rotation=map(potMeterValue,0,1023,0,180);      
  myServo.write(rotation);
  delay(1000);              //you can delete the delay, but on the serial  monitor there will be too much information
  Serial.print("Potmetervalue: ");
  Serial.print(potMeterValue);             
  Serial.print("\t");
  Serial.print("rotation: ");
  Serial.println(rotation);
  Serial.println();
}

Credits

vansteenkistejoren
0 projects • 2 followers
Contact

Comments

Please log in or sign up to comment.