Professional Documents
Culture Documents
Batch A7
Batch A7
Batch A7
A PROJECT REPORT ON
Submitted by
DEGA SRIHARI (162H1A0419)
BATTULA PITCHIREDDY (162H1A0408)
AVVARI SRINIVASULU (162H1A0404)
MALLI KRISHNA BABU (162H1A0440)
CERTIFICATE
This is to certify that the project report entitled “IOT BASED HOME
AUTOMATION CAN BE CONTROLLEDAUDIO WITH MULTI
LANGUAGES” is submitted by Mr. DEGA SRIHARI (162H1A0419), Mr.
BATTULA PITCHI REDDY (162H1A0408), Mr. AVVARI SRINIVASULU
(162H1A0404), Mr. MALLI KRISHNA BABU(162H1A0440) in partial fulfillment
of the requirement for the award of the Degree of Bachelor of Technology in
ELECTRONICS AND COMMUNICATION ENGINEERING to
“AUDISANKARA INSTITUTE OF TECHNOLOGY”, GUDUR is a record of
bonafide work carried out by them under my guidance and supervision from 05-
02-20 to 11-3-20.
The results presented in this report have been verified and are found to be
satisfactory. The results embodied in this report have not been submitted to any other
university for the award of any degree.
External Examiner
ACKNOWLEDGEMENT
First and foremost, we would like to thank our beloved parents for their blessings and
grace in making this project success. We avail this opportunity to express our
profound sense of sincere and deep gratitude to those who constantly guided,
supported and encouraged during the course of our project.
We wish to express our heartfelt thanks and deep sense of gratitude to the honorable
chairman Dr.VANKI PENCHALAIAH, M.L, for his encouragement and inspiration
throughout the process.
We would like to thank our college management for having allowed us to do the
project work. Lastly we would like to pay our regards and thank our principal Dr.
T.VENU MADHAV whose ideas are proved to be really worth full in our work.
We wish to express our deep sense of gratitude to our beloved and esteemed Head of
the Department of ECE, SYED KAREEMSAHEB, M.Tech, (Ph.D). For his
support, encouragement and valuable suggestions, this went a long way in the
successful completion of this project
Finally we would like to thank and express our gratitude to our project guide
ASSISTANT PROFESSOR, AV KARTHIK KUMAR M .Tech, and we regard for
his valuable suggestions and support throughout our project work.
LITERATURE SURVEY 15
CHAPTER 3
3.1 Existing Home Automation System 16
3.2 Proposed System 17
3.3 Block Diagram 18
CHAPTER 4
HARDWARE COMPONENTS
4.1 ESP 8266 Wifi Module(NodeMCU) 19-20
4.1.1 Features 21-27
4.2 Relay 28-29
4.2.1 Basic Design and Operations 30-33
4.2.2 Types of Relay 34-42
4.3 8 Channel Relay 42-46
4.4 Transformers 46
4.4.1 Classification Parameters 47-48
4.4.2 Types of Transformers 48-52
4.4.3 Steps to Convert 230V AC to 12 V DC Using 53-55
Step Down Transformer
4.5 Rectifiers 56
4.5.1 Types of Rectifiers 56
4.5.2 Bridge Rectifier 57-58
CHAPTER 5
SOFTWARE
5.1 Arduino IDE 59-63
CHAPTER 6
6.1 ADVANTAGES 64
6.2 APPLICATIONS 64
CHAPTER 7
RESULT 65
CHAPTER 8
8.1 Conclusion 66
8.2 References 66
APPENDIX II (Acronyms) 72
LIST OF FIGURES
CHAPTER 1
INTERNET OF THINGS
1.1 Introduction
The definition of the Internet of things has evolved due to the convergence of
multiple technologies, real-time analytics, machine learning, commodity sensors,
and embedded systems.[1] Traditional fields of embedded systems, wireless sensor
networks, control systems, automation (including home and building automation), and
others all contribute to enabling the Internet of things. In the consumer market, IoT
technology is most synonymous with products pertaining to the concept of the "smart
home", covering devices and appliances (such as lighting fixtures, thermostats,
home security systems and cameras, and other home appliances) that support one or
more common ecosystems, and can be controlled via devices associated with that
ecosystem, such as smartphones and smart speakers.
There are a number of serious concerns about dangers in the growth of IoT,
especially in the areas of privacy and security, and consequently industry and
governmental moves to address these concerns have begun.
1.2 History
The main concept of a network of smart devices was discussed as early as 1982, with
a modified Coca-Cola vending machine at Carnegie Mellon University becoming the
first Internet-connected appliance, able to report its inventory and whether newly
loaded drinks were cold or not. Mark Weiser's 1991 paper on ubiquitous computing,
"The Computer of the 21st Century", as well as academic venues such as UbiComp
and PerCom produced the contemporary vision of the IoT. In 1994, Reza Raji
described the concept in IEEE Spectrum as "[moving] small packets of data to a large
The term "Internet of things" was likely coined by Kevin Ashton of Procter &
Gamble, later MIT's Auto-ID Center, in 1999, though he prefers the phrase
"Internet for things".At that point, he viewed radio-frequency identification (RFID) as
essential to the Internet of things, which would allow computers to manage all
individual things.
Defining the Internet of things as "simply the point in time when more 'things or
objects' were connected to the Internet than people", Cisco Systems estimated that the
IoT was "born" between 2008 and 2009, with the things/people ratio growing from
0.08 in 2003 to 1.84 in 2010.[17]
The key driving force behind the Internet of things is the MOSFET (metal-oxide-
semiconductor field-effect transistor, or MOS transistor),[18] which was originally
invented by Mohamed M. Atalla and Dawon Kahng at Bell Labs in 1959.[19][20] The
MOSFET is the basic building block of most modern electronics,
including computers, smartphones, tablets and Internet services. MOSFET
scaling miniaturization at a pace predicted by Dennard scaling and Moore's law has
been the driving force behind technological advances in the electronics industry since
the late 20th century. MOSFET scaling has been extended into the early 21st century
with advances such as reducing power consumption, silicon-on-
insulator (SOI) semiconductor device fabrication, and multi-core
processor technology, leading up to the Internet of things, which is being driven
by MOSFETs scaling down to nanoelectronic levels with reducing energy
consumption.
1.3 Trends and Characteristics
The IoT creates opportunities for more direct integration of the physical world into
computer-based systems, resulting in efficiency improvements, economic benefits,
and reduced human exertions
The number of IoT devices increased 31% year-over-year to 8.4 billion in the year
2012 and it is estimated that there will be 30 billion devices by 2020 The global
market value of IoT is projected to reach $7.1 trillion by 2020.
1.4 Features
Any IoT device comes up with the following features.
Connectivity: In the case of IoT, the most important feature one can consider
is connectivity. Without seamless communication among the interrelated
components of the IoT ecosystems (i.e. sensors, compute engines, data hubs,
etc.) it is not possible to execute any proper business use case. IoT devices
can be connected over Radio waves, Bluetooth, Wi-Fi, Li-Fi, etc. We can
leverage various protocols of internet connectivity layers in order to
maximize efficiency and establish generic connectivity across IoT ecosystems
and Industry. There may be special cases where the IoT ecosystem is built on-
premises or in an intranet.
Scale: IoT devices should be designed in such a way that they can be scaled
up or down easily on demand. In general, IoT is being used from smart home
automation to automating large factories and workstations, so the use cases
vary in scale. A carrier should design their IoT infrastructure depending upon
their current and future engagement scale.
Dynamic Nature: For any IoT use case, the first and foremost step is to
collecting and converting data in such a way that means business decisions
can be made out of it. In this whole process, various components of IoT need
to change their state dynamically. For example, the input of a temperature
sensor will vary continuously based on weather conditions, locations, etc. IoT
devices should be designed this keeping in mind.
Intelligence: In almost every IoT use cases in today’s world, the data is used
to make important business insights and drive important business decisions.
We develop machine learning/ deep learning models on top of this massive
data to obtain valuable insights. The analog signals are preprocessed and
converted to a format on which machine-learning models are trained. We need
to keep in mind the proper data infrastructure based on business needs.
Energy: From end components to connectivity and analytics layers, the whole
ecosystems demand a lot of energy. While designing an IoT ecosystem, we
need to consider design methodology such that energy consumption is minimal.
1.5 IOT PROTOCOLS
IoT primarily exploits standard protocols and networking technologies.
However, the major enabling technologies and protocols of IoT are RFID, NFC, low-
energy Bluetooth, low-energy wireless, low-energy radio protocols, LTE-A, and Wi-
Fi-Direct. These technologies support the specific networking functionality needed
in an IoT system in contrast to a standard uniform network of common systems.
LOW-ENERGY BLUETOOTH:
This technology supports the low-power, long-use need of IoT function while
exploiting a standard technology with native support across systems.
LOW-ENERGY WIRELESS:
This technology replaces the most power-hungry aspect of an IoT system. Though
sensors and other elements can power down over long periods, communication links
(i.e., wireless) must remain in listening mode. Low-energy wireless not only reduces
consumption, but also extends the life of the device through less use.
RADIO PROTOCOLS:
ZigBee, Z-Wave, and Thread are radio protocols for creating low-rate private area
networks. These technologies are low power but offer high throughput unlike many
similar options. This increases the power of small local device networks without the
typical costs.
LTE-A:
LTE-A, or LTE Advanced, delivers an important upgrade to LTE technology by
increasing not only its coverage, but also reducing its latency and raising its
throughput. It gives IoT a tremendous power through expanding its range, with its
most significant applications being vehicle, UAV, and similar communication.
WI-FI-DIRECT:
Wi-Fi-Direct eliminates the need for an access point. It allows P2P (peer-to-
peer) connections with the speed of Wi-Fi, but with lower latency. Wi-Fi-Direct
eliminates an element of a network that often bogs it down, and it does not
compromise on speed or throughput.
Smart Home:
Whenever we think of IoT systems, the most important and efficient application that
stands out every time is Smart Home ranking as highest IOT application on all
channels. The number of people searching for smart homes increases every month
with about 60,000 people and increasing. Another interesting thing is that the database
of smart homes for IoT Analytics includes 256 companies and startups. More
companies are now actively being involved in smart homes than similar other
applications in the field of IoT. The estimated amount of funding for Smart Home
startups exceeds $2.5bn and is ever growing. The list of startups includes prominent
startup company names such as AlertMe or Nest as well as a number of multinational
corporations like Philips, Haier, or Belkin etc.
Let’s See Thing Worx IoT – Foundation, Studio, Components & Interface.
Various types of wireless technology and networks allow devices to speak (send data)
to each other and to the web (TCP/IP Networks) without cables. There are a number
of different wireless technologies out there that can be implemented in hardware
products for the Internet of Things (IoT) and Machine to Machine
(M2M) communication.
The Institute of Electrical and Electronics Engineers (IEEE) has seven task groups in
place for 802.15 technologies. Those groups set the standards for common types of
wireless technologies used for personal area networks. Those 802.15 task groups
include: WPAN/Bluetooth, Coexistence, High Rate WPAN, Low Rate WPAN, mesh
Networking, Body Area Networks, and Visible Light Communication. Each
IEEE protocol has its own distinctive advantages and limitations. Promising
developments expand their potential applications and uses.
The ZigBee protocol offers 128-bit AES encryption. The technology is also
used in Mesh networks, which allow nodes to be connected together through
multiple pathways. The wireless technology is hoped to ultimately be implemented in
things like smart home devices. The technology's ability to connect multiple devices
together simultaneously makes it ideal for a connected home environment where users
may want things like smart locks, lights, robots and thermostats to talk to one another.
The ZigBee Alliance recently standardized the technology in the hope to make that
connectivity possible. Currently all ZigBee devices are not capable of talking to all
other ZigBee devices. The hope is that standardization will correct that issue and that
the devices will offer a uniform experience for the end user.
At Link Labs, many of our customers are former ZigBee users, but found that range
and performance limited their applications.
WiFi uses radio waves (RF) to allow two devices to communicate with one
another. The technology is most commonly used to connect Internet routers to
devices like computers, tablets and phones; however, it can be used to connect
together any two hardware components. WiFi is a local wireless network that runs of
the 802.11 standards set forth by the Institute of Electrical and Electronics Engineers
(IEEE).
WiFi can utilize both the global 2.4GHz UHF and 5GHz SHF ISM radio bands. The
WiFi Alliance certifies some products, allowing them to be labeled as ―Wi-Fi
Certified.‖ In order to receive that designation, and product must go through the
Alliance’s interoperability certification testing.
802.11b, 802.11g, and 802.11n run on the 2.4GHz ISM band. The band is susceptible
to interference from some Bluetooth devices as well as some microwave ovens and
cordless phones. Devices that run on either band can be operated in the United States
without a license from the FCC, but still require FCC part 15 certification. The first
six channels of frequencies from each are considered part of the amateur radio band.
Bluetooth and Bluetooth Low Energy (BLE) are wireless technologies used to transfer
data over short distances. The technology is frequently used in small consider devices
that connect to users phones and tablets. For instance, the technology is used in many
speaker systems. Bluetooth Low Energy uses less power than standard Bluetooth and
is used in hardware such as fitness trackers, smart watches and other
connected devices in order to wirelessly transmit data without heavily compromising
the battery power in a user’s phone.
BLE has only recently started to pick up steam. The technology was initially
introduced by smartphone maker Nokia in 2006 but didn’t become part of Bluetooth
standard until 2010. Today, BLE, which is also referred to as Bluetooth Smart, is
supported by the majority of smartphone and computer makers as well as most major
operating systems including Windows 8, OS X, Linux, Windows Phone, Android and
iOS.
Bluetooth uses UHF radio waves for data transfer. The technology was originally
standardized as IEEE 802.15.1, but the IEEE no longer maintains that specific
standard. Companies that work with Bluetooth are often affiliated with the Bluetooth
Special Interest group (SIG). The group currently has over 20,000 members and must
certify a product before it can be marketed as a Bluetooth device to the consumer or
business market. That certification helps ensure that all Bluetooth devices work in a
standardized way and provide a similar experience for consumers.
The WiMax Forum certifies devices before they can be sold to consumer or
businesses. The technology can be used both indoors and outdoors, however, WiMax
devices typically produce a better signal when used outside or by a window.
Link Labs builds a new type of wireless technology, called Symphony Link.
Symphony Link solves many of the range and performance issues of the technologies
listed above.
1.8 Wireless Communication
Different types of signals are used in communication between the devices for wireless
transmission of data. The following are the different electromagnetic signals are used
depending on their wavelength and frequency.
Drawbacks:
These are frequency dependent
These have the relatively low bandwidth for data transmission.
Infrared Transmission:
Microwave Transmission:
Drawbacks
Lightwave Transmission:
LITERATURE SURVEY
Introduction
IoT is a trending concept in which the machines or things are made to interact with
the environment by exchanging data and information sensed by the sensors. The
devices gather information and data from the surrounding environment by using
various latest technologies and then there is a data flow between devices. Typically,
IoT offers advanced connectivity of devices, systems, and services which is beyond
machine-to-machine communications (M2M) and covers a variety of protocols,
domains, and applications. The interconnection of these embedded devices will usher
in automation in nearly all fields, right from a Smart Grid, to the areas such as smart
cities. IoT is a concept which is expected to rule the world within a few years.
Literature survey:
N. Srikanth and Tan Karanda in their work have presented an application of Bluetooth
Technology for Home Automation. The Bluetooth technology which emerged in late
1990's is used for implementing the wireless home automation system. Various
appliances such as air conditioners, home theatres, cellular phones etc., are
interconnected, thus creating a Personal Area Network in Home Environment. The
communication between several client modules and the host server takes place
through the Bluetooth module. A Home Automation Protocol has been developed to
enhance communication between the host server and the client modules. The system
also allows integration or removal of devices to the network which makes the system
scalable. The wireless system aims at reducing the cost of Home Automation. But the
system does not use the trending mobile technology. A. Z. Alkar and U. Buhur have
developed an internet based wireless home automation system for multifunctional
devices. A flexible, low cost, wireless solution to the home automation is introduced.
The transformation of the initial simple functionality control mechanism of devices to
more complex devices has been discussed. The home appliances are connected
through a server to a central node. The system is secured from unauthorized users by
using SSL algorithm.
CHAPTER 3
The existing works were mainly focused on switching and controlling home
appliances or connected devices rather than remotely monitoring of home
environment.
Bluetooth module TX and RX pins are connected to the RXD and TXD pins of
controller. GND pin is connected to ground and Vcc pin is connected to the 5V. Serial
communication (UART protocol) is used by the controller to communicate with
Bluetooth module. To communicate with Bluetooth, a baud rate of 9600 is used. The
Bluetooth name and password can be changed by using Bluetooth AT commands.
3.2 Proposed system
Compare the received string with predefined strings and accordingly switch the
Electrical loads.
The system is installed beside the conventional electrical switches on the wall. The
risk of dangerous electric shocks can be avoided by using low voltage switches. The
system uses two GUIs- one on the personal computer and the other on Smartphone.
The status of the appliances i.e. weather it is on/off can be known by using this GUI.
Any changes in the status of the appliances, immediate intimation is shown on the
GUI. The window GUI will act as a server to forward or transmit any data to/from the
Smartphone and the main control board, after the Smartphone’s Bluetooth is
connected to the Bluetooth of the computer. In case, the Bluetooth connection
between the PC or laptop and the control board fails, then connection can be re-
established by using USB cable.
HARDWARE COMPONENTS
NodeMCU Dev Kit/board consist of ESP8266 wifi enabled chip. The ESP8266 is a
low-cost Wi-Fi chip developed by Espressif Systems with TCP/IP protocol. For more
information about ESP8266, you can refer ESP8266 WiFi Module.
There is Version2 (V2) available for NodeMCU Dev Kit i.e. NodeMCU
Development Board v1.0 (Version2), which usually comes in black colored PCB.
Fig:4.3 NodeMCU Development Board/kit v1.0 (Version2)
For more information about NodeMCU Boards available in market refer NodeMCU
Development Boards
NodeMCU Dev Kit has Arduino like Analog (i.e. A0) and Digital (D0-D8) pins on
its board.
Using such serial protocols, we can connect it with serial devices like I2C enabled
LCD display, Magnetometer HMC5883, MPU-6050 Gyro meter + Accelerometer,
RTC chips, GPS modules, touch screen displays, SD cards etc.
4.1.1 FEATURES:
The Internet of Things (IoT) has been a trending field in the world of technology. It
has changed the way we work. Physical objects and the digital world are connected
now more than ever. Keeping this in mind, Espressif Systems (A Shanghai-based
Semiconductor Company) has released an adorable, bite-sized WiFi enabled
microcontroller – ESP8266, at an unbelievable price! For less than $3, it can monitor
and control things from anywhere in the world – perfect for just about any IoT
project.
ESP-12E MODULE:
The development board equips the ESP-12E module containing ESP8266 chip
having Tensilica Xtensa32-bit LX106 RISC microprocessor which operates at 80 to
160 MHz adjustable clock frequency and supports RTOS.
ESP-12E Chip
Tensilica Xtensa® 32-bit LX106
80 to 160 MHz Clock Freq.
128kB internal RAM
4MB external flash
802.11b/g/n Wi-Fi transceiver
The ESP8266 Integrates 802.11b/g/n HT40 Wi-Fi transceiver, so it can not only
connect to a WiFi network and interact with the Internet, but it can also set up a
network of its own, allowing other devices to connect directly to it. This makes the
ESP8266 NodeMCU even more versatile.
POWER REQUIREMENT:
As the operating voltage range of ESP8266 is 3V to 3.6V, the board comes with a
LDO voltage regulator to keep the voltage steady at 3.3V. It can reliably supply up to
600mA, which should be more than enough when ESP8266 pulls as much as 80mA
during RF transmissions. The output of the regulator is also broken out to one of the
sides of the board and labeled as 3V3. This pin can be used to supply power to
external components.
Power Requirement
Operating Voltage: 2.5V to 3.6V
On-board 3.3V 600mA regulator
80mA Operating Current
20 µA during Sleep Mode
Power to the ESP8266 NodeMCU is supplied via the on-board MicroB USB
connector. Alternatively, if you have a regulated 5V voltage source, the VIN pin can
be used to directly supply the ESP8266 and its peripherals.
Warning:
The ESP8266 requires a 3.3V power supply and 3.3V logic levels for
communication. The GPIO pins are not 5V-tolerant! If you want to interface
the board with 5V (or higher) components, you’ll need to do some level
shifting.
PERIPHERALS AND I/O:
The ESP8266 NodeMCU has total 17 GPIO pins broken out to the pin headers on
both sides of the development board. These pins can be assigned to all sorts of
peripheral duties, including:
SPI, I2C & I2S interface – SPI and I2C interface to hook up all sorts of sensors and
peripherals.
I2S interface – I2S interface if you want to add sound to your project.
Multiplexed I/Os
1 ADC channels
2 UART interfaces
4 PWM outputs
SPI, I2C & I2S interface
The ESP8266 NodeMCU features two buttons. One marked as RST located on the top
left corner is the Reset button, used of course to reset the ESP8266 chip. The
other FLASH button on the bottom left corner is the download button used while
upgrading firmware.
The board also has a LED indicator which is user programmable and is connected to
the D0 pin of the board.
COMMUNICATION:
The board includes CP2102 USB-to-UART Bridge Controller from Silicon Labs,
which converts USB signal to serial and allows your computer to program and
communicate with the ESP8266 chip.
Serial Communication
If you have an older version of CP2102 driver installed on your PC, we recommend
upgrading now.
The ESP8266 NodeMCU has total 30 pins that interface it to the outside world. The
connections are as follows:
Fig:4.9 pin layout
For the sake of simplicity, we will make groups of pins with similar functionalities.
Power Pins There are four power pins viz. one VIN pin & three 3.3V pins. The VIN
pin can be used to directly supply the ESP8266 and its peripherals, if you have a
regulated 5V voltage source. The 3.3V pins are the output of an on-board voltage
regulator. These pins can be used to supply power to external components.
GND is a ground pin of ESP8266 NodeMCU development board.
I2C Pins are used to hook up all sorts of I2C sensors and peripherals in your project.
Both I2C Master and I2C Slave are supported. I2C interface functionality can be
realized programmatically, and the clock frequency is 100 kHz at a maximum. It
should be noted that I2C clock frequency should be higher than the slowest clock
frequency of the slave device.
GPIO Pins ESP8266 NodeMCU has 17 GPIO pins which can be assigned to various
functions such as I2C, I2S, UART, PWM, IR Remote Control, LED Light and Button
programmatically. Each digital enabled GPIO can be configured to internal pull-up or
pull-down, or set to high impedance. When configured as an input, it can also be set
to edge-trigger or level-trigger to generate CPU interrupts.
ADC Channel The NodeMCU is embedded with a 10-bit precision SAR ADC. The
two functions can be implemented using ADC viz. Testing power supply voltage of
VDD3P3 pin and testing input voltage of TOUT pin. However, they cannot be
implemented at the same time.
UART Pins ESP8266 NodeMCU has 2 UART interfaces, i.e. UART0 and UART1,
which provide asynchronous communication (RS232 and RS485), and can
communicate at up to 4.5 Mbps. UART0 (TXD0, RXD0, RST0 & CTS0 pins) can be
used for communication. It supports fluid control. However, UART1 (TXD1 pin)
features only data transmit signal so, it is usually used for printing log.
SPI Pins ESP8266 features two SPIs (SPI and HSPI) in slave and master modes.
These SPIs also support the following general-purpose SPI features:
used to directly interface SD cards. 4-bit 25 MHz SDIO v1.1 and 4-bit 50 MHz SDIO
v2.0 are supported.
PWM Pins The board has 4 channels of Pulse Width Modulation (PWM). The PWM
output can be implemented programmatically and used for driving digital motors and
LEDs. PWM frequency range is adjustable from 1000 μs to 10000 μs, i.e., between
100 Hz and 1 kHz.
Control Pins are used to control ESP8266. These pins include Chip Enable pin (EN),
Reset pin (RST) and WAKE pin.
EN pin – The ESP8266 chip is enabled when EN pin is pulled HIGH. When pulled
LOW the chip works at minimum power.
WAKE pin – Wake pin is used to wake the chip from deep-sleep.
4.2 Relay
The traditional form of a relay uses an electromagnet to close or open the contacts, but
other operating principles have been invented, such as in solid-state relays which
use semiconductor properties for control without relying on moving parts. 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.
Latching relays require only a single pulse of control power to operate the switch
persistently. Another pulse applied to a second set of control terminals, or a pulse with
opposite polarity, resets the switch, while repeated pulses of the same kind have no
effects. Magnetic latching relays are useful in applications when interrupted power
should not affect the circuits that the relay is controlling.
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(s) 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 trans is tors
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.
If the relay is driving a large, or especially a reactive load, there may be a similar
problem of surge currents around the relay output contacts. In this case
a snubber circuit (a capacitor and resistor in series) across the contacts may absorb the
surge. Suitably rated capacitors and the associated resistor are sold as a single
packaged component for this commonplace use.
If the coil is designed to be energized with alternating current (AC), some method is
used to split the flux into two out-of-phase components which add together,
increasing the minimum pull on the armature during the AC cycle. Typically, this is
done with a small copper "shading ring" crimped around a portion of the core that
creates the delayed, out-of-phase component, which holds the contacts during the zero
crossings of the control voltage.
Contact materials for relays vary by application. Materials with low contact resistance
may be oxidized by the air or may tend to "stick" instead of cleanly parting when
opening. Contact material may be optimized for low electrical resistance, high
strength to withstand repeated operations, or high capacity to withstand the heat of an
arc. Where very low resistance is required, or low thermally induced voltages are
desired, gold-plated contacts may be used, along with palladium and other non-
oxidizing, semi-precious metals. Silver or silver-plated contacts are used for signal
switching. Mercury-wetted relays make and break circuits using a thin, self-renewing
film of liquid mercury. For higher-power relays switching many amperes, such as
motor circuit contactors, contacts are made with a mixtures of silver and cadmium
oxide, providing low contact resistance and high resistance to the heat of arcing.
Contacts used in circuits carrying scores or hundreds of amperes may include
additional structures for heat dissipation and management of the arc produced when
interrupting the circuit. Some relays have field-replaceable contacts, such as certain
machine tool relays; these may be replaced when worn out, or changed between
normally open and normally closed state, to allow for changes in the controlled
circuit.
Pole and throw:
Since relays are switches, the terminology applied to switches is also applied to
relays; a relay switches one or more poles, each of whose contacts can be thrown by
energizing the coil. Normally open (NO) contacts connect the circuit when the relay is
activated; the circuit is disconnected when the relay is inactive. Normally closed (NC)
contacts disconnect the circuit when the relay is activated; the circuit is connected
when the relay is inactive. All of the contact forms involve combinations of NO and
NC connections.
The National Association of Relay Manufacturers and its successor, the Relay and
Switch Industry Association define 23 distinct electrical contact forms found in relays
and switches. Of these, the following are commonly encountered:
SPST-NO (Single-Pole Single-Throw, Normally-Open) relays have a single Form
A contact or make contact. These have two terminals which can be connected or
disconnected. Including two for the coil, such a relay has four terminals in total.
SPST-NC (Single-Pole Single-Throw, Normally-Closed) relays have a
single Form B or break contact. As with an SPST-NO relay, such a relay has four
terminals in total.
SPDT (Single-Pole Double-Throw) relays have a single set of Form C, break
before make or transfer contacts. That is, a common terminal connects to either of
two others, never connecting to both at the same time. Including two for the coil,
such a relay has a total of five terminals.
DPST – Double-Pole Single-Throw relays are equivalent to a pair of SPST
switches or relays actuated by a single coil. Including two for the coil, such a
relay has a total of six terminals. The poles may be Form A or Form B (or one of
each; the designations NO and NC should be used to resolve the ambiguity).
DPDT – Double-Pole Double-Throw relays have two sets of Form C contacts.
These are equivalent to two SPDT switches or relays actuated by a single coil.
Such a relay has eight terminals, including the coil
Form D – make before break
Form E – combination of D and B
The S (single) or D (double) designator for the pole count may be replaced with a
number, indicating multiple contacts connected to a single actuator. For example,
4PDT indicates a four-pole double-throw relay that has 12 switching terminals.
EN 50005 are among applicable standards for relay terminal numbering; a typical EN
50005-compliant SPDT relay's terminals would be numbered 11, 12, 14, A1 and A2
for the C, NC, NO, and coil connections, respectively.
85 = relay coil -
86 = relay coil +
87 = common contact
87a = normally closed contact
87b = normally open contact
4.2.2 Types of relay:
Coaxial relay:
Where radio transmitters and receivers share one antenna, often a coaxial relay is used
as a TR (transmit-receive) relay, which switches the antenna from the receiver to the
transmitter. This protects the receiver from the high power of the transmitter. Such
relays are often used in transceivers which combine transmitter and receiver in one
unit. The relay contacts are designed not to reflect any radio frequency power back
toward the source, and to provide very high isolation between receiver and transmitter
terminals. The characteristic impedance of the relay is matched to the transmission
line impedance of the system, for example, 50 ohms.
Contactor:
A contactor is a heavy-duty relay with higher current ratings, [14] used for switching
electric motors and lighting loads. Continuous current ratings for common contactors
range from 10 amps to several hundred amps. High-current contacts are made with
alloys containing silver. The unavoidable arcing causes the contacts to oxidize;
however, silver oxide is still a good conductor. Contactors with overload protection
devices are often used to start motors.
A force-guided contacts relay has relay contacts that are mechanically linked together,
so that when the relay coil is energized or de-energized, all of the linked contacts
move together. If one set of contacts in the relay becomes immobilized, no other
contact of the same relay will be able to move. The function of force-guided contacts
is to enable the safety circuit to check the status of the relay. Force-guided contacts
are also known as "positive-guided contacts", "captive contacts", "locked contacts",
"mechanically linked contacts", or "safety relays".
These safety relays have to follow design rules and manufacturing rules that are
defined in one main machinery standard EN 50205 : Relays with forcibly guided
(mechanically linked) contacts. These rules for the safety design are the one that are
defined in type B standards such as EN 13849-2 as Basic safety principles and Well-
tried safety principles for machinery that applies to all machines.
Force-guided contacts by themselves can not guarantee that all contacts are in the
same state, however they do guarantee, subject to no gross mechanical fault, that no
contacts are in opposite states. Otherwise, a relay with several normally open (NO)
contacts may stick when energised, with some contacts closed and others still slightly
open, due to mechanical tolerances. Similarly, a relay with several normally closed
(NC) contacts may stick to the unenergised position, so that when energised, the
circuit through one set of contacts is broken, with a marginal gap, while the other
remains closed. By introducing both NO and NC contacts, or more commonly,
changeover contacts, on the same relay, it then becomes possible to guarantee that if
any NC contact is closed, all NO contacts are open, and conversely, if any NO contact
is closed, all NC contacts are open. It is not possible to reliably ensure that any
particular contact is closed, except by potentially intrusive and safety-degrading
sensing of its circuit conditions, however in safety systems it is usually the NO state
that is most important, and as explained above, this is reliably verifiable by detecting
the closure of a contact of opposite sense.
Force-guided contact relays are made with different main contact sets, either NO, NC
or changeover, and one or more auxiliary contact sets, often of reduced current or
voltage rating, used for the monitoring system. Contacts may be all NO, all NC,
changeover, or a mixture of these, for the monitoring contacts, so that the safety
system designer can select the correct configuration for the particular application.
Safety relays are used as part of an engineered safety system.
Latching relay:
Another latching type has a reagent core that retains the contacts in the operated
position by the remanent magnetism in the core. This type requires a current pulse of
opposite polarity to release the contacts. A variation uses a permanent magnet that
produces part of the force required to close the contact; the coil supplies sufficient
force to move the contact open or closed by aiding or opposing the field of the
permanent magnet.[17] A polarity controlled relay needs changeover switches or an H
bridge drive circuit to control it. The relay may be less expensive than other types, but
this is partly offset by the increased costs in the external circuit.
In another type, a ratchet relay has a ratchet mechanism that holds the contacts closed
after the coil is momentarily energized. A second impulse, in the same or a separate
coil, releases the contacts. [17] This type may be found in certain cars,
for headlamp dipping and other functions where alternating operation on each switch
actuation is needed.
A stepping relay is a specialized kind of multi-way latching relay designed for early
automatic telephone exchanges.
Very early computers often stored bits in a magnetically latching relay, such
as ferreed or the later remreed in the 1ESS switch.
IOT Based Home Automation Can be Controlled Audio with Multi Languages
Some early computers used ordinary relays as a kind of latch—they store bits in
ordinary wire spring relays or reed relays by feeding an output wire back as an input,
resulting in a feedback loop or sequential circuit. Such an electrically latching relay
requires continuous power to maintain state, unlike magnetically latching relays or
mechanically racheting relays.
In computer memories, latching relays and other relays were replaced by delay line
memory, which in turn was replaced by a series of ever-faster and ever-smaller
memory technologies.
A machine tool relay is a type standardized for industrial control of machine tools,
transfer machines, and other sequential control. They are characterized by a large
number of contacts (sometimes extendable in the field) which are easily converted
from normally open to normally closed status, easily replaceable coils, and a form
factor that allows compactly installing many relays in a control panel. Although such
relays once were the backbone of automation in such industries as automobile
assembly, the programmable logic controller (PLC) mostly displaced the machine tool
relay from sequential control applications.
Mercury relay:
A mercury relay is a relay that uses mercury as the switching element. They are used
where contact erosion would be a problem for conventional relay contacts. Owing to
environmental considerations about significant amount of mercury used and modern
alternatives, they are now comparatively uncommon.
A mercury-wetted reed relay is a form of reed relay that employs a mercury switch, in
which the contacts are wetted with mercury. Such relays are used to switch low-
voltage signals (one volt or less). Mercury reduces the contact resistance and
mitigates the associated voltage drop. Surface contamination may result in poor
conductivity for low-current signals. For high-speed applications, the mercury
eliminates contact bounce, and provides virtually instantaneous circuit closure.
Mercury wetted relays are position-sensitive and must be mounted according to the
manufacturer's specifications. Because of the toxicity and expense of liquid mercury,
these relays have increasingly fallen into disuse.
The same coalescence process causes another effect, which is a nuisance in some
applications. The contact resistance is not stable immediately after contact closure,
and drifts, mostly downwards, for several seconds after closure, the change perhaps
being 0.5 ohm.
Multi-voltage relays:
Multi-voltage relays are devices designed to work for wide voltage ranges such as 24
to 240 VAC and VDC and wide frequency ranges such as 0 to 300 Hz. They are
indicated for use in installations that do not have stable supply voltages.
Electric motors need overcurrent protection to prevent damage from over-loading the
motor, or to protect against short circuits in connecting cables or internal faults in the
motor windings. The overload sensing devices are a form of heat operated relay where
a coil heats a bimetallic strip, or where a solder pot melts, to operate auxiliary
contacts. These auxiliary contacts are in series with the motor's contactor coil, so they
turn off the motor when it overheats.
This thermal protection operates relatively slowly allowing the motor to draw higher
starting currents before the protection relay will trip. Where the overload relay is
exposed to the same ambient temperature as the motor, a useful though crude
compensation for motor ambient temperature is provided.
The other common overload protection system uses an electromagnet coil in series
with the motor circuit that directly operates contacts. This is similar to a control relay
but requires a rather high fault current to operate the contacts. To prevent short over
current spikes from causing nuisance triggering the armature movement is damped
with a dashpot. The thermal and magnetic overload detections are typically used
together in a motor protection relay.
Electronic overload protection relays measure motor current and can estimate motor
winding temperature using a "thermal model" of the motor armature system that can
be set to provide more accurate motor protection. Some motor protection relays
include temperature detector inputs for direct measurement from
a thermocouple or resistance thermometer sensor embedded in the winding.
Polarized relay:
A polarized relay places the armature between the poles of a permanent magnet to
increase sensitivity. Polarized relays were used in middle 20th Century telephone
exchanges to detect faint pulses and correct telegraphic distortion.
Reed relay:
(from top) Single-pole reed switch, four-pole reed switch and single-pole reed relay. Scale in centimeters.
A reed relay is a reed switch enclosed in a solenoid. The switch has a set of contacts
inside an evacuated or inert gas-filled glass tube that protects the contacts against
atmospheric corrosion; the contacts are made of magnetic material that makes them
move under the influence of the field of the enclosing solenoid or an external magnet.
Reed relays can switch faster than larger relays and require very little power from the
control circuit. However, they have relatively low switching current and voltage
ratings. Though rare, the reeds can become magnetized over time, which makes them
stick "on", even when no current is present; changing the orientation of the reeds
or degaussing the switch with respect to the solenoid's magnetic field can resolve this
problem.
Sealed contacts with mercury-wetted contacts have longer operating lives and less
contact chatter than any other kind of relay.
Safety relays:
Safety relays are devices which generally implement protection functions. In the event
of a hazard, the task of such a safety function is to use appropriate measures to reduce
the existing risk to an acceptable level.[22]
Solid-state contactor:
A solid-state contactor is a heavy-duty solid state relay, including the necessary heat
sink, used where frequent on-off cycles are required, such as with electric heaters,
small electric motors, and lighting loads. There are no moving parts to wear out and
there is no contact bounce due to vibration. They are activated by AC control signals
or DC control signals from programmable logic controllers (PLCs), PCs, transistor-
transistor logic (TTL) sources, or other microprocessor and microcontroller controls.
Solid-state relay:
A solid-state relay (SSR) is a solid state electronic component that provides a function
similar to an electromechanical relay but does not have any moving components,
increasing long-term reliability. A solid-state relay uses a thyristor, TRIAC or other
solid-state switching device, activated by the control signal, to switch the controlled
load, instead of a solenoid. An optocoupler (a light-emitting diode (LED) coupled
with a photo transistor) can be used to isolate control and controlled circuits.
Static relay:
A static relay consists of electronic circuitry to emulate all those characteristics which
are achieved by moving parts in an electro-magnetic relay.
Time delay relay:
Timing relays are arranged for an intentional delay in operating their contacts. A very
short (a fraction of a second) delay would use a copper disk between the armature and
moving blade assembly. Current flowing in the disk maintains magnetic field for a
short time, lengthening release time. For a slightly longer (up to a minute) delay, a
dashpot is used. A dashpot is a piston filled with fluid that is allowed to escape
slowly; both air-filled and oil-filled dashpots are used. The time period can be varied
by increasing or decreasing the flow rate. For longer time periods, a mechanical
clockwork timer is installed. Relays may be arranged for a fixed timing period, or
may be field adjustable, or remotely set from a control panel. Modern microprocessor-
based timing relays provide precision timing over a great range.
Some relays are constructed with a kind of "shock absorber" mechanism attached to
the armature which prevents immediate, full motion when the coil is either energized
or de-energized. This addition gives the relay the property of time-delay actuation.
Time-delay relays can be constructed to delay armature motion on coil energization,
de-energization, or both.
Time-delay relay contacts must be specified not only as either normally open or
normally closed, but whether the delay operates in the direction of closing or in the
direction of opening. The following is a description of the four basic types of time-
delay relay contacts.
First, we have the normally open, timed-closed (NOTC) contact. This type of contact
is normally open when the coil is unpowered (de-energized). The contact is closed by
the application of power to the relay coil, but only after the coil has been continuously
powered for the specified amount of time. In other words, the direction of the
contact's motion (either to close or to open) is identical to a regular NO contact, but
there is a delay in closing direction. Because the delay occurs in the direction of coil
energization, this type of contact is alternatively known as a normally open, on-delay.
Vacuum relays:
A vacuum relay is a sensitive relay having its contacts mounted in an evacuated glass
housing, to permit handling radio-frequency voltages as high as 20,000 volts without
flashover between contacts even though contact spacing is as low as a few hundredths
of an inch when open.
Description:
8 Channel Relay Board is a simple and convenient way to interface 8 relays for
switching application in your project. Input voltage level support TTL as well as
CMOS. Easy interface with Microcontrollers based projects and analog circuits.
Specifications:
Screw terminal connector for easy relay output and aux power connection
PCB:
Fig: 4.19 PCB View
Ports Description:
Input:
4.4 Transformers
Transformers are most commonly used for increasing low AC voltages at high current
(a step-up transformer) or decreasing high AC voltages at low current (a step-down
transformer) in electric power applications, and for coupling the stages of signal
processing circuits. Transformers can also be used for isolation, where the voltage in
equals the voltage out, with separate coils not electrically bonded to one another.
Fig:4.20 Transformer
1. Step up transformer
2. Step down
A transformer in which the output (secondary) voltage is greater than its input
(primary) voltage is called a step-up transformer. The step-up transformer decreases
the output current for keeping the input and output power of the system equal.
Considered a step-up transformer shown in the figure below. The E1 and E2 are the
voltages, and T1 and T2 are the number of turns on the primary and secondary winding
of the transformer.
The number of turns on the secondary of the transformer is greater than that of the
primary, i.e., T2 > T1.Thus the voltage turn ratio of the step-up transformer is 1:2. The
primary winding of the step-up transformer is made up of thick insulated copper wire
because the low magnitude current flows through it.
Faraday’s law states that ―when the magnetic flux linking a circuit changes, an
electromotive force is induced in the circuit proportional to the rate of change of the
flux linkage‖.
The emf (Electro Motive Force) induced between the two windings is determined by
the number of turns in primary and secondary winding respectively. This ratio is
called as Turns Ratio.
The voltage reduction capability of step down transformers depends on the turn ratio
of the primary and secondary coil. As the number of windings in secondary coil is less
as compared to the number of windings in primary coil, so the amount of flux linkage
to the secondary coil of the transformer will also be less compared to the primary coil.
Accordingly, the emf induced will be less in the secondary coil. Due to this, the
voltage reduces at the secondary winding compared to primary winding.
Turns Ratio:
The voltage reduction capability of step-down transformers depends on the turn ratio
of the primary and secondary coil. As the number of windings in secondary coil is less
as compared to the number of windings in primary coil, so the amount of flux linkage
to the secondary coil of the transformer will also be less compared to the primary coil.
Accordingly, the emf induced will be less in the secondary coil. Due to this, the
voltage reduces at the secondary winding compared to primary winding.
Where,
Ns = number of turns in secondary
Vs = Voltage in secondary
Vp = Voltage in primary
The number of turns in secondary winding should always be less than the number of
turns in the primary winding of the transformer i.e. Np>Ns to work transformer as
―Step-Down Transformer‖.
As the number of turns will be less in secondary winding, so will be total induced emf
and hence the output voltage in the secondary will also be less than the primary input
voltage.
Fig: 4.22 Symbol and Physical View of Single Phase Step Down Transformer
Center Tapped Step Down Transformer:
This type of Step-Down Transformers will be having one primary winding and a
center split in the secondary winding, by which it gives the output voltage with the
center pint.
Ex: 12v-0-12v.
Fig: 4.23 Symbol and Physical View of Center Tapped Step Down Transformer
Multi Tapped Step Down transformer:
This type of Step-Down Transformers has multiple tapping in Secondary coil.
Multiple Tapping are used to get the desired varied output with secondary coils.
Fig: 4.24 Symbol and Physical View of Multi Tapped Step Down Transformer
4.4.3 STEPS TO CONVERT THE 230V AC TO 12V DC USING STEP DOWN
CONVERTER:
Every electrical and electronic device that we use in our day-to-day life will
require a power supply. In general, we use an AC supply of 230V 50Hz, but this
power has to be changed into the required form with required values or voltage range
for providing power supply to different types of devices. There are various types of
power electronic converters such as step-down converter, step-up converter, voltage
stabilizer, AC to DC converter, DC to DC converter, DC to AC converter, and so on.
For example, consider the microcontrollers that are used frequently for developing
many embedded systems’ based projects and kits used in real-time applications. These
microcontrollers require a 12V DC supply, so the AC 230V needs to be converted
into 12V DC using the step-down converter in their power supply circuit.
3 Steps to Convert 230V AC to 12V
DC 1.Step Down the Voltage Level
The step-down converters are used for converting the high voltage into low voltage.
The converter with output voltage less than the input voltage is called as a step-down
converter, and the converter with output voltage greater than the input voltage is
called as step-up converter. There are step-up and step-down transformers which are
used to step up or step down the voltage levels. 230V AC is converted into 12V AC
using a step-down transformer. 12V output of stepdown transformer is an RMS value
and its peak value is given by the product of square root of two with RMS value,
which is approximately 17V.
2. Convert AC to DC:
230V AC power is converted into 12V AC (12V RMS value wherein the peak value
is around 17V), but the required power is 5V DC; for this purpose, 17V AC power
must be primarily converted into DC power then it can be stepped down to the 5V
DC. But first and foremost, we must know how to convert AC to DC? AC power can
be converted into DC using one of the power electronic converters called as Rectifier.
There are different types of rectifiers, such as half-wave rectifier, full-wave rectifier
and bridge rectifier.
Due to the advantages of the bridge rectifier over the half and full wave rectifier, the
bridge rectifier is frequently used for converting AC to DC.
Bridge rectifier consists of four diodes which are connected in the form a bridge. We
know that the diode is an uncontrolled rectifier which will conduct only forward bias
and will not conduct during the reverse bias. If the diode anode voltage is greater than
the cathode voltage then the diode is said to be in forward bias. During positive half
cycle, diodes D2 and D4 will conduct and during negative half cycle diodes D1 and
D3 will conduct. Thus, AC is converted into DC; here the obtained is not a pure DC
as it consists of pulses. Hence, it is called as pulsating DC power. But voltage drop
across the diodes is (2*0.7V) 1.4V; therefore, the peak voltage at the output of this
rectifier circuit is 15V (17-1.4) approx.
15V DC can be regulated into 5V DC using a step-down converter, but before this, it
is required to obtain pure DC power. The output of the diode bridge is a DC
consisting of ripples also called as pulsating DC. This pulsating DC can be filtered
using an inductor filter or a capacitor filter or a resistor-capacitor-coupled filter for
removing the ripples. Consider a capacitor filter which is frequently used in most
cases for smoothing.
The output of full wave rectifier has low ripples compared to half-wave rectifier but
still, it’s not smooth and steady.
In order to make the output voltage smooth & steady, a capacitor is placed at the
output as shown in the figure below.
The capacitor charge & discharges which make smooth transitions between the half
cycles.
CHAPTER 5
SOFTWARE
After setting up ESP8266 with Node-MCU firmware, let’s see the IDE
(Integrated Development Environment) required for development of NodeMCU.
Lua scripts are generally used to code the NodeMCU. Lua is an open source,
lightweight, embeddable scripting language built on top of C programming language.
Arduino IDE:
NodeMCU is Lua based firmware of ESP8266. Generally, ESPlorer IDE is referred
for writing Lua scripts for NodeMCU. It requires to get familiar with ESPlorer IDE
and Lua scripting language.
There is another way of developing NodeMCU with a well-known IDE i.e. Arduino
IDE. We can also develop NodeMCU applications using Arduino development
environment. This makes things easy for Arduino developers than learning new
language and IDE for NodeMCU.
Now
on
Preference
window, En
ter below
link in
Additional
Boards
Manager URLs
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Now close Preference window and go to Tools -> Board -> Boards Manager
In Boards Manager window, Type esp in the search box, esp8266 will be
listed there below. Now select latest version of board and click on
install.
EXAMPLE:
Let’s see how to write simple serial print sketch using Arduino IDE for NodeMCU.
First connect NodeMCU Development Kit with PC as shown in below figure.
After setting up Arduino IDE for NodeMCU, open Arduino IDE and write
simple sketch of serial print as shown in below figure.
CHAPTER 6
6.2 Application
This project proposes to create Smart Home with the help of internet of
things.
CHAPTER
7 RESULT
After the successful connection to the server, the data of sensor are sent to the web
server for monitoring of the system. By entering the assigned IP address in the web
browser this web server page will appear. The web server gives the information about
the temperature in different places of the house and motion state in the house. It also
gives the status of the various electrical appliances like light, fan etc which we can
control remotely. The stored data can be analyzed at anytime and anywhere.And also
it shows the state of the motion detector along with the time. It also provides
information about time of motion detected and how many times as well. All this
information is stored in the cloud which can be checked by the user any time when
away from home.
CHAPTER 8
8.1 CONCLUSION
8.2 REFERENCES
Chan, M., Campo, E., Esteve, D., Fourniols, J.Y., ―Smart homes-current
features and future perspectives,‖ Maturitas, vol. 64, issue 2, pp. 90-97, 2009.
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#define Relay1 D1
#define Relay2 D2
#define Relay3 D3
#define Relay4 D4
#define Relay5 D5
#define Relay6 D6
#define Relay7 D7
// 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/Relay1"); // FeedName
Adafruit_MQTT_Subscribe Light2 = Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME "/feeds/Relay2");
Adafruit_MQTT_Subscribe Light3 = Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME "/feeds/Relay3");
Adafruit_MQTT_Subscribe Light4 = Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME "/feeds/Relay4");
Adafruit_MQTT_Subscribe Light5 = Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME"/feeds/Relay5"); // FeedName
Adafruit_MQTT_Subscribe Light6 = Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME "/feeds/Relay6");
Adafruit_MQTT_Subscribe Light7 = Adafruit_MQTT_Subscribe(&mqtt,
AIO_USERNAME "/feeds/Relay7");
void MQTT_connect();
void setup()
{ Serial.begin(115200);
pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(Relay3, OUTPUT);
pinMode(Relay4, OUTPUT);
pinMode(Relay5, OUTPUT);
pinMode(Relay6, OUTPUT);
pinMode(Relay7, OUTPUT);
// 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);
mqtt.subscribe(&Light3);
mqtt.subscribe(&Light2);
mqtt.subscribe(&Light4);
mqtt.subscribe(&Light5);
mqtt.subscribe(&Light6);
mqtt.subscribe(&Light7);
}
void loop()
{ MQTT_connect
();
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(Relay1, Light1_State);
}
if (subscription == &Light2)
{ Serial.print(F("Got: "));
Serial.println((char *)Light2.lastread);
int Light2_State = atoi((char *)Light2.lastread);
digitalWrite(Relay2, Light2_State);
}
if (subscription == &Light3)
{ Serial.print(F("Got: "));
Serial.println((char *)Light3.lastread);
int Light3_State = atoi((char *)Light3.lastread);
digitalWrite(Relay3, Light3_State);
}
if (subscription == &Light4)
{ Serial.print(F("Got: "));
Serial.println((char *)Light4.lastread);
int Light4_State = atoi((char *)Light4.lastread);
digitalWrite(Relay4, Light4_State);
}
if (subscription == &Light5) {
Serial.print(F("Got: "));
Serial.println((char *)Light5.lastread);
int Light5_State = atoi((char *)Light5.lastread);
digitalWrite(Relay5, Light5_State);
}
if (subscription == &Light6)
{ Serial.print(F("Got: "));
Serial.println((char *)Light6.lastread);
int Light6_State = atoi((char *)Light6.lastread);
digitalWrite(Relay6, Light6_State);
}
if (subscription == &Light7)
{ Serial.print(F("Got: "));
Serial.println((char *)Light7.lastread);
int Light7_State = atoi((char *)Light7.lastread);
digitalWrite(Relay7, Light7_State);
}
}
}
void MQTT_connect() {
int8_t ret;
}
APPENDIX II
VCC Collector voltage
GND Ground
DA Distribution Automation
IP Internet Protocol