Professional Documents
Culture Documents
However, control mechanisms were designed that could automatically adjust the
system’s input variable(s) in order to restrict the output to a tolerable range from
the desired output level. These control mechanisms were collectively referred to as
control systems. A control system is an interconnection of components that can
interface with a system in order to achieve a desired response (output) [1].
Most control systems employ a feedback mechanism such that the actual output at
any given interval is measured and compared against a desired value. These are
known as closed-loop control systems [1]. Here, any deviation produced is used to
generate an error signal and sent to a component called the actuator which directly
applies the correction on the system. The former action is performed by a
controller (or sometimes called a control device). The block diagram of a typical
control system is shown in plate 1.1.
1
Fig. 1.1: Block Diagram of a Typical Control System [1]
Actuators are necessary because they provide a way of physically interacting with
a system [2].
James Watt developed the first controller ‘the flyball governor’ which could
control the speed of an engine by regulating its fuel intake [1]. The all-mechanical
device utilized the movement of two fly balls to manipulate a shaft which then
opens the fuel intake valve or closes it. The controller-actuator link here was a
combination of the mechanical linkage between the flyballs and the intake valve.
These systems were inefficient as they depended on the system for their source of
energy. As time progressed, pneumatic control devices were developed.
Controllers in this case were still mechanical devices, the difference was they were
pneumatically powered and generated pneumatic signals to drive actuators. This
implies that they could be driven by an external pressure source thereby reducing
3
the problem of taking energy from the system. However, they were limited in
performance since they were based on mechanical parts.
Finally, modern control systems were developed based on electric and electronic
components. Semiconductor devices were used as controllers and actuators were
electrically activated as described earlier. These devices were programmed to
generate signals corresponding to the desired control action.
4
SECTION TWO
2.0 OVERVIEW OF BASIC COMPONENTS AND RELATED
WORKS
2.1 OVERVIEW OF BASIC COMPONENTS
Electrically activated motion actuators are ubiquitous in most modern control
systems. Such actuators include; electric motors and solenoids. These devices are
operated by electric signals and they can be found in automatic assembly lines,
generators, control valves, robotic systems and whatnots. Knowledge of how these
actuators operate is necessary in developing control strategies.
5
When the current through the motor is reversed, the direction of rotation also
reverse according to Fleming’s left-hand rule. DC motors can be brushed or
brushless. Brushed DC motors use a conductor (brush) – thick orange line close to
the shaft in plate 2.1 - to pass current to the armature winding.
Servo-motors: Servo motors are regular motors equipped with a control circuitry.
The control circuitry senses error based on the angular difference between the
current position of the motor’s shaft and the desired position due to the control
signal received. Position is sensed using a potentiometer. The error signal is then
used to correct the motor’s output (shaft position).
Servos can be either DC or AC and they are used for accurate angular positioning.
Usually, they are controlled by pulse-width modulated signals where the width of
the pulse determines the angular displacement of the shaft [3]. They are widely
used in robotics and small models as they are easily controlled using just three
wires, Power, Ground and Signal Control [5] as seen in plate 2.2
6
Plate 2.2: Block diagram of a servo motor [5]
Stepper motor: Stepper motors are quite different from DC motors in that they do
not rotate but step. Internally, steppers consist of a rotor with permanent magnet
teeth and a stator having electromagnet (has electromagnetic coils) teeth [5].
When a coil is energized, it acts like a magnet and the rotor moves to align with it.
This is known as a step. Since each coil can be separately energized, the rotor can
be made to go through one revolution by sequentially activating the coil pairs.
Thus, an integer number of steps makes a full rotation. In that way, the motor can
be rotated (stepped) through a precise angle known as the step angle as shown in
plate 2.3.
This makes stepper motors ideal for precise motion control, since every position
can be approximately determined in a number of steps from the initial position. A
revolution can be divided into 4 – 400 steps, although 24, 48 and 200 steps are
commonly used. By dividing a complete revolution by the number of steps, the
degree change per step can be found. For example, a 200-step motor will have a
step degree change of 360/200, i.e. 1.8° step angle.
7
Plate 2.3: A step motor having 4 poles and a step angle of 15°[5]
The stepper motor has four coils, making it a 4-phase motor, with the number of poles on
the stator being eight (2 x 4) which are spaced at 45 degrees intervals. The number of teeth
on the rotor is six which are spaced 60 degrees apart.
Then there are 24 (6 teeth x 4 coils) possible positions or “steps” for the rotor to complete
one full revolution. Therefore, the step angle above is given as: 360°/24 = 15°
Solenoids: The word solenoid is a generic term used to refer to wires wound
around a magnetic core thus forming an electromagnetic. This is shown in plate 2.4
below.
8
When energized by an electric source, the wires produce a magnetic field which
can then be used to cause linear motion by attracting or repelling a moving piston.
Solenoids are used as high power on/off switches and can be found in automatic
ignition systems, factory equipment, control valves etc.
2.1.2 RASPBERRY PI
9
Typical features of Raspberry pi boards
● Quad-core ARM processors (except for Pi zero models which use a single-
core processor)
● Universal serial bus (USB) ports: 2 or 4 (depending on the model)
● Peripherals: General purpose input and output (GPIO) pins, and HAT ID bus
● Power source: 5V via microUSB or GPIO headers
● Other feature are shown in plate 2.5.
10
operate on the more common 5V logic. In this case, a level converter would be
used to match the logic. GPIO pins are for interfacing input and output devices and
they can only source a maximum of 50mA [6]. Drivers would be needed to meet
higher current requirements. Also, a microSD card serves as the primary memory -
this is also where it looks for the operating system (OS). The microSD is slotted
into the SD card slot.
Execute program
Assuming you purchased a new raspberry pi, the first thing to do is to install the
operating system (OS). Raspberry pi supports several operating systems such as:
13
● RISC OS
● Windows IOT
● Arch Linux ARM
● LinuTop
● Open-Source Media Center (OSMC) etc. [8]
New Pi boards do not come pre-installed with any OS, instead new-out-of-the-box
software (NOOBs) are provided via an SD card. NOOBs are actually a variety of
operating systems from which the user can make their choice. Alternatively, the
OS can be downloaded from the internet and written to an SD card (raspberry pi
loads its OS from the SD card attached to SD card slot) [6]. The whole process is
summarized in fig. 3.2.
14
Purchase pi board
YES
Are the
given OS NO
desired?
YES
Write to SD card
Connect power
Boot the pi
15
Standard power supply to a raspberry pi is 5V 2/2.5A. This can be provided by the
means stated earlier.
Although older models feature 26 GPIO pins, newer models now possess 40 GPIO
pins. These pins are driven by a 3.3V rail and rated at about 17mA [6]. This is
different from the power headers where we have two 5V pins (pin 2 and pin 4) and
the 3.3V power lines which can source up to 500mA. This however depends on the
pi’s model.
GPIO pins are integrated into the circuit board of the computer. Their behavior can
be controlled by the user to allow them to read data from sensors, and control
components like LEDs, motors, and displays.
16
3.1.3 Overview of some GPIO pins
1. Power pins:
a. 5V pins (pins 2 and 4)
b. 3.3V (pins 1 and 17)
c. Ground (pins 6, 9, 14, 20, 25, 30, 34 and 39)
The power pins (can be used to power peripherals and at the same time
supply power to the pi board. The amount of current that can be sourced
to peripherals depends on what is left after the pi board has met its power
needs. Most models draw about 2A on booting, but only require about
750mA when running. Therefore, if a 2.5A power supply is used, the
maximum current that peripherals can draw without affecting the pi is
1.7A. Placing 5V on the 3.3V lines would fry the pi board.
2. Pulse width modulation (PWM) pins:
Software PWM is available on all pins save the power headers. Hardware
PWM available on GPIO12, GPIO13, GPIO18, GPIO19. Note:
distinction between pin 12 and GPIO12 as indicated in plate 3.3***.
PWM finds extensive use in controlling devices such as electric motors.
17
I2C requires two pins, serial data line (SDL) and a serial clock line
(SCL). This is provided by GPIO2 and GPIO3 pins respectively.
GPIO libraries are basically pre-written programs that allow you access and control
the GPIO pins. Several libraries exist but the most popularly used and up-to-date
libraries are RPi.GPIO (default raspberry pi GPIO library), wiringPi, GPIO zero
and pigpio.
Motor Relay
(DC and
stepper) Solenoid
A driver in its basic form is a switching and amplifying transistor which could be a
bipolar junction transistor (NPN or PNP), MOSFET or transistors in Darlington
configuration to meet high current requirements. Driver ICs have also been
developed to minimize the use of discrete components and provide easy
interfacing.
19
Fig. 3.4: Circuit showing the use of MOSFET in switching relays [9]
The flyback diode in fig. 3.4 is to protect the transistor from damage due to reverse
current.
Motor driver circuits act as current amplifiers. For DC motors, drivers consist
basically of switching elements arranged in an H-bridge. This allows for the motor
to be rotated in both directions by selectively turning on the switching elements.
This alternates the voltage between the terminals, and hence causes the current to
flow in the reverse direction which causes change in direction of rotation. A basic
structure of an H-bridge is shown in fig 3.
20
Fig. 3.5: Nature of the H-bridge during forward and reverse rotation respectively [10]
1. Switching off all the transistors. This will cause the motor to gradually
come to a halt.
2. Applying an equal voltage to both sides of the H-bridge. This will
cause a sudden halt.
The diodes in the circuit of fig. 3.4 protects sensitive electronics of the driver from
damage due to back emf. When motors rotate, they produce a back emf (or reverse
voltage) which opposes the main supply voltage from the driver. If allowed, the
reverse voltage may destroy the transistors or other circuitry.
Servo motors are equipped with onboard drivers. Therefore, they do not exceed
driver. They only require a control signal to specify the position of the shaft.
Stepper motors on the other hand, can use the same driver as a DC motor as long
as it can provide the current requirement.
The L298D motor driver shown in plate 3.2, works just like every other driver, it
acts as a current amplifier. Internally, it consists of two H-bridge driver circuits. It
21
can drive two brushed DC motors simultaneously, both in forward and reverse
directions. More features of the L298D:
Relays require about 50 – 100mA as input. GPIO pins can only source at most
50mA without tripping the module. To enable GPIO pins to interface with relays,
drivers could be used. One popular choice of relay driver is the ULN2003A, shown
in plate 3.3.
22
Fig 3.6: DIP package of ULN2003A IC and the logic diagram
23
3.3 CONTROLLING MOTORS ACTUATORS
The basic steps required to enter code into Raspberry pi has already been itemized
in section two. The working principles of the motion actuators have already been
discussed and how they can be interfaced with the pi board. Now looking at how to
write a program will be based on this understanding.
PWM allows a fixed voltage to be varied, depending on the duty cycle. For DC
motors, there is a linear relationship between the voltage and the speed. This
implies with PWM we can have control over a motor’s speed, the speed being
proportional to the duty cycle. Using a pseudocode to show this:
24
Import GPIO library
If (RPi.GPIO is used) Set pin reference style
Assign state for output pins
Set PWM frequency
Assign value for duty cycle and initiate PWM
To step a stepper motor requires activating one pair of its coils [5]. This can be
achieved by commanding the driver to activate the line on which the coil is
attached. The pseudocode of a program to rotate a 4-coil stepper is shown below:
Servo motors are usually equipped with an onboard driver. This simplifies control
as the microcontroller only has to specify the position using PWM control signals
applied via the control wires, the duty cycle of the PWM determines what position
the servo motor will take. The pseudocode of a basic servo control program:
25
Import GPIO libraries
Set PWM output
Set duty cycle and initiate PWM
change the duty cycle (if necessary)
There are several GPIO libraries available but RPi.GPIO is the default package
provided on a Raspberry Pi. It contains classes to control the GPIO pins.
RPi.GPIO offers two pin reference styles: board numbering (BOARD) scheme in
which the pin numbers follow the numbers on header P1 i.e., pin 1, pin 2 and so
on [3]. There is also the Broadcom chip-specific (BCM) pin numbers where pin
numbers follow the lower-level numbering system defined by the Raspberry Pi’s
Broadcom-chip brain. Few RPi.GPIO library functions are given below:
26
solenoids. Motors and solenoids are ubiquitous in most embedded and automated
processes. In automatic lock systems for example, a stepper motor can be used to
swing the door open and close or retract the frames in case of sliding doors. Such is
common in access control systems. Access control systems usually require a form
of authentication or verification which is used to selectively grant access [12]. This
is usually based on evaluation of some form of credential such as passcode, radio
frequency identification tag (RFID) tag, biometrics etc.
Evaluating credentials would require interfacing with devices that transform the
credential into readable form known as readers, and also a database of authorized
credentials. When a credential is read and authenticated, the lock is activated and
the door opens. Electric locks are employed in such cases which internally consist
of relays and solenoids. Raspberry pi is capable of performing credential
evaluation as explained above and even controls the locks and automatically opens
the door. This will provide some cost-saving as a dedicated microcontroller won’t
be necessary. Everything can be done with the pi module!
27
SECTION FOUR
4.0 CONCLUSION AND RECOMMENDATION
4.1 CONCLUSION
Raspberry pi can be used to control motion actuators such as electric DC motors of
different types and also activate relays to control actuators. It all depends on how
to interface such devices with the Raspberry Pi board for control and also to ensure
that it is provided with adequate power to operate. A lot of factors come into play
when controlling motion actuators. First is the choice of a driver. It is assumed that
the choice of motor or solenoid is based on the application in which it is to be used.
After choosing a motor or solenoid, interfacing it with Raspberry Pi would require
using an appropriate driver. This means, using a driver that will supply the voltage
and current needs of the actuator. Most drivers such as the L293D can operate over
a voltage range (4.5V to 36V) [3]. However, care must be taken about the current
demand. It is better to choose a driver with a high current-sourcing ability so as to
reduce overheating.
The second important factor is choosing a GPIO library among the pool of
available libraries. RPi.GPIO offers great advantages but is not suitable for real
time applications. WiringPi is another GPIO access library. Modeled after the
Arduino wiring system, it tries to bring the simplicity of arduino wiring to
Raspberry Pi. It is written in C language. GPIO Zero is learner friendly and is best
for learning purposes. Some factors to consider when choosing a GPIO library are:
28
● Support system: Libraries with great support systems are usually advised,
since one may run into issues while working with a library.
● Speed: How fast are library functions executed?
4.2 RECOMMENDATION
Raspberry pi is a great tool for embedded projects but its ability to perform in time-
critical applications is still beneath that of microcontrollers such as Atmel chips
and Arduino boards. A great deal of software and hardware improvements is rather
solicited in this area especially due to the widespread use and availability of
Raspberry Pi.
29
REFERENCES
30