Download as pdf or txt
Download as pdf or txt
You are on page 1of 91

SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

POWER SUPPLY

INTRODUCTION:

Almost all basic household electronic circuits need an unregulated AC to be converted to constant
DC, in order to operate the electronic device. All devices will have a certain power supply limit and the
electronic circuits inside these devices must be able to supply a constant DC voltage within this limit.
That is, all the active and passive electronic devices will have a certain DC operating point (Q-point or
Quiescent point), and this point must be achieved by the source of DC power. The DC power supply is
practically converted to each and every stage in an electronic system. Thus a common requirement for all
this phases will be the DC power supply. All low power system can be run with a battery. But, for long
time operating devices, batteries could prove to be costly and complicated. The best method used is in the
form of an unregulated power supply –a combination of a transformer, rectifier and a filter. The diagram
is shown below.

As shown in the figure above, a small step down transformer is used to reduce the voltage level to the
devices needs. In India, a 1 Ø supply is available at 230 volts. The output of the transformer is a pulsating
sinusoidal AC voltage, which is converted to pulsating DC with the help of a rectifier. This output is
given to a filter circuit which reduces the AC ripples, and passes the DC components. But here are certain
disadvantages in using an unregulated power supply.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 3


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Poor regulation:

When the load varies, the output does not appear constant. The output voltage changes by a great value
due to the huge change in current drawn from the supply. This is mainly due to the high internal
resistance of the power supply (>30 Ohms).

AC Supply Main Variations:

The maximum variations in AC supply mains is give or take 6% of its rated value . But this value may go
higher in some countries (180-280 volts). When the value is higher it’s DC voltage output will differ
largely.

Temperature Variation:

The use of semiconductor devices in electronic devices may cause variation in temperature.

These variations in dc output voltage may cause inaccurate or erratic operation or even malfunctioning of
many electronic circuits. For instance, in oscillators the frequency will shift, in transmitters output will
get distorted, and in amplifiers the operating point will shift causing bias instability.

All the above listed problems are overcome with the help of a voltage regulator which is employed in
conjunction with an unregulated power supply. Thus, the ripple voltage is largely reduced. Thus, the
supply becomes a regulated power supply.

The internal circuitry of a regulated power supply also contains certain current limiting circuits which
helps the supply circuit from getting fired from inadvertent circuits. Nowadays, all the power supplies
use IC’s to reduce ripples, enhance voltage regulation and for widened control options. Programmable
power supplies are also available to allow remote operation that is useful in many settings.

REGULATED POWER SUPPLY:

Regulated power supply is an electronic circuit that is designed to provide a constant dc voltage of
predetermined value across load terminals irrespective of ac mains fluctuations or load variations.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 4


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

As shown in the figure, the two main parts of a regulated power supply are a simple power supply and a
voltage regulating device. The power supply output is given as input to the voltage regulating device that
provides the final output. The voltage output of the power supply remains constant irrespective of large
variations in the input AC voltage or output load current.

Given below is a circuit diagram of a regulated power supply circuit using a transistor series regulator as
a regulating device The input AC voltage (230 Voltas Vrms), is supplied to a transformer. The output will
be a stepped down ac output appropriate for the desired dc output. This ac voltage is then given to a
bridge rectifier to produce a full-wave rectified output. This is then given to a pi-filter circuit to produce a
dc voltage. The filter output may have some ac voltage variations and ripples. This is further filtered
using a regulating circuit whose output will be a constant dc voltage. This regulated dc voltage is then
given to a voltage divider, which supplies the different dc voltages that may be needed for different
electronic circuits.

The potential divider is a single tapped resistor connected across the output terminals of the supply. The
tapped resistor may consist of two or three resistors connected in series across the supply. A bleeder
resistor may also be employed as a potential divider.

POWER SUPPLY CHARACTERISTICS:

The quality of the power supply is determined by various characteristics like load voltage, load
current, voltage regulation, source regulation, output impedance, ripple rejection, and so on. Some of the
characteristics are briefly explained below.

Load Regulation:

The load regulation or load effect is the change in regulated output voltage when the load current changes
from minimum to maximum value.

Load regulation = Vno-load – Vfull-load

Vno-load – Load Voltage at no load

Vfull-load – Load voltage at full load.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 5


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

From the above equation we can understand that when Vno-load occurs the load resistance is infinite, that
is, the out terminals are open circuited. Vfull-load occurs when the load resistance is of the minimum
value where voltage regulation is lost.

% Load Regulation = [(Vno-load – Vfull-load)/Vfull-load] * 100

Minimum Load Resistance:

The value of I full-load, full load current should never increase than that mentioned in the data sheet of
the power supply.

Source/Line Regulation:

In the block diagram, the input line voltage has a nominal value of 230 Volts but in practice, there are
considerable variations in ac supply mains voltage. Since this ac supply mains voltage is the input to the
ordinary power supply, the filtered output of the bridge rectifier is almost directly proportional to the ac
mains voltage.

The source regulation is defined as the change in regulated output voltage for a specified rage of line
voltage.

Output Impedance:

A regulated power supply is a very stiff dc voltage source. This means that the output resistance is very
small. Even though the external load resistance is varied, almost no change is seen in the load voltage. An
ideal voltage source has an output impedance of zero.

Ripple Rejection:

Voltage regulators stabilize the output voltage against variations in input voltage. Ripple is equivalent to
a periodic variation in the input voltage. Thus, a voltage regulator attenuates the ripple that comes in with
the unregulated input voltage. Since a voltage regulator uses negative feedback, the distortion is reduced
by the same factor as the gain.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 6


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

DC POWER SUPPLY:

An AC powered unregulated power supply usually uses a transformer to convert the voltage from the
wall outlet (mains) to a different, nowadays usually lower, voltage. If it is used to produce DC, a rectifier
is used to convert alternating voltage to a pulsating direct voltage, followed by a filter, comprising one or
more capacitors, resistors, and sometimes inductors, to filter out (smooth) most of the pulsation. A small
remaining unwanted alternating voltage component at mains or twice mains power frequency (depending
upon whether half- or full-wave rectification is used)—ripple—is unavoidably superimposed on the
direct output voltage. For purposes such as charging batteries the ripple is not a problem, and the simplest
unregulated mains-powered DC power supply circuit consists of a transformer driving a single diode in
series with a resistor. Before the introduction of solid-state electronics, equipment used valves (vacuum
tubes) which required high voltages; power supplies used step-up transformers, rectifiers, and filters to
generate one or more direct voltages of some hundreds of volts, and a low alternating voltage for
filaments. Only the most advanced equipment used expensive and bulky regulated power supplies.

Transformer:

A transformer is a static electrical device that transfers energy by inductive coupling between its winding
circuits. A varying current in the primary winding creates a varying magnetic flux in the transformer's
core and thus a varying magnetic flux through the secondary winding. This varying magnetic flux
induces a varying electromotive force (EMF) or voltage in the secondary winding. Transformers range in
size from thumbnail-sized used in microphones to units weighing hundreds of tons interconnecting the
power grid. A wide range of transformer designs are used in electronic and electric power applications.
Transformers are essential for the transmission, distribution, and utilization of electrical energy.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 7


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Fig: Transformer

Rectifier:

A rectifier is an electrical device that converts alternating current (AC), which periodically reverses
direction, to direct current (DC), which flows in only one direction. The process is known as rectification.
Physically, rectifiers take a number of forms, including vacuum tube diodes, mercury-arc valves, copper
and selenium oxide rectifiers, solid-state diodes, silicon-controlled rectifiers and other silicon-based
semiconductor switches. Historically, even synchronous electromechanical switches and motors have
been used. Early radio receivers, called crystal radios, used a "cat's whisker" of fine wire pressing on a
crystal of galena (lead sulfide) to serve as a point-contact rectifier or "crystal detector". Rectifiers have
many uses, but are often found serving as components of DC power supplies and high-voltage direct
current power transmission systems. Rectification may serve in roles other than to generate direct current
for use as a source of power. As noted, detectors of radio signals serve as rectifiers. In gas heating
systems flame rectification is used to detect presence of flame. The simple process of rectification
produces a type of DC characterized by pulsating voltages and currents (although still unidirectional).
Depending upon the type of end-use, this type of DC current may then be further modified into the type
of relatively constant voltage DC characteristically produced by such sources as batteries and solar cells.
A more complex circuitry device which performs the opposite function, converting DC to AC, is known
as an inverter.

• Single-phase rectifiers

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 8


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

• Half-wave rectification

• Full-wave rectification

Filter Capacitor:

Filter capacitors are capacitors used for filtering of undesirable frequencies. They are common in
electrical and electronic equipment, and cover a number of applications, such as:

• Glitch removal on Direct current (DC) power rails

• Radio frequency interference (RFI) removal for signal or power lines entering or leaving equipment

• Capacitors used after a voltage regulator to further smooth dc power supplies

• Capacitors used in audio, intermediate frequency (IF) or radio frequency (RF) frequency filters (e.g. low
pass, high pass, notch, etc.)

• Arc suppression, such as across the contact breaker or 'points' in a spark-ignition engine

Filter capacitors are not the same as reservoir capacitors, the tasks the two perform are different, albeit
related The simple capacitor filter is the most basic type of power supply filter. The application of the
simple capacitor filter is very limited. It is sometimes used on extremely high-voltage, low-current power
supplies for cathode-ray and similar electron tubes, which require very little load current from the supply.
The capacitor filter is also used where the power-supply ripple frequency is not critical; this frequency
can be relatively high. The capacitor (C1) shown in figure 4-15 is a simple filter connected across the
output of the rectifier in parallel with the load

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 9


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Fig: Capacitor

Resistor:

