Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Controlling ServoMotor By Using Of Potentiometer In Arduino
WhatsApp
Sr Karthiga
4y
9.2k
0
2
100
Article
servopoten.zip
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 Arduino Uno.
Connect the gnd of the Bluetooth to the Gnd of the Arduino Uno.
Connect the Vin of the Bluetooth to the 09 of the Arduino Uno.
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;
// first servo
const
int
servo2 = 10;
// second servo
const
int
servo3 = 5;
// third servo
const
int
servo4 = 11;
// fourth servo
const
int
servo5 = 9;
// fifth servo
const
int
joyH = 2;
// L/R Parallax Thumbstick
const
int
joyV = 3;
// U/D Parallax Thumbstick
const
int
joyX = 4;
// L/R Parallax Thumbstick
const
int
joyP = 5;
// U/D Parallax Thumbstick
const
int
potpin = 0;
// O/C potentiometer
int
servoVal;
// variable to read the value from the analog pin
Servo myservo1;
// create servo object to control a servo
Servo myservo2;
// create servo object to control a servo
Servo myservo3;
// create servo object to control a servo
Servo myservo4;
// create servo object to control a servo
Servo myservo5;
// create servo object to control a servo
void
setup() {
// Servo
myservo1.attach(servo1);
// attaches the servo
myservo2.attach(servo2);
// attaches the servo
myservo3.attach(servo3);
// attaches the servo
myservo4.attach(servo4);
// attaches the servo
myservo5.attach(servo5);
// attaches the servo
// Inizialize Serial
Serial.begin(9600);
}
void
loop(){
servoVal = analogRead(potpin);
servoVal = map(servoVal, 0, 1023, 0, 179);
myservo5.write(servoVal);
delay(15);
// Display Joystick values using the serial monitor
outputJoystick();
// Read the horizontal joystick value (value between 0 and 1023)
servoVal = analogRead(joyH);
servoVal = map(servoVal, 0, 1023, 0, 180);
// scale it to use it with the servo (result between 0 and 180)
myservo2.write(servoVal);
// sets the servo position according to the scaled value
// Read the horizontal joystick value (value between 0 and 1023)
servoVal = analogRead(joyV);
servoVal = map(servoVal, 0, 1023, 70, 180);
// scale it to use it with the servo (result between 70 and 180)
myservo1.write(servoVal);
// sets the servo position according to the scaled value
delay(15);
// waits for the servo to get there
// Read the horizontal joystick value (value between 0 and 1023)
servoVal = analogRead(joyP);
servoVal = map(servoVal, 0, 1023, 70, 180);
// scale it to use it with the servo (result between 70 and 180)
myservo4.write(servoVal);
// sets the servo position according to the scaled value
delay(15);
// waits for the servo to get there
// Read the horizontal joystick value (value between 0 and 1023)
servoVal = analogRead(joyX);
servoVal = map(servoVal, 0, 1023, 70, 180);
// scale it to use it with the servo (result between 70 and 180)
myservo3.write(servoVal);
// sets the servo position according to the scaled value
delay(15);
// waits for the servo to get there
}
/**
* Display joystick values
*/
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 Servo Motor using Potentiometer. It is used to adjust and control the motor.
Controlling ServoMotor
IoT
Potentiometer In Arduino
Up Next
Ebook Download
View all
Raspberry Pi -Sensorial Symphony of Connectivity
Read by 704 people
Download Now!
Learn
View all
Membership not found