Hi,
Today, we will try to control servo motors using potentiometer. And for doing these we will use Arduino as a micro controller.
After these connections, we can continue with Arduino code.
In this code, we are using Servo.h library of Arduino, after the adding this library to our code we should determine our pins. One of them is in analog pins, second one is in digital pins.
We are using analog pin for reading the resistance value of potentiometer, for writing the handled data from this analog pin will be on digital pin which determine in the beginning.
Today, we will try to control servo motors using potentiometer. And for doing these we will use Arduino as a micro controller.
First of all we need some components for doing this job, here the list of needs :
- Arduino
- Servo Motor
- Potentiometer
- Jumper Cables
Stabilizing the servo motor also important, because of the changing of the angel sould seen by us. Other hand, we will examine the potentiometer movement effect to servo motor.
We can continue with connection:
We can continue with connection:
For my code, connections would be as shown above. If you change the code - for digital and analog pins- you can change connections depending on your code.
After these connections, we can continue with Arduino code.
In this code, we are using Servo.h library of Arduino, after the adding this library to our code we should determine our pins. One of them is in analog pins, second one is in digital pins.
We are using analog pin for reading the resistance value of potentiometer, for writing the handled data from this analog pin will be on digital pin which determine in the beginning.
On the other hand, we are using the mapping command for scaling the our analog pin data, because of our servo motor limit.
As you can see on our code, value of the potentiometer which is 0 to 1023 mapped 0 to 180 for can writing by servo easily.
As you can see on our code, value of the potentiometer which is 0 to 1023 mapped 0 to 180 for can writing by servo easily.
After this mapping, we are writing data's to servo motor. As a result we can control the servo motor using potentiometer.
You can reach the code easily :
You can reach the code easily :
//Controlling the Servo Motor Using Potentiometer
//M.Furkan BAHAT
#include
const int pot=A1;
Servo myservo;
int potdurum=0;
int pos = 0;
void setup(){
myservo.attach(9);
}
void loop(){
potdurum=analogRead(pot);
pos= map(potdurum,0,1023,0,180);
{
myservo.write(pos);
}
}
It just tells me that #include expects a "filename"
ReplyDelete