A resistor is a passive two terminal electrical component that implements electrical resistor as a circuit
element. The current through a resistor is in direct proportion to the voltage across the resistor's terminals.
This relationship is represented by Ohm's law. where I is the current through the conductor in units of
amperes V is the potential difference measured across the conductor in units of volts and R is the
resistance of the conductor in units of ohm .The ratio of the voltage applied across a resistor's terminals to
the intensity of current in the circuit is called its resistance, and this can be assumed to be a constant
(independent of the voltage) for ordinary resistors working within their ratings. Resistors are common
elements of electrical networks and electronic circuits and are ubiquitous in electronic equipment.
Practical resistors can be made of various compounds and films, as well as resistance wire (wire made of
a high-resistivity alloy, such as nickel-chrome). Resistors are also implemented within integrated circuits
particularly analog devices, and can also be integrated into hybrid and printed circuits. The electrical
functionality of a resistor is specified by its resistance: common commercial resistors are manufactured
over a range of more than nine orders of magnitude. When specifying that resistance in an electronic
design, the required precision of the resistance may require attention to the manufacturing tolerance of
the chosen resistor, according to its specific application. The temperature coefficient of the resistance
may also be of concern in some precision applications. Practical resistors are also specified as having a
maximum power rating which must exceed the anticipated power dissipation of that resistor in a
particular circuit: this is mainly of concern in power electronics applications. Resistors with higher power
ratings are physically larger and may require heat sinks. In a high-voltage circuit, attention must
sometimes be paid to the rated maximum working voltage of the resistor. Practical resistors have a series
inductance and a small parallel capacitance; these specifications can be important in high-frequency
applications. In a low-noise amplifier or pre-amp, the noise characteristics of a resistor may be an issue.
The unwanted inductance, excess noise, and temperature coefficient are mainly dependent on the
technology used in manufacturing the resistor. They are not normally specified individually for a
particular family of resistors manufactured using a particular technology. A family of discrete resistors is

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 10


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

also characterized according to its form factor, that is, the size of the device and the position of its leads
(or terminals) which is relevant in the practical manufacturing of circuits using them.

Fig: Resistor

Voltage Regulator:

A voltage regulator is designed to automatically maintain a constant voltage level. A voltage regulator
may be a simple "feed-forward" design or may include negative feedback control loops. It may use an
electromechanical mechanism, or electronic components. Depending on the design, it may be used to
regulate one or more AC or DC voltages. Electronic voltage regulators are found in devices such as
computer power supplies where they stabilize the DC voltages used by the processor and other elements.
In automobile alternators and central power station generator plants, voltage regulators control the output
of the plant. In an electric power distribution system, voltage regulators may be installed at a substation
or along distribution lines so that all customers receive steady voltage independent of how much power is
drawn from the line.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 11


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Fig: Voltage Regulator

TEMPERATURE AND HUMIDITY MODULE DHT11

INTRODUCTION:

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 12


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

DHT11 digital temperature and humidity sensor is a calibrated digital signal output of the temperature
and humidity combined sensor. It uses a dedicated digital modules capture technology and the
temperature and humidity sensor technology to ensure that products with high reliability and excellent
long-term stability. Sensor includes a resistive element and a sense of wet NTC temperature measurement
devices and with a high-performance 8-bit microcontroller connected.

DHT11 output calibrated digital signal. It utilizes exclusive digital-signal-collecting-technique and


humidity sensing technology, assuring its reliability and stability. Its sensing elements are connected with
8-bit single-chip computer. Every sensor of this model is temperature compensated and calibrated in
accurate calibration chamber and the calibration-coefficient is saved in OTP memory. Small size & low
consumption & long transmission distance (20m) enable DHT11 to be suited in all kinds of harsh
application occasions. Single-row packaged with four pins, making the connection very convenient.

Technical Specification:

MODEL DHT11

Power supply 3-5.5V DC

Output signal digital signal via single-bus

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 13


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Sensing element Polymer resistor

Measuring range humidity 20-90%RH; temperature 0-50 Celsius

Accuracy humidity +-4%RH (Max +-5%RH); temperature +-


2.0Celsius

Resolution or sensitivity humidity 1%RH; temperature 0.1Celsius

Repeatability humidity +-1%RH; temperature +-1Celsius

Humidity hysteresis +-1%RH

Long-term Stability +-0.5%RH/year

Sensing period Average: 2s

Interchangeability fully interchangeable

Dimensions size 12*15.5*5.5mm

Dimensions: (unit----mm):

Front view Back view Side view

Applications:

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 14


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

HVAC, dehumidifiers, testing and inspection equipment, consumer goods, automotive,


automation, data loggers, weather stations, home appliances, humidity regulator, medical and other
relevant humidity measurement and control.

Typical circuit:

Connecting the typical application circuit shown above the microprocessor and DHT11, DATA pull-up
and microprocessor I/O port. 1. A typical application circuit recommended cable length shorter than 20
meters with a 5.1K pull-up resistor when greater than 20 meters when the pull-up resistor to reduce the
actual situation. 2. When using a 3.3V voltage supply cable length must not be greater than 100cm.
Otherwise it will lead to lack of line drop sensor supply, causing measurement bias. 3. Temperature and
humidity values are read out every last measurement result, want to get real-time data, to be read twice in
a row, but not recommended repeatedly read sensors, each sensor reading interval of more than 5 seconds
to obtain accurate data.

Serial Communications Description (single-wire bidirectional):

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 15


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Single Bus Description:

DHT11 device uses a simplified single-bus communication. Single bus that only one data line, the data
exchange system, are controlled by a single bus is complete. Device (master or slave) through an open-
drain or tri-state port is connected to the data line to allow the device to send data when not able to
release the bus, and let other devices use the bus; single bus usually requires an external approximately
5.1kΩ pull up resistor, so that when the bus is idle, the state is high. Because they are master-slave
structure, only the host calls a slave, a slave to answer, so the host access devices must strictly follow the
sequence of a single bus, if there is a sequence of confusion, the device will not respond to the host

Single bus transfer data bit definition:

DATA is used for communication between the microprocessor and DHT11 and synchronization, single-
bus data format, a 40-bit data transfer, high first-out. Data formats: 8bit humidity integer data + 8bit
decimal data +8 bit temperature and humidity data + 8bit temperature decimal integer data +8 bit parity
bit.

Parity bit data definition:

"8bit humidity decimal integer data + 8bit humidity temperature data +8 bit decimal integer data + 8bit
temperature data" 8bit parity bit is equal to the result of the end of eight.

Example One:40 receives the data to:

0011 0101 0000 0000 0001 1000 0000 0000 0100 1101

High humidity 8 Low humidity 8 High temperature 8 Low temperature 8 Parity bit

Calculated as follows:

0011 0101+0000 0000+0001 1000+0000 0000= 0100 1101

Receive data is correct:

Humidity: 0011 0101=35H=53%RH

Temperature:0001 1000=18H=24℃

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 16


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Example Two: The received data is 40:

0011 0101 0000 0000 0001 1000 0000 0000 0100


1001

High humidity 8 High humidity 8 High temperature 8 High temperature 8 Parity bit

Calculated as follows:

0011 0101+0000 0000+0001 1000+0000 0000= 0100 1101 01001001 is not equal to 01001101

The received data is not correct, give up, again receiving data.

Data Timing Diagram:

Hosts (MCU) after sending a start signal, DHT11 transition from a low-power mode to high-speed mode,
the host until after the end of the start signal, DHT11 send a response signal, send 40bit data acquisition
and trigger a letter. Signal transmission shown in fig.

Fig: Data timing Diagram

Note:

The host reads temperature and humidity data from DHT11 always previous measurements, such as the
two measured time interval is long, please read twice in a row is the second time in real time temperature
and humidity values.

Peripheral reading step:

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 17


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Communication between master and slave can be completed by the following steps (peripherals
(such as a microprocessor) to read step DHT11 data). Step one: DHT11 after power (power after DHT11
1S to wait to cross the unstable state during this period can’t send any commands), test environment
temperature and humidity data, and record data while the data lines DATA DHT11 pulled by a pull-up
resistor remains high; DHT11 this time the DATA pin is the input state, always detect external signals.
Step two: Microprocessor I / O output while the output is set to low, and low retention time can’t be less
than 18ms, then the microprocessor I / O is set to enter the state, due to the pull-up resistor, the
microprocessor I / O that the data lines DHT11 also will go high, waiting to answer DHT11 signals
transmitted signal as shown:

Step three:

DHT11 the DATA pin when external signals detected low, waiting for the external signal low end, after a
delay DHT11 the DATA pin is an output, the output low as 80 microseconds response signal, followed
by the output of 80 micro-notify the second high peripheral is ready to receive data, the microprocessor I
/ O at this time in the input state detecting I / O with low (DHT11 echo signal) to the wait for 80
microseconds high data receiving and sending signals as shown:

Step four:

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 18


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

The 40 bit data output by the DHT11 DATA pin, the microprocessor according to the change of I/O level
receive 40 bits of data, a data format of "0": high level and low level of 50 microseconds and 26-28
microsecond, format data "1": low level 50 microsecond plus 70 microsecond high. Bit data "0", "1"
format signal as shown in fig:

End signal:

DHT11 the DATA pin output 40-bit data, the continued output low 50 microseconds after the entry into
the state, due to the pull-up resistor attendant goes high. But DHT11 temperature and humidity inside the
test-retest data, and record the data, awaiting the arrival of an external signal.

Application Information:

Working and storage conditions:

The proposed scope of work may result in up to 3% RH temporary drift of the signal. Return to normal
working conditions, the sensor calibration status will slowly recover. To speed up the recovery process
can be found in "recovery process." The use of the product will accelerate the aging process for a long
time under abnormal operating conditions. Avoid placing components on a long-term condensation and
dry conditions and the following environments.

