Hello In this chapter we will see 3 different
types of inputs digital inputs Analog inputs
and interrupt inputs using Arduino boards
or the PLCs based on Arduino both are recommended
to connect PNP sensors it means that the
PLC needs to read Voltaje to understand that
the signal is in High Level on the other
hand the analog inputs from the PLCs work
at the industrial standard from 0 to 10 Volts take the note that the Arduino Leonardo and
the arduino Mega work both at 5 Volts then it means that they have to receive 5V from
the sensors in the digital input on the other hand any analog signal connected directly
on the Arduino boards can work from 0 to 5 Volts… because the inputs from the Arduino
boards work at 10 bits what you can read
is a lineal value from 0 to 1023 now we will
see how the inputs work how they have to
be connected and how they have to be programed
first of all we will see how a sensor has
to be connected most of them have 3 wires
I don’t want less time in this video explaining all the possibilities of sensors but if you
have any question you can contact a tutor
by sending an email at course@industrialshields.com
and your individual tutor will answer your
questions ok a sensor has a cable called
SIGNAL this wire has to be connected on the input connector from the PLC it is the same
case for all types of sensors, analog or digital usually the sensors also have to be connected
at the power supply then they have to be
connected at the voltaje in industrial uses
it is usually connected at 24 Volts and at
the Ground or COM there are a lot of sensors
which can be connected from 12 to 24 Volts it is the same case we have on the PLC usually
on installation the power supply which is
powering the PLC at the same power supply
which is powering the sensors after connecting the PLC and the sensor at the power supply
all that remains is connect the signal wire
from the senros to the input pin on the PLC
now we will see how the digital signals work digital inputs have 2 states LOW state when
we read a 0 value on the program and HIGH level when we read 1 on the program it means
that when the sensor doesn't provide a signal the input is located in LOW state and when
the senros provide voltaje the input is in
HIGH level the analog inputs from industrial
sensors usually provide a signal from 0 to
10 Volts these sensors can not be connected
directly on the Arduino board because it works from 0 to 5 Volts but these sensors can be
connected directly on the Arduino Based PLCs the analog inputs have 10 bits it means that
we will read a value from 0 to 1023 the value read works as a lineal interpolation
it means that there is a constant reference between 0 volts and the 0 value we read and
10 volts and the 1023 value we read and for sure if we read 510 the input is receiving
5 volts as you can see on the picture we
can read all values and they can be fixed
independent from the time and we will read the same value if the input doesn’t change
on the other hand on the PLCs we have some input which work as a optoisolated it means
that the power supply connected to the PLC can be different than the power supply connected
to the sensor then it is necessary to connect the signal cable from the sensor to the input
pin but it is also necessary to connect the
negative cable from the sensor to the right
pin next to the input. It is usually used
on installation where you want to have separately
the main installation and the PLC finally
we will see how the interrupt inputs work
we can imagine that we have programmed a logical sequence and it is running… the code is
running in order as it is written and when
it is finalizing we start again and so on
then if we receive a signal from the interrupt input the running program is stopped immediately
and the PLC starts running the interrupt sequence after the execution of the interrupt sequence
the program continues at the same point where the program stopped before the interrupt signal
read these types of signals are used basically in inputs which we need to read as a priority
on the installation and the scan time is higher than the time required to read those signals
for example if we need to read a rotary encoder to count the number of revolutions from a
shaft we need to read all pulses and the
time between each other is higher than the
scan time from the PLC now we will see on the arduino IDE how a digital input
is read first of all we open the Arduino
IDE we see that the default file already
has a template where we have the void setup at the beginning to configure the different
signals and variables and the void loop at
the end where we will write the main code
executing the logic of the project ok here
we open the first example of digital input
doing click on file examples and in the
first section we have 01 – basics and we
open the example called READ SERIAL it is usually to read some comments at the beginning
of the program where we can read what the program does then after the comments we
declare all variables used on the program and after that these variables are configured
on the setup menú this example is interesting because we also have the serial port configured
because we want to read the input states on the serial monitor in the Arduino IDE it
is done using the sentence Serial.begin and the transmisión velocity between the PLC
and the laptop in this case we use 9600
bits per second on the setup menú
we also configure a variable called PUSHBUTTON as an INPUT because we want to define the
value as we have on the input after the configuration we add the main code on the void loop first
of all we read the input called as PUSHBUTTON and we save the current value on the BUTTONSTATE
variable…. then we send the current value
of this variable at the serial monitor using
the sentence SERIAL PRINTLN where between brackets we write the name of the variable
ok then if we upload the program on the Arduino based PLC we can read the value in the serial
monitor from the Arduino IDE. Well, the next interesting logic is what we can find on the
debounce example in the example 02- digital this example shows us how to add a filter
reading an input we also could use this example as a timer this filter let us to add a filter
in an input which will be understood as a
high level after the time defined on the filter
the first done in the program is define and
configure the variables into this example
the first thing done is to configure the input and the output this example is very interesting
because the first we found is a variable which is configured on the setup as the value red
from the input then the first thing the PLC
will do immediately after the powereing will
be define the value of this variable as the
current value from the input after the setup
configuration we can read the main program in the void loop the first thing to do is
reading the digital input then we start the
if sentence where the timer starts using the
millis sentence using that the timer starts
when the input changes the state from low
to HIGH level after a time defined as DEBOUNCE DELAY we change the state of the variable
defined at high level and we understand that the input is correctly read this example
is very interesting because some mechanisms can include some rebounds for example buttons
limit sensors of reed sensors to finalice
we have seen the state from inputs on the
serial monitor but we also can use some SCADA interfaz in fact we will see during the next
chapters how it is possible to include a basic SCADA interface on our projects which let
us do projects using the USB connector from the Arduino now we will see how an analog
input works we can open the example Analog Input from the 03 analog folder in the examples
menú in this example first of all we can
read some comments where we can read the analogRead()
sentence we will see in this example after the comments we can read how the variables
are defined and we can read the variable CALLED as SENSOR PIN which is defined from the A0
analog signal from the Arduino on the other hand we also define an output using the 13
pin from the Arduino on the setup we can read that it is only necessary to configure
the output because the analog signals are
automatically defined and it is not necessary
to define it again continuing to the program the first thing written in the void loop is
read the analog input and save the current state in the variable assigned that variable
will inform us the analog value from the input the analog inputs work at 10 bits then we
can read the signal from 0 to 10 23 In this
example we also include the name of the variable
inside the delay sentence because in this
case the time defined as a delay is depending
from the analog input today we have seen
2 timer functions the first one using the
Delay sentence and second one the MILLIS sentence in fact we don’t recommend using the Delay
sentence in industrial environments because the scan time is stopped while the delay sentence
is running we recommend using the millis
function because it is much easier to be controlled
anyway we only have to keep in mind the time before the sentence and compare it with the
value of the internal time during the sentence ok now we can show how the interrupt input
runs to know how the interrupt inputs work is very easy and we can see the sentence inside
the arduino webpage basicalle we can use the ATTACHINTERRUPT sentence searched on Arduino.org
first of all it is necessary to see the interrupt name for the right input because that number
is different from how the pins are called
working as a digital signal see the details
on from the Arduino Leonardo and Arduino Mega the interrupt input must be called inside
the void loop then it is possible to choose
different functions for example change the
current state receive a high state well
we can choose different options the sentence
asking for an interrupt input is Attachinterrupt and as you can see here there are different
ways to program it first of all we have to
be in mind that the logic done during the
interruption must be programmed outside of the void loop then when the attachinterrupt
function inside the void loop will be activated the code will stop and the interrupt logic
is going to start running each PLC has the indicated signals which can work as interrupt
functions we can also see in the silk-screened from the PLC using the Ardbox Relay one
of which we have shown during this chapter we can see on the maping map and we can also
see the interrupt identification of each pin on the other way we also have interrupt inputs
on the M-duino as you can see here into the industrial shields webpage it is easy to
identify the name of the interrupt choosing the pin available on the Arduino Mega you
can connect an interrupt input as you connect digital inputs there are different ways to
program interrupt inputs I would recommend you review how interrupt inputs can work
having a clear concept about how they work ok I wait for you in the next chapter
