This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:iot-open:hardware2:actuators_motors [2023/08/25 12:46] – ekontoturbo | en:iot-open:hardware2:actuators_motors [2023/11/23 13:26] (current) – pczekalski | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Actuators ====== | ||
| + | {{: | ||
| + | Actuators are devices that can do a physical action to the surrounding world. Most actuators are based on one of the forms of electric motors, sometimes directly, sometimes using a gearbox and advanced control logic.\\ | ||
| + | An electric motor is an electromechanical device which can turn electrical energy into mechanical energy. The motor turns because the electricity in its winding generates a magnetic field that inducts the mechanical force between the winding and the magnet. Electric motors are made in many variants, of which the simplest is the permanent-magnet DC motor. | ||
| + | |||
| + | == DC Motor (One Direction) == | ||
| + | DC motor is a device which converts direct current into mechanical rotation. DC motor consists of permanent magnets in the stator and coils in the rotor. Applying the current to coils creates an electromagnetic field, and the rotor tries to align itself to the magnetic field. Each coil is connected to a commutator, which supplies coils with current, thus ensuring continuous rotation. Some motors have a tachometer functionality as the loopback signal that generates a pulse train of frequency proportional to the rotation speed. Tacho signal can be connected to a digital or interrupt input of a microcontroller, | ||
| + | |||
| + | <figure dcmotor1> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <figure dcmotor2> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | Sample code to control a DC motor using Arduino framework is present below: | ||
| + | <code c> | ||
| + | void setup () | ||
| + | { | ||
| + | pinMode(5, | ||
| + | //The function for turning on the motor is defined | ||
| + | #define motON digitalWrite(5, | ||
| + | //The function for turning off the motor is defined | ||
| + | #define motOFF digitalWrite(5, | ||
| + | } | ||
| + | void loop () | ||
| + | { | ||
| + | motON; //Turn on the motor | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | == DC Motor With H-Bridge == | ||
| + | |||
| + | The H-bridge has earned its name because it resembles the capital ' | ||
| + | By switching the switches, it is possible to change the motor direction. It is important to remember that the switches must be turned on and off in pairs (figure {{ref> | ||
| + | |||
| + | <figure hbridge1> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | When all switches are turned off, the motor is in free movement. It is not always acceptable, so two solutions can be implemented. If both positive or negative switches are turned on at the top or the bottom, then the motor coil is shorted, not allowing it to have a free rotation – it is slowed down faster. The fastest option to stop the motor is to turn the H-bridge in the opposite direction for a while. | ||
| + | |||
| + | <note warning> | ||
| + | |||
| + | The motor management can be reflected in the table {{ref> | ||
| + | |||
| + | <table hbridgetable> | ||
| + | < | ||
| + | ^ Upper left ^ Upper right ^ Lower left ^ Lower right ^ Motor work mode ^ | ||
| + | | **On** | Off | Off | **On** | **Turns in one direction** | | ||
| + | | Off | **On** | **On** | Off | **Turns in another direction** | | ||
| + | | **On** | **On** | Off | Off | Braking | | ||
| + | | Off | Off | **On** | **On** | Braking | | ||
| + | </ | ||
| + | |||
| + | The complicated part is implementing and controlling the switches mentioned above, usually as relays or appropriate power transistors. The biggest drawback of relays is that they can only turn the engine on or off. Transistors must be used if the rotation speed needs to be regulated using the pulse width modulation. The MOSFET-type transistors should be used to ensure a large amount of power.\\ | ||
| + | Nowadays, the stable operation of the bridge is ensured by adding extra elements. All elements can be encapsulated in a single integrated circuit, e.g. L293D (figure {{ref> | ||
| + | |||
| + | <figure L293D_1> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The L293D microchip consists of two H-bridges and is made for managing two motors. It has separate control pins for the left and right branches, avoiding the power short circuit if connected properly.\\ An example schematic diagram of connecting the chip to the Arduino Uno board can be seen in figure {{ref> | ||
| + | < | ||
| + | |||
| + | <figure L293D_2> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The example code to control the L293D chip is presented below: | ||
| + | <code c> | ||
| + | int dirPin1 = 7; //1st direction pin | ||
| + | int dirPin2 = 8; //2nd direction pin | ||
| + | int speedPin = 5; //Pin responsible for the motor speed | ||
| + | |||
| + | void setup () | ||
| + | { | ||
| + | pinMode (dirPin1, | ||
| + | pinMode (dirPin2, | ||
| + | pinMode (speedPin, | ||
| + | } | ||
| + | |||
| + | void loop () | ||
| + | { | ||
| + | analogWrite(speedPin, | ||
| + | //Speed value can be from 0 to 255 | ||
| + | | ||
| + | int motDirection = 1; //Motor direction can be either 0 or 1 | ||
| + | | ||
| + | if (motDirection) //Setting motor direction | ||
| + | {//If 1 | ||
| + | digitalWrite(dirPin1, | ||
| + | digitalWrite(dirPin2, | ||
| + | } | ||
| + | else | ||
| + | {//If 0 | ||
| + | digitalWrite(dirPin1, | ||
| + | digitalWrite(dirPin2, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | == Linear actuator == | ||
| + | A bidirectional DC motor, usually controlled with an H-bridge and equipped with thread gear, can be used to implement the linear actuators.\\ | ||
| + | Linear actuators used to be equipped with end position detectors such as switches, or eventually, their end positions can be detected with overload detection. A simple linear actuator is present in figure {{ref> | ||
| + | <figure linactuator> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | == Stepper Motor == | ||
| + | A certain angle or step can move stepper motors. The full rotation of the motor is divided into small, equal steps. Stepper motor has many individually controlled electromagnets; | ||
| + | An example of use can be found in the source ((https:// | ||
| + | |||
| + | <figure steppermotor1> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <figure steppermotor2> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The example code: | ||
| + | <code c> | ||
| + | #include < | ||
| + | |||
| + | int in1Pin = 12; //Defining stepper motor pins | ||
| + | int in2Pin = 11; | ||
| + | int in3Pin = 10; | ||
| + | int in4Pin = 9; | ||
| + | |||
| + | //Define a stepper motor object | ||
| + | Stepper motor(512, in1Pin, in2Pin, in3Pin, in4Pin); | ||
| + | |||
| + | void setup() | ||
| + | { | ||
| + | pinMode(in1Pin, | ||
| + | pinMode(in2Pin, | ||
| + | pinMode(in3Pin, | ||
| + | pinMode(in4Pin, | ||
| + | |||
| + | Serial.begin(9600); | ||
| + | motor.setSpeed(20); | ||
| + | } | ||
| + | |||
| + | void loop() | ||
| + | { | ||
| + | motor.step(5); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | == Servomotor == | ||
| + | |||
| + | The servomotor includes the internal closed-loop position feedback mechanism that precisely controls its position angle. To set the angle, the PWM technique is used. Additionally, | ||
| + | Servomotors have limited rotation angles depending on their type, e.g. 90, 180 or 270 degrees. A typical servo is 180 degrees (usually a bit lower). Servo powering depends on size; micro servos are typically between 4.8V and 6V. Larger servos require higher voltage and more current to operate.\\ | ||
| + | There are two standards for controlling servos, so-called " | ||
| + | |||
| + | < | ||
| + | |||
| + | From the figure {{ref> | ||
| + | The servomotor management chain meets the impulse every 20 ms, but the pulse width shows the position the servomotor has to reach. For example, 1 ms corresponds to the 0° position but 2 ms – to the 180° position against the starting point. When entering the defined position, the servomotor will keep it and resist any outer forces trying to change the current position. The graphical representation of the control signal and its impact on the position of the servomotor is presented in image {{ref> | ||
| + | |||
| + | <figure servomotor> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | Just like other motors, servomotors have different parameters, where the most important one is the time of performance – the time necessary to change the position to the defined position. The best enthusiast-level servomotors do a 60° turn in 0.09 s. There are three types of servomotors: | ||
| + | * **Positional rotation servomotor** – most widely used type of servomotor. With the help of a management signal, it can determine the position of the rotation angle from its starting position. | ||
| + | * **Continuous rotation servomotor** – this type of motor allows setting the speed and direction of the rotation using the management signal. If the position is less than 90°, it turns in one direction, but if more than 90°, it turns in the opposite direction. The speed is determined by the difference in value from 90°; 0° or 180° will turn the motor at its maximum speed while 91° or 89° at its minimum rate. | ||
| + | * **Linear servomotor** – with the help of additional transfers, it allows moving forward or backwards; it doesn' | ||
| + | |||
| + | Unfortunately, | ||
| + | |||
| + | Sample standard servo is present in figure {{ref> | ||
| + | |||
| + | <figure stdservo1> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | <figure stdservo2> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The example code to control a servo: | ||
| + | <code c> | ||
| + | #include < | ||
| + | Servo servo; //Define a Servo object | ||
| + | |||
| + | void setup () | ||
| + | { | ||
| + | servo.attach(6); | ||
| + | servo.write(90); | ||
| + | Serial.begin(9600); | ||
| + | } | ||
| + | |||
| + | void loop () | ||
| + | { | ||
| + | servo.write(110); | ||
| + | delay(200); //wait for 200 ms | ||
| + | servo.write(70);// | ||
| + | delay(200); //Wait for 200 ms | ||
| + | } | ||
| + | |||
| + | </ | ||