A. smoke
B. B. Acid or oxidizing gases such as sulfur dioxide, hydrochloric acid Recommended Storage
Environment Temperature:10~40℃ Humidity:60% RH or less

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 19


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Effects of exposure to chemical substances:

Sensing resistive humidity sensor will be disturbed chemical vapor layer, the diffusion layer in the
induction of chemicals may cause drift and measurement sensitivity. In a clean environment, slowly
release contaminants out. The recovery process described below to accelerate the process. High
concentrations of chemical pollution can cause damage to the sensor sensing layer completely.

Temperature Effect:

Relative humidity of the gas is largely dependent on temperature. Therefore, when measuring the
humidity should be possible to ensure that the humidity sensor works at the same temperature. If you
share a printed circuit board with electronic components heat released in the sensor should be installed as
far as possible away from the electronic components, and installed at the bottom of the heat source, while
maintaining a well-ventilated enclosure. To reduce the thermal conductivity sensor and a copper plating
layer of the printed circuit board should be as minimal other portions, and leaving a gap between them.

Light effects:

Prolonged exposure to sunlight or strong ultraviolet radiation will reduce performance.

Recovery process:

Placed under extreme operating conditions or chemical vapor sensors, through the following process, you
can return it to the state calibration. 45 ℃ and humidity under 70% RH conditions were maintained for
more than 5 hours.

Wiring Precautions:

DATA signal wire quality will affect the communication distance and communication quality, we
recommend using a high-quality shielded cable.

Soldering Information:

Manual welding, at a temperature of 300 ℃ maximum contact time must be less than 10 seconds.

MQ2 GAS SENSOR MODULE

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 20


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

INTRODUCTION:

MQ2 gas sensor can be used to detect the presence of LPG, Propane and Hydrogen, also could be used to
detect Methane and other combustible steam, it is low cost and suitable for different application. Sensor
is sensitive to flammable gas and smoke. Smoke sensor is given 5 volt to power it. Smoke sensor
indicates smoke by the voltage that it outputs .More smoke more output. A potentiometer is provided to
adjust the sensitivity. Sn02 is the sensor used which is of low conductivity when the air is clean. But
when smoke exist sensor provides an analog resistive output based on concentration of smoke. The
circuit has a heater. Power is given to heater by VCC and GND from power supply. The circuit has a
variable resistor. The resistance across the pin depends on the smoke in air in the sensor. The resistance
will be lowered if the content is more. And voltage is increased between the sensor and load resistor.

Fig: MQ2 Gas sensor Module

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 21


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Board Schematic:

Features:

1. Wide detecting scope


2. High sensitivity and fast response
3. Long life and stable
4. Simple drive circuit

Due to its fast response time and high sensitivity, measurements can be taken as soon as possible. The
sensor sensitivity can be adjusted by using the potentiometer.

Applications:

They are useful in gas leakage detection of LPG, propane, methane, i-butane, alcohol, Hydrogen, and
smoke.

 Safety of home
 Control of air quality
 Measurement of gas level

Specifications:

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 22


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

 Power Supply: 4.5V to 5V DC


 High sensitivity to Propane, Smoke, LPG and Butane
 Wide range high sensitivity to Combustible gases
 Long life and low cost
 Analog and Digital output available
 Onboard visual indicator (LED) for indicating alarm
 Compact design and easily mountable
 Simple 4 PIN header interface
 Drive circuit is simple.
 Sensor Type : Semiconductor
 Concentration: 300-10000ppm ( Combustible gas)
 Supply voltage =5v

Working Principle:

The MQ2 has an electrochemical sensor, which changes its resistance for different concentrations of
varied gasses. The sensor is connected in series with a variable resistor to form a voltage divider circuit
(Fig 1), and the variable resistor is used to change sensitivity. When one of the above gaseous elements
comes in contact with the sensor after heating, the sensor’s resistance changes. The change in the
resistance changes the voltage across the sensor, and this voltage can be read by a microcontroller. The
voltage value can be used to find the resistance of the sensor by knowing the reference voltage and the
other resistor’s resistance. The sensor has different sensitivity for different types of gasses. The
sensitivity characteristic curve (Fig 2) is shown below for the different type of gases.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 23


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Where,
1.Ro is the resistance of the sensor in clean air

2. Rs is the resistance of the sensor when exposed to gases

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 24


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Procedure to Calculate the Concentration of a Particular Type of Gas

To find the concentration of gas, two values has to be measured using a microcontroller with ADC such
as Arduino,

1. Ro–The resistance of the sensor when measured in clean air,


2. Rs – The resistance of the sensor when it is exposed to any of the mentioned gasses
To find Ro, connect the sensor to one of the Analog pins of Arduino, note 100 values, and select the
median value. This will reduce if any dynamic errors present in the values. The sensor is connected in the
series with a variable resistor (Potentiometer on the sensor board). So, to find the resistance of the sensor
(Ro or Rs), the resistance of the variable resistor (R1) is required. In most of the MQ2 sensor modules,
any one end of the potentiometer and the middle pin of potentiometer will be connected between Sig or
Vout Pin and Ground. Find the resistance of R1 using a multimeter and note it down.

The voltage across the sensor Vs (Vs is Vo in Clean Air) is calculated by using the following formula:

Vs=VRef – ADC_Value * (VRefH-VRefL)/ (2R)

Where,
VRefH is the higher Reference voltage of the ADC, in Arduino, it is usually 5V or 3.3V
VRefL is the lower reference voltage of the ADC, in Arduino, it is usually 0V
R is the resolution of the ADC, in most of the Arduino boards, it is 10 Bits

Once the voltage across the sensor and value of R1 is known, the resistance of the sensor can be
calculated by using the formula

Ro=R1 Vo/ (VRef-Vo)

Where Vo is the voltage across the sensor in clean Air

Similarly, the Resistance of the sensor when exposed to gas can be calculated by repeating the above
steps and using the formula

Rs=R1 Vs / (VRef-Vs)

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 25


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Where Vs is the voltage across the sensor in the Air contaminated with LPG molecules

Note: The value of R1 is only for finding the value of Rs and Ro. For finding the concentration of gas,
R1 is not required as the concentration is dependent on the Rs/Ro ratio. R1 is not required for finding just
the ratio.

Finding the Concentration of a Gas:

The concentration of a gas can be calculated by measuring the sensor’s Ro and Rs values and using the
following formula

Concentration = Xo (Y/ Yo) Φ

Where Φ is the slope, which can be found using the Sensitivity Characteristic curve and the following
formula

Φ = Log (Y2/Y1) / Log(X2/X1)

Where (X2, Y2) and (X1, Y1) are any two points on a section (lines between indicated points on the
curve) of the curve. Since the curve has different slopes at different concentrations the (X2, Y2) and (X1,
Y1) values should be taken from the corresponding sections

The Xo and Yo values are Initial Concentration and Rs/Ro ratio on a section of the curve (lines between
marked points), these values are the starting points of each section ( each line between marked points has
different slopes) Y is the Rs/Ro ratio for the current concentration of the gas

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 26


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

FIRE SENSOR

A sensor which is most sensitive to a normal light is known as a flame sensor. That’s why this sensor
module is used in flame alarms. This sensor detects flame otherwise wavelength within the range of 760
nm – 1100 nm from the light source. This sensor can be easily damaged to high temperature. So this
sensor can be placed at a certain distance from the flame. The flame detection can be done from a 100cm
distance and the detection angle will be 600. The output of this sensor is an analog signal or digital signal.
These sensors are used in fire fighting robots like as a flame alarm.

What is a Flame Sensor?

A flame-sensor is one kind of detector which is mainly designed for detecting as well as responding to
the occurrence of a fire or flame. The flame detection response can depend on its fitting. It includes
an alarm system, a natural gas line, propane & a fire suppression system. This sensor is used in industrial
boilers. The main function of this is to give authentication whether the boiler is properly working or not.
The response of these sensors is faster as well as more accurate compare with a heat/smoke detector
because of its mechanism while detecting the flame.

Working Principle:
This sensor/detector can be built with an electronic circuit using a receiver like electromagnetic radiation.
This sensor uses the infrared flame flash method, which allows the sensor to work through a coating of
oil, dust, water vapor, otherwise ice.

Flame Sensor Module:


The pin configuration of this sensor is shown below. It includes four pins which include the following.
When this module works with a microcontroller unit then the pins are

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 27


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

 Pin1 (VCC pin): Voltage supply rages from 3.3V to 5.3V


 Pin2 (GND): This is a ground pin
 Pin3 (AOUT): This is an analog output pin (MCU.IO)
 Pin4 (DOUT): This is a digital output pin (MCU.IO)

Different Types

Flame-sensors are classified into four types


 IR single frequency
 IR multi-spectrum
 UV flame detectors
 UV/ IR flame detectors
Features & Specifications
The features of this sensor include the following.
 Photosensitivity is high
 Response time is fast
 Simple to use
 Sensitivity is adjustable
 Detection angle is 600,
 It is responsive to the flame range.
 Accuracy can be adjustable
 Operating voltage of this sensor is 3.3V to 5V
 Analog voltage o/ps and digital switch o/ps

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 28


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

 The PCB size is 3cm X 1.6cm


 Power indicator & digital switch o/p indicator
 If the flame intensity is lighter within 0.8m then the flame test can be activated, if the flame intensity
is high, then the detection of distance will be improved.

Applications

These sensors are used in several dangerous situations which include the following.
 Hydrogen stations
 Industrial heating
 Fire detection
 Fire alarm
 Fire fighting robot
 Drying systems
 Industrial gas turbines
 Domestic heating systems
 Gas-powered cooking devices

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 29


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

ESP-12E Wi-Fi MODULE (ESP8266)

INTRODUCTION:

