====== Actuators ======
{{:en:iot-open:czapka_b.png?50| General audience classification icon }}{{:en:iot-open:czapka_e.png?50| General audience classification icon }}\\
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, allowing for determining actual rotation speed. DC motors are widely used in power tools, toys, electric cars, robots, etc. (figure {{ref>dcmotor1}}). The connection schematic for a small DC motor is present in figure {{ref>dcmotor2}}.
Sample code to control a DC motor using Arduino framework is present below:
void setup ()
{
pinMode(5,OUTPUT); //Digital pin 5 is set to output
//The function for turning on the motor is defined
#define motON digitalWrite(5,HIGH)
//The function for turning off the motor is defined
#define motOFF digitalWrite(5,LOW)
}
void loop ()
{
motON; //Turn on the motor
}
== DC Motor With H-Bridge ==
The H-bridge has earned its name because it resembles the capital 'H' wherein all the corners are switches, and the electric motor is in the middle. This bridge is usually used for operating permanent-magnet DC motors, electromagnets and other similar elements because it allows working with significantly bigger current devices using a small, driving current.
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>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.
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,OUTPUT); //1st direction pin is set to output
pinMode (dirPin2,OUTPUT); //2nd direction pin is set to output
pinMode (speedPin,OUTPUT); //Speed pin is set to output
}
void loop ()
{
analogWrite(speedPin, 100); //Setting motor speed
//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,HIGH);
digitalWrite(dirPin2,LOW);
}
else
{//If 0
digitalWrite(dirPin1,LOW);
digitalWrite(dirPin2,HIGH);
}
}
== 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>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; turning them on or off makes a motor shaft rotate by one step. Changing the switching speed or order can precisely control the rotation's angle, direction or speed. Because of their exact control ability, they are used in CNC machines, 3D printers, scanners, hard drives, etc.\\ A popular stepper motor is present in figure {{ref>steppermotor1}} and its controlling circuit in figure {{ref>steppermotor2}}.\\
An example of use can be found in the source ((https://learn.adafruit.com/adafruit-arduino-lesson-16-stepper-motors/breadboard-layout)).
The example code:
#include //Include library for stepper motor
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, OUTPUT); //Set stepper motor control pins to output
pinMode(in2Pin, OUTPUT);
pinMode(in3Pin, OUTPUT);
pinMode(in4Pin, OUTPUT);
Serial.begin(9600);
motor.setSpeed(20); //Set the speed of stepper motor object
}
void loop()
{
motor.step(5); //Rotate 5 steps
}
== 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, it is possible to control the speed of angle change, acceleration and deceleration of the rotation.\\
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 "analogue" and "digital". Analogue servos are controlled with a PWM signal of 50Hz (20ms period), while digital servos, even if backwards compatible with analogue, can be controlled with a PWM signal up to 250Hz. A duty cycle (a ratio between //HIGH// and //LOW//) controls servo position. We focus below on analogue servomotors, controlled with a 50Hz PWM signal, but the transition to digital ones is straightforward.
#include //Include Servo library
Servo servo; //Define a Servo object
void setup ()
{
servo.attach(6); //Connect servo object to pin D6
servo.write(90); //Set position of servo to 90°
Serial.begin(9600);
}
void loop ()
{
servo.write(110); //Set position of servo to 110°
delay(200); //wait for 200 ms
servo.write(70);//Set position of servo to 70°
delay(200); //Wait for 200 ms
}