This is the third chapter of the course Arduino
based PLC for industrial uses. During
this chapter we will see how different types
of outputs work. Digital outputs, PWM, and
Analog outputs also. We will see the relay
outputs during next chapters. Keep in mind
that on the chapter 4 we are going to see
the integration between an SCADA module using
processing and Inputs and outputs, analog
and digital from the Ardbox Relay. Ok. Let's
continue. To work with outputs it is necessary
to connect the PLC at the Power supply. The
PLCs have a plug connector with 2 pins where
you can connect Voltage and GND. All PLCs
can work from 12 to 24 Volts. Continuous volts.
Using an Arduino board the first thing is
connect the negative wire to the GND pins
which are marked and connect the positive
to the PIN where we can read the text VIN.
We recommend provide at the Arduino 7 volts
from the power supply. Using the Arduino Leonardo
and the Arduino Mega there isn’t any difference
about how to connect the power supply. After
connecting the power to the devices we are
ready to see how digital outputs work. The
outputs from the PLC and also from the Arduino
boards provide voltaje. It means that when
the outputs are in HIGH level the outputs
provide voltaje. First of all it is necessary
to connect the PLC at the power supply which
has to be powered from 12 to 24 Volts. Then
we can connect directly an output from the
PLC to the actuator. In this example, you
can see on the draw we have a representation
of a light to simplify the conexions on the
draw. As you can see the light have to be connected
at the negative from the same power supply
which provides voltaje at the PLC. Then, the
digital output from the PLC has to be connected
at the positive pin on the light. Sometimes
it is necessary to have optoisolated installations.
The PLCs have also some optoisolation outputs.
It means that the power supply which provides
voltaje at the PLC is not the same as the
power supply which provides voltaje at the
outputs. We can understand something like…
we have another power supply. Usually it happens
when the installation where we have to install
our new Project have to be separated from
our new PLC. And that installation provides
voltaje at the optoisolation outputs.. We
also have to connect the negative wire from
the installation at the common pin from the
optoisolation outputs from the PLC because
we need to connect the reference to avoid
problems of noise. There are a lot of installations
where it is necessary to join both electrical
parts. Then it is necessary to connect the
negative pin from the new Project, or new
power supply to the negative from the current
installation. Anyway with the PLC it is also
necessary to connect the common voltaje pin
and the common negative pin because put the
outputs running. At a summary. The arduino
assembled inside the PLC is optoisolated to
the industrial installation where it is installed.
As you can see, a digital output can be represented
as a switch ON or switch OFF where if you
program the output at a LOW state it means
that the output doesn’t provide voltaje
and programming the output at a HIGH state
it means that the output provides Voltage.
The voltaje provided is the same as we connect
the common voltaje from the isolated outputs.
All the PLCs let us connect this voltaje from
5 to 24 Volts. OK. Now we are ready to see
another type of digital output. This one is
called PWM and it provides a digital signal
working using high frequency. Basically, this
type of signals provide some pulses by a fixed
frequency provided by the Arduino board. Then
the time on a HIGH level can be configured.
Inside the PLCs we use the Arduino Leonardo
and Arduino mega, and these boards provide
a 8 bits signal. It represents that you can
adjust a value from 0 to 255. To program the
PWM signals is necessary to use the sentence
AnalogWrite(). As we can see on the graph
we understand that the 0 value doesn’t provide
any pulse at HIGH level. If we configure the
output at 125 the pulse is on HIGH level the
half of the cycle time. And if we configure
the output at 255 the output is on HIGH level
all the time. 100%. Our Arduino Based PLC
can use a PWM output as an analog output because
there are some signals designed to convert
the PWM signal at analog signal from 0 to
10 Volts. This is one of the most used industrial
standards working as an analog signal. There
is a lineal interpolation between 0 and 255
to 0 and 10 volts. This type of signal can
be used to adjust the velocity of a motor
powered by an invertir where if you adjust
the analog output from 0 to 10 Volts you can
go from a mínimum frequency and máximum
frequency of the motor. Ok. Now we will see
how to program this type of signals using
the Arduino IDE. It is important to crystal
clear these basic concepts. On the next chapter
you also use digital and analog signals connected
by the USB port from the Arduino Based PLC
or an original Arduino board to the laptop
and check the signals using the SCADA developed
under processing. Please, answer the questions
you can find in each chapter. It is important
to receive additional material to complete
the course and to connect the PLC to the SCADA
platform. You will see how easy it is to actívate
an output doing a click on the laptop. And
how you can see the current state from the
inputs immediately to check your installation.
To connect the PLC and the Graphical interface
we will use the serial port connecting the
USB cable. This kind of connection can be
also connected with other devices as GPS,
bar code readers, and others… OK. Let's
continue. How to program a digital output
using the Arduino IDE. First of all we can
open the example Blink from the example menú
in the 01 digital section. As usually, the
first thing we can read is a summary about
what the program does. It is really powerful
to write some comments on the projects you
do because. After some time it is not easy
to remember what the program done then…
if you can dedícate some tim to write a short
description about the functions of the program,
for sure it will a great helpful After the
comments we have the configuration. First
of all it is necessary to configure the right
pin as an output. Similar to what we saw last
week using inputs. After the configuration.
Inside the void loop section we write the
main code. In this case it is very simple
because we only use the sentence digitalWrite()
where we add the name of the output and the
state, LOW to deactivate and HIGH to actívate
the output. Seeing the blink example we also
see the delay() function. Remember that we
don’t recommend using this sentence in an
industrial Project. But it can simplify us
to a basic example of use. To program the
PWM we can open the example ANALOGWRITE MEGA
in the section ANALOG inside the examples
menú. In this example we can see the configuration
of the 13 PIN which lets Works as a PWM. There
are different pins from the Arduino board
capable of working as a PWM. You can read
from the Arduino Page the availables pins
and there is also a pin map on our arduino
based PLCs page where you can see which outputs
can work as an analog output and also as PWM
output. To connect PWM outputs you can see
how to connect digital outputs because it
is exactly the same. OK. This example shows
us how the 13 PIN is assigned to a variable.
And in the main code we also can see how the
sentence FOR Works to increase the value of
the variable using the code ++ written as
a consecutive. After the name of the variable
“brightness”, between the values where
the PWM outputs work. Which are from 0 to
255 because these signals work using 8 bits.
In this example we also see how to await 2
milliseconds using the sentence delay(). Ok.
It is usually to read a variable using the
serial monitor. Now we can open the example
ANALOGINOUTSERIAL from the 03-Analog section
inside the examples menú on the Arduino IDE.
This example shows us how to program a PWM
output depending on the state of the ANALOG
input. Here we print on the serial monitor
the analog input and PWM output values. To
do it first of all it is necessary to configure
the serial port at 9600bauts to ensure the
communication between the laptop and the Arduino
board inside the PLC. Reading the code we
see the sentence ANALOGREAD which was shown
last week. AND we also see the sentence MAP()
to do an interpolation between the value read
from the analog input which Works at 10 bits
where we read from 0 to 10 23. With the 8
bits available on the PWM outputs where we
write from 0 to 255. Using the MAP sentence
we can do the linear interpolation writing
only one line of code. Finally we define the
PWM value using the sentence ANALOGWRITE().
To print the value from different variables
using the serial port it is necessary to use
the sentence SERIAL …. Print. Which letus
on the one hand print a text wraited between
doublé quotation marks and also le tus to
print the value from different variables writing
the name of that variable. OK. After showing
this basic example about how to configure
and use variables assigned to digital and
analog outputs. We will see some basic concepts
we will use to program a Project using the
Arduino IDE: OK. We can Open the Arduino webpage
and read some sentences. I would like to comment
that there are 2 Arduino pages. The first
one is Arduino.cc and the other one is Arduino.org.
All sentences are available in both pages
going to the Reference Section from the learning
menú. The first thing we can read is the
STRUCTURE área. Where we have seen during
the previous chapters using the sentence void
loop and the void setup. All programs done
with the Arduino IDE have to include at least
these 2 parts. Opening each example from the
reference page on the Arduino webpage we can
also read some code used in the Arduino IDE
which let us understand how each stanceWorks.
We can read the sentences used in the previous
chapter so far. We can read the sentence MAP,
millis and delay(). The MAP sentence sabe
the values doing a linear interpolation between
mínimum value and máximum value from the
reference number to a mínimum value and a
máximum value on the interpolated scale.
This is exactly how we have seen today Reading
an analog input. On the other side we also
have seen the millis and delay sentence as
we have used in the previous chapters. I will
recommend you to review these sentences because
it will be very helpful during the next chapters.
And it is necessary to read and know how they
work. First off all you can start Reading
the Analog I/OS and see how boolean operations
Works. And of course how the sentences if,
or if else if Works. In the next chapter we
will connect a processing scada with the PLC
using serial communication between the Arduino
board inside the PLC and the Laptop. We will
use the sentence serial.print and serial.printLN
(which is used to change the line printed
on the serial monitor). We also will configure
the serial port using the serial.begin sentence
inside the setup Now and on the chapter will
be more productive. Then I will recommend
you to understand all previous concepts done
until now. Please, don’t forget to do some
practices if you need to understand some basic
concepts. And of course, you can contact with
a tutor sending an email at course@industrialshields.com.
On the next chapters we will connect some
motors, drivers, and communication ports.
See you in the next chapters!!!!