ESP-12E Wi-Fi module is developed by Ai-thinker Team. core processor ESP8266 in smaller
sizes of the module encapsulates Tensilica L106 integrates industry-leading ultra low power 32-bit MCU
micro, with the 16-bit short mode, Clock speed support 80 MHz, 160 MHz, supports the RTOS,
integrated Wi-Fi MAC/BB/RF/PA/LNA, on-board antenna. The module supports standard IEEE802.11
b/g/n agreement, complete TCP/IP protocol stack. Users can use the add modules to an existing device
networking, or building a separate network controller. ESP8266 is high integration wireless SOCs,
designed for space and power constrained mobile platform designers. It provides unsurpassed ability to
embed Wi-Fi capabilities within other systems, or to function as a standalone application, with the lowest
cost, and minimal space requirement.

ESP8266EX offers a complete and self-contained Wi-Fi networking solution; it can be used to host
the application or to offload Wi-Fi networking functions from another application processor. When
ESP8266EX hosts the application, it boots up directly from an external flash.

ESP8266EX is among the most integrated Wi-Fi chip in the industry; it integrates the antenna
switches, RF balun, power amplifier, low noise receive amplifier, filters, power management modules, it
requires minimal external circuitry, and the entire solution, including front-end module, is designed to
occupy minimal PCB area

Figure: ESP8266-12E

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 30


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

The ESP8266 has seen a wide adoption as a cost-effective solution for IOT and Wi-Fi-capable devices.
The ESP8266 was developed by Shangai-based Espressif systems, as a Serial (UART) to Wi-Fi SoC
(System on a Chip) based around a Tensilica Xtensa LX3DPU. This tiny IC includes an RF front end,
RAM, and (usually) an onboard TCP/IP stack that allows it ready to connect to a nearby Access Point, to
act as an Access Point itself, or both.

Family of Breakout Boards (ESP-NN):

Quickly after launch, a variety of breakout boards for the ESP8266 started becoming available.
The most popular ones have been the ESP-NN series, which typically integrate the SOC along with Flash
RAM, a crystal, and even an onboard antenna. The most salient distinction between different ESP-NN
models are the pins that are broken out from the ESP8266

As the ESP8266 was developed as a Serial to Wi-Fi adapter, its firmware implemented an interpreter for
AT commands. Thus initial usage of the IC was limited to using a either a USB to Serial adapter, or a
separate microcontroller (e.g., ATmega328) to issue AT commands over the ESP8266's Serial UART
interface. For this reason, the ESP-01 board quickly became popular amongst the ESP8266 community
because of its 2×4, 0.1in-pitch connector that can be easily wired to a USB to Serial adapter.

The connector gave access to the pins used for serial communication, namely RX and TX, as well as 4
control pins, GPIO0, GPIO2, CH_PD and RST (reset), along with VCC and GND.

However, other ESP-NN boards offer access to a wider variety of pins, although their packaging is of a
custom Surface-Mount Device, with castellated pins as seen in the documentation page linked above.
From the different ESP-NN boards, we began to experiment with the ESP-12E. The main reason is that
this module was the one chosen by the developers of the Node MCU project for their hardware Dev Kit
1.0

Because the ESP8266 provides a cost-effective solution to the rapidly growing market of internet-
connected projects and devices (i.e., the so-called Internet of Things), it has become one of the most
popular development platforms over the past year and a half. In consequence, a dedicated community has
formed around the platform which has been focused on improving its functionality.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 31


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

For starters, different firmware options have been ported to run on the ESP8266, effectively taking it
from a simple Serial to Wi-Fi adapter into a fully functional microcontroller with access to its GPIO and
hardware-based functions like PWM, I2C, 1-Wire communication, and ADC; all this, of course, in
addition to maintaining its Wi-Fi capabilities.

Features:

• 802.11 b/g/n

• Integrated low power 32-bit MCU

•Integrated 10-bit ADC

• Integrated TCP/IP protocol stack

• Integrated TR switch, balun, LNA, power amplifier and matching network

• Integrated PLL, regulators, and power management units

• Supports antenna diversity

• Wi-Fi 2.4 GHz, support WPA/WPA2

• Support STA/AP/STA+AP operation modes

• Support Smart Link Function for both Android and IOS devices

• Support Smart Link Function for both Android and iOS devices

• SDIO 2.0, (H) SPI, UART, I2C, I2S, IRDA, PWM, GPIO

• STBC, 1x1 MIMO, 2x1 MIMO

• A-MPDU & A-MSDU aggregation and 0.4s guard interval Shenzhen Anxinke Technology

• Deep sleep power < 5uA

• Wake up and transmit packets in < 2ms

• Standby power consumption of < 1.0mW (DTIM3)

• +20dBm output power in 802.11b mode • Operating temperature range -40C ~ 125C

Applications:

 Smart power plugs

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 32


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

 Home automation
 Mesh network
 Industrial wireless control
 Baby monitors
 IP Cameras
 Sensor networks
 Wi-Fi location-aware devices
 Security ID tags
 Wi-Fi position system beacons

AT Commands:

Command Description

AT Test AT start up

AT+RST Restart module

AT+GMR View version Info

AT+GSLP Enter deep sleep mode

ATE AT commands echo or not

AT+RESTORE Factory Reset

AT+UART UART Configuration

AT+UART_CUR UART current configuration

AT+UART_DEF UART default configuration, save to flash

AT+SLEEP Sleep mode

AT+RFPOWER Set maximum value of RF TX power

AT+RFVVD RF TX power according to VDD33

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 33


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

A few different firmware options are available for the ESP8266. These allow us to access the module in
different ways, as you can see below.

AT Command Processor (Default):

The quickest way to get started with the ESP8266 is to use its original firmware, which allows it to
process any AT commands that it receives over its Serial UART interface. The biggest advantage of this
option is that we need not be familiar with any specific language or framework to use the module. We
can simply send it a series of commands to achieve our goal. The downside to this is that we need either
an additional microcontroller involved or a USB to Serial adapter to send the necessary commands.

Whereas the AT commands are the standard way of communicating with wireless-capable ICs (e.g.,
Bluetooth, Wi-Fi, GSM), they pose the limitation of needing another module to run the application that
specifies these commands accordingly. However, if we could run the application within
the ESP8266 itself then we'd have everything self-contained by a single IC. Fortunately, Espressif made
a Software Development Kit (SDK) available that allowed users to flash different firmware options.

ESP-12E Pin design:

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 34


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Pin Descriptions:

NO. Pin Name Function

1 RST Reset the module

2 ADC A/D Conversion result. Input voltage range 0-1v,scope:0-1024

3 EN Chip enable pin. Active high

4 IO16 GPIO16; can be used to wake up the chipset from deep sleep
mode.

5 IO14 GPIO14; HSPI_CLK

6 IO12 GPIO12; HSPI_MISO

7 IO13 GPIO13; HSPI_MOSI; UART0_CTS

8 VCC 3.3V power supply (VDD)

9 CS0 Chip selection

10 MISO Salve output Main input

11 IO9 GPIO9

12 IO10 GBIO10

13 MOSI Main output slave input

14 SCLK Clock

15 GND GND

16 IO15 GPIO15; MTDO; HSPICS; UART0_RTS

17 IO2 GPIO2; UART1_TXD

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 35


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

18 IO0 GPIO0

19 IO4 GPIO4

20 IO5 GPIO5

21 RXD UART0_RXD; GPIO3

22 TXD UART0_TXD; GPIO1

Table: Pin mode

Mode GPIO15 GPIO0 GPIO2

UART Low Low High

Flash Boot Low High High

Table: Dimension of ESP-12E Wi-Fi Module

Length Width Height PAD Pin Pitch


Size(Bottom)

16 mm 24mm 3 mm 0.9 mm x 1.7 mm 2mm

Functional Descriptions:

MCU:

ESP8266EX is embedded with Tensilica L106 32-bit micro controller (MCU), which features extra low
power consumption and 16-bit RSIC. The CPU clock speed is 80MHz. It can also reach a maximum
value of 160MHz. ESP8266EX is often integrated with external sensors and other specific devices
through its GPIOs; codes for such applications are provided in examples in the SDK.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 36


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Memory Organization:

Internal SRAM and ROM:

ESP8266EX Wi-Fi SOC is embedded with memory controller, including SRAM and ROM. MCU can
visit the memory units through iBus, dBus, and AHB interfaces. All memory units can be visited upon
request, while a memory arbiter will decide the running sequence according to the time when these
requests are received by the processor. According to our current version of SDK provided, SRAM space
that is available to users is assigned as below:

▪ RAM size < 36kB, that is to say, when ESP8266EX is working under the station mode and is connected
to the router, programmable space accessible to user in heap and data section is around 36kB.)

▪ There is no programmable ROM in the SOC, therefore, user program must be stored in an external SPI
flash.

External SPI Flash:

This module is mounted with an 4 MB external SPI flash to store user programs. If larger definable
storage space is required, a SPI flash with larger memory size is preferred. Theoretically speaking, up to
16 MB memory capacity can be supported.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 37


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

RELAY

INTRODUCTION:

A relay is an electrically operated switch. Many relays use an electromagnet to mechanically operate a
switch, but other operating principles are also used, such as solid-state relays. Relays are used where it is
necessary to control a circuit by a separate low-power signal, or where several circuits must be controlled
by one signal. The first relays were used in long distance telegraph circuits as amplifiers: they repeated
the signal coming in from one circuit and re-transmitted it on another circuit. Relays were used
extensively in telephone exchanges and early computers to perform logical operations.

A type of relay that can handle the high power required to directly control an electric motor or other loads
is called a contactor. Solid-state relays control power circuits with no moving parts, instead using a
semiconductor device to perform switching. Relays with calibrated operating characteristics and
sometimes multiple operating coils are used to protect electrical circuits from overload or faults; in
modern electric power systems these functions are performed by digital instruments still called
"protective relays".

