Introduction
In this article, I am explaining about controlling the ServoMotor using Potentiometer in Arduino. In this article, I will control the Servo Motor in the adjustment of Potentiometer.
Parts of the List
- Arduino Uno
- Potentiometer
- Servo Motor
- Bread Board
- Hook up wires
Connection
Servo Motor
- Connect the Vcc of the Servo Motor to the 5v of the ArduinoUno.
- Connect the gnd of the bluetooth to the Gnd of the ArduinoUno.
- Connect the Vin of the bluetooth to the 09 of the ArduinoUno.
Potentiometer
- Connect as per the preceding figure to the Arduino board and the LCD Display.
- The Vin is connected to the LCD display in 03.
Programming
- #include <Servo.h>
-
- const int servo1 = 3;
- const int servo2 = 10;
- const int servo3 = 5;
- const int servo4 = 11;
- const int servo5 = 9;
- const int joyH = 2;
- const int joyV = 3;
- const int joyX = 4;
- const int joyP = 5;
- const int potpin = 0;
-
- int servoVal;
-
-
- Servo myservo1;
- Servo myservo2;
- Servo myservo3;
- Servo myservo4;
- Servo myservo5;
- void setup() {
-
-
- myservo1.attach(servo1);
- myservo2.attach(servo2);
- myservo3.attach(servo3);
- myservo4.attach(servo4);
- myservo5.attach(servo5);
-
-
- Serial.begin(9600);
- }
-
-
- void loop(){
-
- servoVal = analogRead(potpin);
-
- servoVal = map(servoVal, 0, 1023, 0, 179);
-
- myservo5.write(servoVal);
-
- delay(15);
-
- outputJoystick();
-
-
- servoVal = analogRead(joyH);
- servoVal = map(servoVal, 0, 1023, 0, 180);
-
- myservo2.write(servoVal);
-
-
- servoVal = analogRead(joyV);
- servoVal = map(servoVal, 0, 1023, 70, 180);
-
- myservo1.write(servoVal);
-
- delay(15);
-
-
- servoVal = analogRead(joyP);
- servoVal = map(servoVal, 0, 1023, 70, 180);
-
- myservo4.write(servoVal);
-
- delay(15);
-
- servoVal = analogRead(joyX);
- servoVal = map(servoVal, 0, 1023, 70, 180);
-
- myservo3.write(servoVal);
-
- delay(15);
-
- }
-
-
-
-
-
- void outputJoystick(){
-
- Serial.print(analogRead(joyH));
- Serial.print ("---");
- Serial.print(analogRead(joyV));
- Serial.println ("----------------");
- Serial.print(analogRead(joyP));
- Serial.println ("----------------");
- Serial.print(analogRead(joyX));
- Serial.println ("----------------");
- }
Conclusion
In this article, we learned about controlling the Servo Motor using Potentiometer. It is used to adjust and control the motor.