Arduino + servo + potentiometer

Servo – a drive that is controlled through negative feedback, allowing fine control of movement parameters. Servo is any type of mechanical drive, which is a part of sensor (position, velocity, force, etc.) and drive control unit that automatically maintains the required parameters for sensors and device according to the given external value.

6cbcfb7bbdc72ba36170cde54b77371d

Connecting to Arduino

Many actuators can be connected directly to the Arduino. To do this, go train them with three wires:

red – power supplyconnected to 5V or contact directly to the power supply
brown or blackground (GND pin Arduino)
yellow or whitesignal; connected to Arduino digital output.

You can generate control pulses independently, but it is so common problem that exists simplified standard library Servo.

Limitation of power supply

Straight hobby servo while running consumes more than 100 mA. This Arduino is able to issue up to 500 mA. So if you need to use the draft multiple actuators, it makes sense to think about the selection of servo circuit with additional power.

Limitations on the number of connected servodrives

Most boards Arduino library Servo supports up to 12 control servo drives, the Arduino Mega that number increases to a value of 48 This is a small side effect of using this library if you are not with Arduino Mega, it becomes impossible to use the analogWrite () on 9 and 10 contacts regardless of servos connected to those contacts or not. On the Arduino Mega can be connected to 12 servodrives without disruption PWM / PWM, using more servodrives, we can not use analogWrite () на 11 і 12 контактах.

Functions of Servo Library

Library Servo allows software control servomotor. For this purpose, a class servo Servo. The control is performed by the following functions:

attach () – establishes rise to a specific foam. There are two possible syntax for this function:servo.attach (pin) and servo.attach (pin, min, max). This pin – Room foam, which attach servo, min and max – length of the pulse in microseconds responsible for angles 0 ° and 180 °. By default, exhibited equal 544 ms and 2400 ms, respectively.
write () – typing servo take some value. The syntax is: servo.write (angle), where angle – angle, which should result in servo.
writeMicroseconds () – gives the command sent to the servo pulse of a certain length are low-level analog of a previous command. The syntax is: servo.writeMicroseconds (uS), where uS – pulse length in microseconds.
read () – reads the current value of the angle in which the servo. The syntax is: servo.read (), returns an integer value from 0 to 180.
attached () – check whether the object is attached to a specific foam. The syntax is: servo.attached (), logical unit is returned if the object has been connected to any foam, or zero otherwise.
detach () – takes effect, retroactive attach (), that disconnects the object from the foam to which he was assigned. The syntax is: servo.detach ().



Potentiometer

To manage the change of position servo potentiometer can be used. It has three contacts connected as follows:
Two extreme contacts (usually) power supply is, the earth, and the average – information. Connect power supply potentiometer -> 5 V Arduino, land -> GND Arduino, information -> analog pin Arduino.
Such a scheme might look like:

Arduino+servo+pot

And what a primitive program:

#include

Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}

void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}





And the program works:

Оставить ответ

Обязательные поля помечены*

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.