Magnetic latching relays require one pulse of coil power to move their contacts in one direction, and
another, redirected pulse to move them back. Repeated pulses from the same input have no effect.
Magnetic latching relays are useful in applications where interrupted power should not be able to
transition the contacts.

Magnetic latching relays can have either single or dual coils. On a single coil device, the relay will
operate in one direction when power is applied with one polarity, and will reset when the polarity is
reversed. On a dual coil device, when polarized voltage is applied to the reset coil the contacts will
transition. AC controlled magnetic latch relays have single coils that employ steering diodes to
differentiate between operate and reset commands.

Basic design and operation:

A simple electromagnetic relay consists of a coil of wire wrapped around a soft iron core (a solenoid), an
iron yoke which provides a low reluctance path for magnetic flux, a movable iron armature, and one or
more sets of contacts (there are two contacts in the relay pictured). The armature is hinged to the yoke

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 38


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

and mechanically linked to one or more sets of moving contacts. The armature is held in place by
a spring so that when the relay is de-energized there is an air gap in the magnetic circuit. In this
condition, one of the two sets of contacts in the relay pictured is closed, and the other set is open. Other
relays may have more or fewer sets of contacts depending on their function. The relay in the picture also
has a wire connecting the armature to the yoke. This ensures continuity of the circuit between the moving
contacts on the armature, and the circuit track on the printed circuit board (PCB) via the yoke, which is
soldered to the PCB.

When an electric current is passed through the coil it generates a magnetic field that activates the
armature and the consequent movement of the movable contact either makes or breaks (depending upon
construction) a connection with a fixed contact. If the set of contacts was closed when the relay was de-
energized, then the movement opens the contacts and breaks the connection, and vice versa if the contacts
were open. When the current to the coil is switched off, the armature is returned by a force,
approximately half as strong as the magnetic force, to its relaxed position. Usually this force is provided
by a spring, but gravity is also used commonly in industrial motor starters. Most relays are manufactured
to operate quickly. In a low-voltage application this reduces noise; in a high voltage or current application
it reduces arcing.

When the coil is energized with direct current, a diode is often placed across the coil to dissipate the
energy from the collapsing magnetic field at deactivation, which would otherwise generate a voltage
spike dangerous to semiconductor circuit components. Such diodes were not widely used before the
application of transistors as relay drivers, but soon became ubiquitous as early germanium
transistors were easily destroyed by this surge. Some automotive relays include a diode inside the relay
case.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 39


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Simple electromechanical relay

1- Applications of Relays:

Relays are used in electronics to switch a smaller current which in turn will control larger current. They
prevent the user to have direct contact to the main device being controlled that might be holding high
voltage. These devices are comparable to a remote control which is used to make a big electronic
equipment work. The larger relays or contactors are being utilized in industries to provide energy on
machineries such as pumps and motors.

The function of relay can be easily understood by explaining how head lights turn on. The switches to
turn this on can be found on the dashboards of cars. Once moved, they will send a small current on the
coil turning on the contactor. The relay then will control a high power load which in this case is the head
lights. Besides this instance, relays have other more applications which we deal with everyday but have
not been able to notice.

Relays are being applied at home, industries and even on the street. Electronic equipment for domestic
use have parts that require energy in order to function. An example of it is refrigerator. This appliance has
motors and fans. Relays are responsible in controlling these parts so that refrigerator work and produce
cold temperature. Another application of relays is controlling traffic lights. They can be operated
remotely with the use of a switching component. Automatic garage door is another occasion where relays
are being utilized. The door’s movement and direction are the ones being controlled.

Relays do not only energize electronic equipment but also make devices to stop functioning. These
capabilities have brought automation and convenience in our lives. They let electronics run smoothly and

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 40


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

safely. Now, we do not have to deal directly with electronics that contain high voltage which may cause
danger if they suddenly malfunction.

2-Channel Relay Board:

This is a LOW Level 5V 2-channel relay interface board, and each channel needs a 15-20mA driver
current. It can be used to control various appliances and equipment with large current. It is equipped with
high-current relays that work under AC250V 10A or DC30V 10A. It has a standard interface that can be
controlled directly by microcontroller. This module is optically isolated from high voltage side for safety
requirement and also prevent ground loop when interface to microcontroller.

 Relay Maximum output: DC 30V/10A, AC 250V/10A.


 2 Channel Relay Module with Opto-coupler. LOW Level Trigger expansion board, which is
compatible with Arduino control board.
 Standard interface that can be controlled directly by microcontroller ( 8051, AVR, *PIC, DSP,
ARM, ARM, MSP430, TTL logic).
 Relay of high quality low noise relays SPDT. A common terminal, a normally open, one normally
closed terminal.
 Opto-Coupler isolation, for high voltage safety and prevent ground loop with microcontroller.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 41


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Schematic:

VCC and RY-VCC are also the power supply of the relay module. When you need to drive a large power
load, you can take the jumper cap off and connect an extra power to RY-VCC to supply the relay;
connect VCC to 5V of the MCU board to supply input signals. NOTES: If you want complete optical
isolation, connect "Vcc" to Arduino +5 volts but do NOT connect Arduino Ground. Remove the Vcc to
JD-Vcc jumper. Connect a separate +5 supply to "JD-Vcc" and board Gnd. This will supply power to the
transistor drivers and relay coils. If relay isolation is enough for your application, connect Arduino +5
and Gnd, and leave Vcc to JD-Vcc jumper in place.

It is sometimes possible to use this relay boards with 3.3V signals, if the JD-VCC (Relay Power) is
provided from a +5V supply and the VCC to JD-VCC jumper is removed. That 5V relay supply could be
totally isolated from the 3.3V device, or have a common ground if opto-isolation is not needed. If used
with isolated 3.3V signals, VCC (To the input of the opto-isolator, next to the IN pins) should be
connected to the 3.3V device's +3.3V supply.

NOTE: Some Raspberry-Pi users have found that some relays are reliable and others do not actuate
sometimes. It may be necessary to change the value of R1 from 1000 ohms to something like 220 ohms,
or supply +5V to the VCC connection

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 42


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Module Layout:

Operating Principal:

See the picture below: A is an electromagnet, B armature, C spring, D moving contact, and E fixed
contacts. There are two fixed contacts, a normally closed one and a normally open one. When the coil is
not energized, the normally open contact is the one that is off, while the normally closed one is the other
that is on.

Supply voltage to the coil and some currents will pass through the coil thus generating the
electromagnetic effect. So the armature overcomes the tension of the spring and is attracted to the core,
thus closing the moving contact of the armature and the normally open (NO) contact or you may say

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 43


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

releasing the former and the normally closed (NC) contact. After the coil is de-energized, the
electromagnetic force disappears and the armature moves back to the original position, releasing the
moving contact and normally closed contact. The closing and releasing of the contacts results in power on
and off of the circuit.

Input:

VCC : Connected to positive supply voltage (supply power according to relay voltage)

GND : Connected to supply ground.

IN1: Signal triggering terminal 1 of relay module

IN2: Signal triggering terminal 2 of relay module

Output:

Each module of the relay has one NC (normally close), one NO (normally open) and one COM
(Common) terminal. So there are 2 NC, 2 NO and 2 COM of the channel relay in total. NC stands for the
normal close port contact and the state without power. NO stands for the normal open port contact and
the state with power. COM means the common port. You can choose NC port or NO port according to
whether power or not.

Testing set up:

When a low level is supplied to signal terminal of the 2-channel relay, the LED at the output terminal will
light up. Otherwise, it will turn off. If a periodic high and low level is supplied to the signal terminal, you
can see the LED will cycle between on and off.

Features:

The 2-Channel Relay Module includes the following features:

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 44


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 45


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Adafruit IO Basics: Digital Input

Created by Justin Cooper

Last updated on 2019-07-26 09:16:00 PM UTC

Overview

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 46


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

This guide is part of a series of guides that cover the basics of using Adafruit IO. It will show you how to send momentary button
press data to Adafruit IO.

If you haven't worked your way through the Adafruit IO feed and dashboard basics guides, you should do that before continuing
with this guide so you have a basic understanding of Adafruit IO.

Adafruit IO Basics: Feeds


Adafruit IO Basics: Dashboards

You should go through the setup guides associated with your selected set of hardware, and make sure you have internet
connectivity with the device before continuing. The following links will take you to the guides for your selected platform.

Adafruit Feather HUZZAH ESP8266 Setup Guide

If you have went through all of the prerequisites for your selected hardware, you are now ready to move on to the Adafruit IO
setup steps that are common between all of the hardware choices for this project. Let's get started!

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 47


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Adafruit IO Setup

The first thing you will need to do is to login to Adafruit IO and visit the Settings page. Click
the VIEW AIO KEY button to retrieve your key.

A window will pop up with your Adafruit IO. Keep a copy of this in a safe place. We'll need it later.

Creating the Digital Feed

Next, you will need to create a feed called Digital. If you need help getting started with creating feeds on Adafruit IO, check out
the Adafruit IO Feed Basics guide (https://adafru.it/ioA).

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 48


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Adding the Gauge Block

Next, add a new Gauge block to a new or existing dashboard. Name the block whatever you would like, and give it a max value
of 1 and a min value of 0. Make sure you have selected the Digital feed as the data source for the gauge.

If you need help getting started with Dashboards on Adafruit IO, check out the Adafruit IO Dashboard Basics guide
(https://adafru.it/f5m).

When you are finished editing the form, click Create Block to add the new block to the dashboard.

SRI VENKTESWARA COLLEGE OF ENGINEERING, KADAPA -EEE Page 49


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Next, we will look at wiring the circuit.

Arduino Wiring

You will need the following parts for this tutorial:

1x Adafruit IO compatible Feather 3x


jumper wires
1x 10k resistor
1x momentary button
You will need to connect the following pins to the button and 10k resistor:
Feather GND to one side of the momentary button
Feather Pin 5 to the other side of the momentary button
Feather 3V to one leg of a 10k resistor
The second leg of the 10k resistor to the same side of the momentary button as Pin 5

Note: Resistors are not polarized, so the 10k resistor can be connected to the circuit in either direction.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 50


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Arduino Setup

You should go through the setup guides associated with your selected set of hardware, and make sure you have internet
connectivity with the device before continuing. The following links will take you to the guides for your selected platform.

Adafruit Feather HUZZAH ESP8266 Setup Guide

You will need to make sure you have at least version 2.3.1 of the Adafruit IO Arduino library installed before continuing. You
will also need the Arduino HTTP library and Adafruit MQTT library so check the setup guide above to get all set up!

For this example, you will need to open the adafruitio_06_digital_in example in the Adafruit IO Arduino library.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 51


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Next, we will look at the network configuration options in the sketch.

Arduino Network Config

To configure the network settings, click on the config.h tab in the sketch. You will need to set your Adafruit IO
username in the IO_USERNAME define, and your Adafruit IO key in the IO_KEY define.

WiFi Config

WiFi is enabled by default in config.h so if you are using one of the supported WiFi boards, you will only need to modify
the WIFI_SSID and WIFI_PASS options in the config.h tab.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 52


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

FONA Config

If you wish to use the FONA 32u4 Feather to connect to Adafruit IO, you will need to first comment out the WiFi
support in config.h

Next, remove the comments from both of the FONA config lines in the FONA section of config.h to enable FONA support.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 53


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Ethernet Config

If you wish to use the Ethernet Wing to connect to Adafruit IO, you will need to first comment out the WiFi support in
config.h

Next, remove the comments from both of the Ethernet config lines in the Ethernet section of config.h to enable Ethernet
Wing support.

Next, we will look at how the example sketch works.

Arduino Code

The adafruitio_06_digital_in example uses digital pin 5 by default on all boards, and that can be modified if needed by
changing the BUTTON_PIN define.

Note: If you are using the WICED Feather, you will need to change the BUTTON_PIN define to PC5 instead of the default
setting of 5.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 54


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

/************************ Example Starts Here *******************************/

// digital pin 5
#define BUTTON_PIN 5

The next chunk of code sets up two boolean variables to track button state, and an Adafruit IO Feed instance for a feed called
digital.

// button state

bool current = false;


bool last = false;

// set up the 'digital' feed

AdafruitIO_Feed *digital = io.feed("digital");

In the setup function, we set the BUTTON_PIN as a digital input, and connect to Adafruit IO. The code will wait until you have
a valid connection to Adafruit IO before continuing with the sketch. If you have any issues connecting, check config.h for any
typos in your username or key.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 55


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

void setup() {

// set button pin as an input


pinMode(BUTTON_PIN, INPUT);

// start the serial connection


Serial.begin(115200);

// wait for serial monitor to open


while(! Serial);

// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();

// wait for a connection


while(io.status() < AIO_CONNECTED) {

Serial.print(".");
delay(500);

// we are connected
Serial.println();
Next, we have the main loop() function. The first line of the loop function calls io.run(); this line will need to be present
Serial.println(io.statusText());

at the top of your loop in every sketch. It helps keep your device connected to Adafruit IO, and processes any
}
incoming data.

void loop() {

// io.run(); is required for all sketches.

// it should always be present at the top of your loop

// function. it keeps the client connected to

// io.adafruit.com, and processes any incoming data.


io.run();

The next chunk of code inside the loop() checks the current state of the button, and saves the state of the button in the current
variable. Because we are using a pullup resistor, we will need to flip the button state.

If the button state is LOW it means the button is pressed, so we set current=true;. If the button state is HIGH it means the
button is released, so we set current = false;.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 56


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

We then check if the current button state is equal to the last button state. If it is equal, we will return early and not continue
with the rest of the loop.

// grab the current state of the button.

// we have to flip the logic because we are

// using a pullup resistor.


if(digitalRead(BUTTON_PIN) == LOW)

current = true;
else

current = false;

// return if the value hasn't changed


if(current == last)

The final chunk of the loop() function prints the current value to the Arduino Serial Monitor, and sends the current value to the
return;

digital feed on Adafruit IO. We also set last = current;so we can tell if the state of the button has changed in the next run of
the loop.

// save the current state to the 'digital' feed on adafruit io


Serial.print("sending button -> ");

Serial.println(current);
digital->save(current);

// store last button state


last = current;

Upload the sketch to your board, and open the Arduino Serial Monitor. Your board should now connect to Adafruit IO.

Connecting to Adafruit IO....

Adafruit IO connected.

You can now press the button, and you should see button presses being sent to Adafruit IO.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 57


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

sending button -> 1


sending button -> 0
sending button -> 1
sending button -> 0

Check your dashboard on Adafruit IO, and you should see the gauge respond to button presses.

Python Wiring

Parts

Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB


RAM

$35.00

IN STOCK

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 58


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

ADD TO CART

If you're following along with a Raspberry Pi (https://adafru.it/ejq), we're going to use a T-Cobbler Plus for the IO Basics
Projects. This add-on prototyping board lets you easily connect a Raspberry Pi (Raspberry Pi Model Zero, A+, B+, Pi 2, Pi 3)
to a solderless breadboard.

1 x Jumper Wires

Breadboarding wire bundle.

ADD TO CART

Assembled Pi T-Cobbler Plus - GPIO Breakout

$7.95

IN STOCK ADD TO CART


1 x Button
Tactile Switch Buttons (12mm square, 6mm tall) x 10 pack

ADD TO CART Wiring

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 59


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

You'll need to make the following connections:

Pi GND to a common ground rail.


Pi GND to one side of the momentary button.
Pi Pin 12 to the other side of the momentary button.

Next, proceed to the Python Setup Page (https://adafru.it/BMB) of this guide.

Python Setup

If you're following along with a Raspberry Pi, Beaglebone or any other supported small linux computer, we'll use a special
library called adafruit_blinka (https://adafru.it/BJS) (named after Blinka, the CircuitPython
mascot (https://adafru.it/BJT)) to provide the layer that translates the CircuitPython hardware API to whatever library the Linux
board provides. It's CircuitPython, on Pi!

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 60


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Update your Pi and Python

# The latest Raspbian (currently this is `Stretch`) is required for the installation of Adafruit IO + Blinka.

In this page we'll assume you've already gotten your Raspberry Pi up and running and can log into the command line. Go ahead
and ssh into your Raspberry Pi via terminal or a ssh client:
ssh pi@raspberrypi.local

Run the standard updates:

sudo apt-get update

sudo apt-get upgrade

and

sudo pip3 install --upgrade setuptools

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 61


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Make sure you're using Python 3!

The default python on your computer may not be python 3. Python 2 is officially discontinued and all our libraries are Python 3
only.
pip3

We'll be using python3 and in our commands, use those versions of python and pip to make sure you're using
3 and not 2

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 62


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Install Python Libraries

Installing Adafruit Blinka Library

Now you're ready to install all the python support

Run the following command to install the Raspberry PI GPIO library:

pip3 install RPI.GPIO

Run the following command to install adafruit_blinka

pip3 install adafruit-blinka

The computer will install a few different libraries such as adafruit-pureio (our ioctl-only i2c library), spidev (for SPI
interfacing), Adafruit-GPIO (for detecting your board) and of course adafruit-blinka

Installing Adafruit IO Python Library

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 63


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

We'll also need to install the Adafruit IO Python Client Library (https://adafru.it/eli) to communicate with Adafruit IO. Run
the following command to install the Adafruit IO Client for Python:

pip3 install adafruit-io

# If the installation gives you 'insufficient permissions' errors, add 'sudo' before the call to pip3

Downloading Example Code

The example code is contained within the Python IO Client's examples/basics subdirectory. Navigate to
the root directory of your Pi:

cd ~

Then, download the latest version of the adafruit/io-client-python repository by running:

git clone https://github.com/adafruit/io-client-python.git

Navigate to that folder's example folder for the examples:

cd io-client-python/examples/basics/

That's it! We're all set up.

Next, let's upload some code and learn how it works.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 64


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Python Code

Code

Before we run the script at the bottom of this page, we'll need to
ADAFRUIT_IO_USERNAME ADAFRUIT_IO_KEY
change and to the username and key for your Adafruit IO account.

If you need the AIO Key, navigate to your Adafruit IO Profile (https://adafru.it/BmD)

# Set to your Adafruit IO key.

# Remember, your key is a secret,

# so make sure not to publish it when you publish this code!


ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY'

# Set to your Adafruit IO username.

# (go to https://accounts.adafruit.com to find your username)


ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'

We're going to set up an instance of the feed we created earlier:

digital = aio.create_feed(Feed(name="digital"))

In the while True loop, we're going to check the value of the button and send it to Adafruit IO. A delay (time.sleep())
has been added to avoid timing out by sending too many requests to Adafruit IO.

while True:

if not button.value:
button_current = 1

else:

button_current = 0

print('Button -> ', button_current)


aio.send(digital.key, button_current)

# avoid timeout from adafruit io


time.sleep(1)

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 65


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Running the Code

Make sure you're within the /io-client-python/examples/basics directory.

If you're not sure which directory you're in, you can check this by running and you should see the following
pwd
output from your terminal:

~/io-client-python/examples/basics

Let's run the script. In your terminal, run:

python3 digital-in.py

You can now press the button, and you should see button presses being sent to Adafruit IO:

Button -> 1

Button -> 0

Button -> 1

Button -> 0

Check your dashboard on Adafruit IO, and you should see the gauge respond to button presses:

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 66


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Code

'digital_in.py'

==================================

Example of sending
button values to an
Adafruit IO feed.

Author(s): Brent Rubell,


ToddTreece """

# Import standard python


modules import time

# import Adafruit
Blinka import
board

import digitalio

# import Adafruit IO REST client.

from Adafruit_IO import Client, Feed, RequestError

# Set to your Adafruit IO key.

# Remember, your key is a secret,

# so make sure not to publish it when you


publish this code! ADAFRUIT_IO_KEY =
'YOUR_AIO_KEY'

# Set to your Adafruit IO username.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 67


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

# (go to https://accounts.adafruit.com to find


your username) ADAFRUIT_IO_USERNAME
= 'YOUR_AIO_USERNAME'

# Create an instance of the REST client.

aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY)

try: # if we have a
'digital' feed digital =
aio.feeds('digital')

except RequestError: # create a


digital feed feed =
Feed(name="digital")

digital = aio.create_feed(feed)

# button set up

button =
digitalio.DigitalInOut(board.D12
) button.direction =
digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP
button_current = 0

while True:

if not
button.value:

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 68


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

button_curre
nt = 1

else:

button_current = 0

print('Button -> ',


button_current)
aio.send(digital.key,
button_current)

# avoid timeout from


adafruit io
time.sleep(1)

Adafruit IO
FAQ

Encountering an issue with your Adafruit IO Arduino Project?

If you're having an issue compiling, connecting, or troubleshooting your project, check this page first.

Don't see your issue? Post up on the Adafruit IO Forum with your issue (https://adafru.it/plC).

I encounter the following error when compiling my sketch:

fatal error: Adafruit_MQTT.h: No such file or directory, #include "Adafruit_MQTT.h"

The Adafruit IO Arduino library is dependent on our Adafruit IO MQTT Library.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 69


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

To resolve this error, from the Arduino IDE,


navigate to the Manage Libraries... option in
the Sketch -> Include Library menu.

To resolve this error, from the Arduino IDE,


navigate to the Manage Libraries... option in
the Sketch -> Include Library menu.

# My Serial Monitor prints "..." endlessly after the "Connecting to Adafruit IO" message

Your board is not connecting to Adafruit IO, but why? Let's find out:

First Check in config.h that you have the correct IO_USERNAME, IO_KEY, Wifi_SSID and are set
WIFI_PASS
correctly.
Next, we're going to modify the while loop which waits for an IO connection in your sketch. Change the
line in the status check loop from Serial.println(.); to Serial.println(io.statusText());

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 70


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

// wait for a connection


while(io.status() < AIO_CONNECTED) {
Serial.println(io.statusText());
delay(500);

Verify and re-upload the sketch. If you're receiving a Network disconnected error message, the board is
not able to talk to the internet. Re-check your hardware, connections, and router settings.

If it's still not showing Adafruit IO connected, check the IO status on the Adafruit Status page to make
sure the service is online.

# My data isn't displaying, is Adafruit IO's {service/MQTT/API} down?

Possibly - you can check IO status on the Adafruit Status page.

# Is my data being sent properly? Am I sending too much data?

There's a monitor page built-into Adafruit IO which provides a live view of incoming data and error messages.
Keep this page open while you send data to your Adafruit IO devices to monitor data and errors.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 71


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

ARDUINO IDE

INTRODUCTION:

Arduino is an open-source electronics platform based on easy-to-use hardware and


software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a
Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing
something online. You can tell your board what to do by sending a set of instructions to the
microcontroller on the board. To do so you use the Arduino programming language (based
on Wiring), and the Arduino Software (IDE), based on Processing.

Over the years Arduino has been the brain of thousands of projects, from everyday objects to
complex scientific instruments. A worldwide community of makers - students, hobbyists, artists,
programmers, and professionals - has gathered around this open-source platform, their
contributions have added up to an incredible amount of accessible knowledge that can be of great
help to novices and experts alike.

Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast prototyping,
aimed at students without a background in electronics and programming. As soon as it reached a
wider community, the Arduino board started changing to adapt to new needs and challenges,
differentiating its offer from simple 8-bit boards to products for IoT applications, wearable, 3D
printing, and embedded environments. All Arduino boards are completely open-source,
empowering users to build them independently and eventually adapt them to their particular
needs. The software, too, is open-source, and it is growing through the contributions of users
worldwide.

Hardware Specifications:

 Microcontroller: ATmega328

 Operating Voltage: 5V

 Input Voltage (recommended):7-12V

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 72


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

 Input Voltage (limits): 6- 20V

 Digital I/O Pins: 14 (of which 6 provide PWM output)

 Analog Input Pins: 6 • DC Current per I/O Pin: 40 mA

 DC Current for 3.3V Pin: 50 mA

 Flash Memory: 32 KB (ATmega328)

 SRAM: 2 KB (ATmega328)

 EEPROM: 1 KB (ATmega328)

 Clock Speed: 16 MHz

Board Types:

Various kinds of Arduino boards are available depending on different microcontrollers used.
However, all Arduino boards have one thing in common: they are programmed through the
Arduino IDE. The differences are based on the number of inputs and outputs (the number of
sensors, LEDs, and buttons you can use on a single board), speed, operating voltage, form factor
etc. Some boards are designed to be embedded and have no programming interface (hardware),
which you would need to buy separately. Some can run directly from a 3.7V battery, others need
at least 5V.

Here is a list of different Arduino boards available.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 73


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Arduino boards based on ATMEGA328 microcontroller

Board Name Operati Clock Digital Analog PWM UART Programming


ng Volt Speed i/o Inputs Interface

Arduino Uno 5V 16MHz 14 6 6 1 USB via


R3 ATMega16U2

Arduino Uno 5V 16MHz 14 6 6 1 USB via


R3 SMD ATMega16U2

Red Board 5V 16MHz 14 6 6 1 USB via FTDI

Arduino Pro 3.3V 8 8 MHz 14 6 6 1 FTDI


3.3v/8 MHz Compatible
Header

Arduino Pro 5V 16MHz 14 6 6 1 FTDI


5V/16MHz Compatible
Header

Arduino mini 5V 16MHz 14 8 6 1 FTDI


05 Compatible
Header

Arduino Pro 3.3V 8MHz 14 8 6 1 FTDI


mini Compatible
3.3v/8mhz Header

Arduino Pro 5V 16MHz 14 8 6 1 FTDI


mini Compatible

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 74


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

5v/16mhz Header

Arduino 5V 16MHz 14 6 6 1 FTDI


Ethernet Compatible
Header

Arduino Fio 3.3V 8MHz 14 8 6 1 FTDI


Compatible
Header

LilyPad 3.3V 8MHz 14 6 6 1 FTDI


Arduino 328 Compatible
main board Header

LilyPad 3.3V 8MHz 9 4 5 0 FTDI


Arduino Compatible
simply board Header

Arduino board Description:

We will learn about the different components on the Arduino board. We will study the Arduino
UNO board because it is the most popular board in the Arduino board family. In addition, it is
the best board to get started with electronics and coding. Some boards look a bit different from
the one given below, but most Arduino’s have majority of these components in common.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 75


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

1. Power USB:

Arduino board can be powered by using the USB cable from your computer. All you need to do
is connect the USB cable to the USB connection (1).

2. Power (Barrel Jack):

Arduino boards can be powered directly from the AC mains power supply by connecting it to the
Barrel Jack (2).

3. Voltage Regulator:

The function of the voltage regulator is to control the voltage given to the Arduino board and
stabilize the DC voltages used by the processor and other elements.

4. Crystal Oscillator:

The crystal oscillator helps Arduino in dealing with time issues. How does Arduino calculate
time? The answer is, by using the crystal oscillator. The number printed on top of the Arduino
crystal is 16.000H9H. It tells us that the frequency is 16,000,000 Hertz or 16 MHz

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 76


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

5, 17. Arduino Reset:

You can reset your Arduino board, i.e., start your program from the beginning. You can reset the
UNO board in two ways. First, by using the reset button (17) on the board. Second, you can
connect an external reset button to the Arduino pin labeled RESET (5).

6, 7, 8, 9. Pins (3.3, 5, GND, Vin):

 3.3V (6): Supply 3.3 output volt

 5V (7): Supply 5 output volt

 Most of the components used with Arduino board works fine with 3.3 volt and 5 volt.

 GND (8)(Ground): There are several GND pins on the Arduino, any of which can be used to
ground your circuit.

 Vin (9): This pin also can be used to power the Arduino board from an external power source,
like AC mains power supply.

10. Analog pins:

The Arduino UNO board has five analog input pins A0 through A5. These pins can read the
signal from an analog sensor like the humidity sensor or temperature sensor and convert it into a
digital value that can be read by the microprocessor.

11. Main microcontroller:

Each Arduino board has its own microcontroller (11). You can assume it as the brain of your
board. The main IC (integrated circuit) on the Arduino is slightly different from board to board.
The microcontrollers are usually of the ATMEL Company. You must know what IC your board
has before loading up a new program from the Arduino IDE. This information is available on the
top of the IC. For more details about the IC construction and functions, you can refer to the data
sheet.

12. ICSP pin: Mostly, ICSP (12) is an AVR, a tiny programming header for the Arduino
consisting of MOSI, MISO, SCK, RESET, VCC, and GND. It is often referred to as an SPI

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 77


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

(Serial Peripheral Interface), which could be considered as an "expansion" of the output.


Actually, you are slaving the output device to the master of the SPI bus.

13. Power LED indicator:

This LED should light up when you plug your Arduino into a power source to indicate that your
board is powered up correctly. If this light does not turn on, then there is something wrong with
the connection.

14. TX and RX LEDs:

On your board, you will find two labels: TX (transmit) and RX (receive). They appear in two
places on the Arduino UNO board. First, at the digital pins 0 and 1, to indicate the pins
responsible for serial communication. Second, the TX and RX led (13). The TX led flashes with
different speed while sending the serial data. The speed of flashing depends on the baud rate
used by the board. RX flashes during the receiving process.

15. Digital I / O:

The Arduino UNO board has 14 digital I/O pins (15) (of which 6 provide PWM (Pulse Width
Modulation) output. These pins can be configured to work as input digital pins to read logic
values (0 or 1) or as digital output pins to drive different modules like LEDs, relays, etc. The
pins labeled “~” can be used to generate PWM.

16. AREF:

AREF stands for Analog Reference. It is sometimes, used to set an external reference voltage
(between 0 and 5 Volts) as the upper limit for the analog input pins.

Arduino Installation:

After learning about the main parts of the Arduino UNO board, we are ready to learn how to set
up the Arduino IDE. Once we learn this, we will be ready to upload our program on the Arduino
board. In this section, we will learn in easy steps, how to set up the Arduino IDE on our
computer and prepare the board to receive the program via USB cable.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 78


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Step 1:

First you must have your Arduino board (you can choose your favorite board) and a USB cable.
In case you use Arduino UNO, Arduino Duemilanove, Nano, Arduino Mega 2560, or Diecimila,
you will need a standard USB cable (A plug to B plug), the kind you would connect to a USB
printer as shown in the following image.

Step 2: Download Arduino IDE Software.

You can get different versions of Arduino IDE from the Download page on the Arduino Official
website. You must select your software, which is compatible with your operating system
(Windows, IOS, or Linux). After your file download is complete, unzip the file.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 79


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Step 3: Power up your board.

The Arduino Uno, Mega, Duemilanove and Arduino Nano automatically draw power from
either, the USB connection to the computer or an external power supply. If you are using an
Arduino Diecimila, you have to make sure that the board is configured to draw power from the
USB connection. The power source is selected with a jumper, a small piece of plastic that fits
onto two of the three pins between the USB and power jacks. Check that it is on the two pins
closest to the USB port. Connect the Arduino board to your computer using the USB cable. The
green power LED (labeled PWR) should glow.

Step 4: Launch Arduino IDE

After your Arduino IDE software is downloaded, you need to unzip the folder. Inside the folder,
you can find the application icon with an infinity label (application.exe). Double-click the icon to
start the IDE.

Step 5: Open your first project.

Once the software starts, you have two options:

 Create a new project.

 Open an existing project example.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 80


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

To create a new project, select File --> New.

To open an existing project example, select File -> Example -> Basics -> Blink.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 81


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Here, we are selecting just one of the examples with the name Blink. It turns the LED on and off
with some time delay. You can select any other example from the list.

Step 6: Select your Arduino board.

To avoid any error while uploading your program to the board, you must select the correct
Arduino board name, which matches with the board connected to your computer. Go to Tools ->
Board and select your board

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 82


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Here, we have selected Arduino Uno board according to our tutorial, but you must select the
name matching the board that you are using.

Step 7: Select your serial port.

Select the serial device of the Arduino board. Go to Tools -> Serial Port menu. This is likely to
be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find
out, you can disconnect your Arduino board and re-open the menu, the entry that disappears
should be of the Arduino board. Reconnect the board and select that serial port.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 83


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Step 8: Upload the program to your board.

Before explaining how we can upload our program to the board, we must demonstrate the
function of each symbol appearing in the Arduino IDE toolbar.

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 84


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Now, simply click the "Upload" button in the environment. Wait a few seconds; you will see the
RX and TX LEDs on the board, flashing. If the upload is successful, the message "Done
uploading" will appear in the status bar.

Note: If you have an Arduino Mini, NG, or other board, you need to press the reset button
physically on the board, immediately before clicking the upload button on the Arduino Software.

#include"DHT.h"

#include <ESP8266WiFi.h>

#include "Adafruit_MQTT.h"

#include "Adafruit_MQTT_Client.h"

#define DHTTYPE DHT11

#define dht_dpin D7

#define motor1 D4 //TURN ON/OFF BULB

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 85


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

#define motor2 D0 //TURN ON/OFF FAN

#define analog_pin A0

#define fire D2

//#define Charger D1 //TURN ON/OFF CHARGER

//#define TV D2 //TURN ON/OFF TV

DHT dht(dht_dpin,DHTTYPE);

#define WLAN_SSID "Batch9" // Your SSID

#define WLAN_PASS "eee.2020" // Your password

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER "io.adafruit.com"

#define AIO_SERVERPORT 1883 // use 8883 for SSL

#define AIO_USERNAME "scadausingiot1" // Replace it with your username

#define AIO_KEY "aio_fAlb68RMg3GQEMtIKP8nEie34BUG" // Replace with your


Project Auth Key

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.

WiFiClient client;

// or... use WiFiFlientSecure for SSL

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 86


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

//WiFiClientSecure client;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.

Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT,


AIO_USERNAME, AIO_KEY);

/******************************Feeds **************************************/

// Setup a feed called 'onoff' for subscribing to changes.

Adafruit_MQTT_Subscribe Light1 = Adafruit_MQTT_Subscribe(&mqtt,


AIO_USERNAME"/feeds/motor1"); // FeedName

Adafruit_MQTT_Subscribe Light2 = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME


"/feeds/motor2");

//Adafruit_MQTT_Subscribe Light3 = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME


"/feeds/Charger");

//Adafruit_MQTT_Subscribe Light4 = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME


"/feeds/TV");

Adafruit_MQTT_Publish photocel2 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME


"/feeds/temperature value");

Adafruit_MQTT_Publish photocel3 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME


"/feeds/humidity value");

Adafruit_MQTT_Publish photocel4 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME


"/feeds/co2 level");

Adafruit_MQTT_Publish photocel5 = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME


"/feeds/fire sensor value");

void MQTT_connect();

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 87


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

void setup() {

Serial.begin(115200);

pinMode(motor1, OUTPUT); //CHANGE

pinMode(motor2, OUTPUT); //CHANGE

// pinMode(Charger, OUTPUT); //CHANGE

// pinMode(TV, OUTPUT); //CHANGE

// Connect to WiFi access point.

Serial.println(); Serial.println();

Serial.print("Connecting to ");

Serial.println(WLAN_SSID);

WiFi.begin(WLAN_SSID, WLAN_PASS);

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(".");

Serial.println();

Serial.println("WiFi connected");

Serial.println("IP address: ");

Serial.println(WiFi.localIP());

// Setup MQTT subscription for onoff feed.

mqtt.subscribe(&Light1);

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 88


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

// mqtt.subscribe(&Light3);

mqtt.subscribe(&Light2);

// mqtt.subscribe(&Light4);

void loop() {

MQTT_connect();

//digitalWrite(Bulb,HIGH);

//digitalWrite(Fan,HIGH);

/*digitalWrite(D0,HIGH);

digitalWrite(D4,HIGH);*/

unsigned int h=dht.readHumidity();

unsigned int t=dht.readTemperature();

Serial.println("humidity=");

Serial.print(h);

Serial.println("Temp=");

Serial.print(t);

Serial.print(F("\nSending temperaturesensor val "));

Serial.print(t);

Serial.print("...");

if (! photocel2.publish(t)) {

Serial.println(F("Failed"));

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 89


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

} else {

Serial.println(F("OK!"));

//unsigned int humidity=digitalRead(h);

Serial.print(F("\nSending humiditysensor val "));

Serial.print(h);

Serial.print("...");

if (! photocel3.publish(h)) {

Serial.println(F("Failed"));

} else {

Serial.println(F("OK!"));

float gas=analogRead(analog_pin);

Serial.println("gas value");

Serial.println(gas);

if (! photocel4.publish(gas)) {

Serial.println(F("Failed"));

} else {

Serial.println(F("OK!"));

int light = digitalRead(fire);

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 90


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Serial.println("fire value:");

Serial.println(fire);

if (! photocel5.publish(fire)) {

Serial.println(F("Failed"));

} else {

Serial.println(F("OK!"));

Adafruit_MQTT_Subscribe *subscription;

while ((subscription = mqtt.readSubscription(20000))) {

if (subscription == &Light1) {

Serial.print(F("Got: "));

Serial.println((char *)Light1.lastread);

int Light1_State = atoi((char *)Light1.lastread);

digitalWrite(motor1, Light1_State); //CHANGE

if (subscription == &Light2) {

Serial.print(F("Got: "));

Serial.println((char *)Light2.lastread);

int Light2_State = atoi((char *)Light2.lastread);

digitalWrite(motor2, Light2_State); //CHANGE

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 91


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

/*if (subscription == &Light3) {

Serial.print(F("Got: "));

Serial.println((char *)Light3.lastread);

int Light3_State = atoi((char *)Light3.lastread);

digitalWrite(Charger, Light3_State); //CHANGE

if (subscription == &Light4) {

Serial.print(F("Got: "));

Serial.println((char *)Light4.lastread);

int Light4_State = atoi((char *)Light4.lastread);

digitalWrite(TV, Light4_State); //CHANGE

}*/

void MQTT_connect() {

int8_t ret;

// Stop if already connected.

if (mqtt.connected()) {

return;

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 92


SUPERVISORY CONTROL AND DATA ACQUISITION BY USING IOT

Serial.print("Connecting to MQTT... ");

uint8_t retries = 3;

while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected

Serial.println(mqtt.connectErrorString(ret));

Serial.println("Retrying MQTT connection in 5 seconds...");

mqtt.disconnect();

delay(5000); // wait 5 seconds

retries--;

if (retries == 0) {

// basically die and wait for WDT to reset me

while (1);

Serial.println("MQTT Connected!");

SRI VENKATESWARA COLLEGE OF ENGINEERING, KADAPA - EEE Page 93

You might also like