IoT Note 7th Eee

You might also like

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

"What is IoT?

"
As someone who works for an Internet of Things (IoT) software company, this is a
question that I'm asked frequently. Whether it's a friend, family member, or stranger,
when the conversation turns to what I do, I inevitably find that I need to first explain

what IoT is.

I've also found that if you just Google "what is IoT," many of the answers are

unnecessarily technical.

"The Internet of Things (IoT) is a system of interrelated computing


devices, mechanical and digital machines, objects, animals or people
that are provided with unique identifiers and the ability to transfer data
over a network without requiring human-to-human or human-to-
computer interaction."- An unnecessarily technical explanation of IoT
If you just read that and thought, "ok, so what?", you're not alone. Most people don't
want to nor need to dive into the nitty-gritty of IoT. So in this post, I'll provide you with
a simple explanation of the Internet of Things and what it means for you. This can

also serve as a resource to share with others who need an introduction to IoT (like

friends, family members, or customers).

Before we jump in, note that "The Internet of Things" and "IoT" can and will be used

interchangeably. And a quick tip to sound knowledgeable: avoid saying "the IoT" ;)

A Simple, Non-Technical Explanation of


the Internet of Things
How are you reading this post right now? It might be on desktop, on mobile, maybe a

tablet, but whatever device you're using, it's most definitely connected to the internet.

An internet connection is a wonderful thing, it give us all sorts of benefits that just
weren't possible before. If you're old enough, think of your cell phone before it was a
smartphone. You could call and you could text sure, but now you can read any book,
watch any movie, or listen to any song all in the palm of your hand. And that's just to

name a few of the incredible things your smartphone can do.

The point is that connecting things to the internet yields many amazing
benefits. We've all seen these benefits with our smartphones, laptops, and tablets,

but this is true for everything else too. And yes, I do mean everything.

The Internet of Things is actually a pretty simple concept, it means taking all the

things in the world and connecting them to the internet.

I think that confusion arises not because the concept is so narrow and tightly
defined, but rather because it's so broad and loosely defined. It can be hard to nail

down the concept in your head when there are so many examples and possibilities

in IoT.

To help clarify, I think it's important to understand the benefits of connecting things to

the internet. Why would we even want to connect everything to the internet?

Why IoT Matters


When something is connected to the internet, that means that it can send information
or receive information, or both. This ability to send and/or receive information makes

things smart, and smart is good.


Let's use smartphones (smartphones) again as an example. Right now you can
listen to just about any song in the world, but it's not because your phone actually
has every song in the world stored on it. It's because every song in the world is

stored somewhere else, but your phone can send information (asking for that song)

and then receive information (streaming that song on your phone).

To be smart, a thing doesn't need to have super storage or a super computer inside

of it. All a thing has to do is connect to super storage or to a super computer. Being

connected is awesome.

In the Internet of Things, all the things that are being connected to the internet can

be put into three categories:

1. Things that collect information and then send it.

2. Things that receive information and then act on it.

3. Things that do both.

And all three of these have enormous benefits that feed on each other.

Collecting and Sending Information

This means sensors. Sensors could be temperature sensors, motion sensors,


moisture sensors, air quality sensors, light sensors, you name it. These sensors,
along with a connection, allow us to automatically collect information from the

environment which, in turn, allows us to make more intelligent decisions.

On the farm, automatically getting information about the soil moisture can tell
farmers exactly when their crops need to be watered. Instead of watering too much
(which can be an expensive over-use of irrigation systems) or watering too little
(which can be an expensive loss of crops), the farmer can ensure that crops get
exactly the right amount of water. More money for farmers and more food for the

world!

Just as our sight, hearing, smell, touch, and taste allow us, humans, to make sense

of the world, sensors allow machines to make sense of the world.

Receiving and Acting on Information

We're all very familiar with machines getting information and then acting. Your printer
receives a document and it prints it. Your car receives a signal from your car keys

and the doors open. The examples are endless.

Whether it's a simple as sending the command "turn on" or as complex as sending a
3D model to a 3D printer, we know that we can tell machines what to do from far

away. So what?

The real power of the Internet of Things arises when things can do both of the
above. Things that collect information and send it, but also receive information and

act on it.

Doing Both

Let's quickly go back to the farming example. The sensors can collect information
about the soil moisture to tell the farmer how much to water the crops, but you don't
actually need the farmer. Instead, the irrigation system can automatically turn on as

needed, based on how much moisture is in the soil.


You can take it a step further too. If the irrigation system receives information about
the weather from its internet connection, it can also know when it's going to rain and

decide not to water the crops today because they'll be watered by the rain anyways.

And it doesn't stop there! All this information about the soil moisture, how much the
irrigation system is watering the crops, and how well the crops actually grow can be
collected and sent to supercomputers that run amazing algorithms that can make

sense of all this information.

And that's just one kind of sensor. Add in other sensors like light, air quality, and
temperature, and these algorithms can learn much much more. With dozens,
hundreds, thousands of farms all collecting this information, these algorithms can
create incredible insights into how to make crops grow the best, helping to feed the

world.

Example 1 sending information

This project is related to initial steps in IoT world, here we will


interface DHT11/DHT22 sensor with NodeMCU or other ESP8266
based board and receive data on internet we are going to use Blynk
application, use the following tutorial link if you are not familiar with
blynk application.

For Blynk (it require only few minutes): https://docs.blynk.cc

After this you are require to add esp8266 boards in your Arduino
IDE software, use following link

To add esp8266 boards in Arduino IDE


software: https://randomnerdtutorials.com/how-to-install-esp...

or you can easily find other tutorials for these two steps.

Step 1: Hardware Components and Connections


There are simple hardware connections, you are not going to deal
with any messy connections,
Components:

1. DHT11 or DHT22

2. NodeMCU

3. 5V supply (micro USB cable or you can use Vin pin of nodemcu
for input supply)

4. Some jumper cables

Connections:

Use the following diagrams for complete understanding of


connection.

Connect data/signal pin of DHT sensor to any GPIO of nodeMCU,


the same pin number you will have to mention in your code.

Step 2: Blynk Project


Check out the attached video and follow the steps

1. Create a new Blynk project, copy its authorization token you


received and add two “Gauge” from widget box.

2. Click at the one of newly added widgets, select virtual pin V5 and
label it as “Temperature”, similarly select virtual pin V6 for second
widget and label it as “Humidity”. Set value display range for these
two widgets from 0 to 100.

Other details can be observe in video.

Step 3: Program Your Board


First you need to include Blynk(download the latest library from
blynk official website) and DHT library in your Arduino IDE software,
download the attached files and add them in your Arduino IDE
library folder or whatever the procedure you use for adding libraries.
After adding libraries, copy the following code and program your
NodeMCU

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include "DHTesp.h"

#ifdef ESP32
#pragma message(THIS EXAMPLE IS FOR ESP8266 ONLY!)
#error Select ESP8266 board.
#endif
int Sensor_PIN = 0; //D3

DHTesp dht;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";

// Your WiFi credentials.


// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";

float Temperature;
float Humidity;

BlynkTimer timer;

// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
Temperature = dht.getTemperature(); // Gets the values of the temperature
Humidity = dht.getHumidity(); // Gets the values of the humidity
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V5, Temperature);
Blynk.virtualWrite(V6, Humidity);
}

void setup()
{
// Debug console
Serial.begin(9600);
dht.setup(Sensor_PIN, DHTesp::DHT11);
Blynk.begin(auth, ssid, pass);
// You can also specify server:
//Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
//Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);

// Setup a function to be called every second


timer.setInterval(1000L, myTimerEvent);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}

Note: Before programming your nodeMCU, must add your blynk


project token and local Wi-Fi router credentials in your code,

Step 4: Check Sensor Data at Blynk Application


Make sure your NODEmcu is programmed, your Blynk project
window is complete(you have defined virual pins to both widgets)
and your hardware is ready. Now connect your mobile WiFi and go
live with your blynk application(check video), here you can see
temperature and humidity value displayed by your widgets.

Example 2 Receiving information and acting upon it

In this IoT project, I have shown how to make IoT-based Home


Automation project using NodeMCU and new Blynk app to control a
4-channel relay module from the manual switch & smartphone.

During the article, I have shown all the steps to make this Blynk
home automation system.

This Blynk ESP8266 control smart relay has the following features:

1. Control home appliances with WiFi (Blynk IoT app).


2. Control home appliances with Blynk web dashboard.
3. Control home appliances with manual switches or push
buttons.
4. Monitor real-time feedback in the Blynk IoT App.
5. Control appliances without WiFi from manual switches.

So, you can easily make this home automation project at home just
by using a NodeMCU and relay module. Or you can also use a
custom-designed PCB for this project.
Supplies
You can make this project just by using NodeMCU and 4-channel
relay module. But if you use PCB then you need the following
components.

NodeMCU ESP8266

Relays 5v (SPDT) (4 no)

BC547 Transistors (4 no)

PC817 Optocuplors (4 no)

510-ohm 0.25-watt Resistor (4 no) (R1 - R4)

1k 0.25-watt Resistors (5 no) (R5 - R9)

LED 5-mm (5 no)

1N4007 Diodes (5 no) (D1 - D5)

Push Buttons (4 no)

Terminal Connectors

5V DC supply

Step 1: Circuit Diagram of the ESP8266 Home


Automation Project
This is the complete circuit diagram for this home automation
project. I have explained the circuit in the tutorial video.

The circuit is very simple, I have used the GPIO pins D1, D2, D5 &
D6 to control the 4 relays. And the GPIO pins SD3, D3, D7 &
RX are connected with push buttons to control the 4 relays
manually.

I have used the INPUT_PULLUP function in Arduino IDE instead of


using the pull-up resistors.
I have used a 5V mobile charger to supply the smart relay module.

The D3 pin should not be connected with GND during the booting
process of NodeMCU.

Step 2: Control Relays Using Blynk IoT App


If the NodeMCU is connected with WiFi, then you can control the
home appliances from Blynk IoT App.

You also use multiple smartphones to control the appliances with


Blynk IoT App. For that, you have to log in same Blynk account
from all the smartphones. In this way, all smartphones will be sink
to the Blynk server.

You can control, monitor the real-time status of the relays from
anywhere in the world with the Blynk App.

// Fill-in information from your Blynk Template here

#define BLYNK_TEMPLATE_ID ""

#define BLYNK_DEVICE_NAME ""

#define BLYNK_FIRMWARE_VERSION "0.1.0"

#define BLYNK_PRINT Serial

#define BLYNK_DEBUG

//#define APP_DEBUG

// Uncomment your board, or configure a custom board in Settings.h


//#define USE_SPARKFUN_BLYNK_BOARD

#define USE_NODE_MCU_BOARD

//#define USE_WITTY_CLOUD_BOARD

// define the GPIO connected with Relays and switches

#define RelayPin1 5 //D1

#define RelayPin2 4 //D2

#define RelayPin3 14 //D5

#define RelayPin4 12 //D6

#define SwitchPin1 10 //SD3

#define SwitchPin2 D3 //D3

#define SwitchPin3 13 //D7

#define SwitchPin4 3 //RX


#define wifiLed 16 //D0

//Change the virtual pins according the rooms

#define VPIN_BUTTON_1 V1

#define VPIN_BUTTON_2 V2

#define VPIN_BUTTON_3 V3

#define VPIN_BUTTON_4 V4

// Relay State

bool toggleState_1 = LOW; //Define integer to remember the toggle state for relay 1

bool toggleState_2 = LOW; //Define integer to remember the toggle state for relay 2

bool toggleState_3 = LOW; //Define integer to remember the toggle state for relay 3

bool toggleState_4 = LOW; //Define integer to remember the toggle state for relay 4
#include "BlynkEdgent.h"

BLYNK_CONNECTED() {

// Request the latest state from the server

Blynk.syncVirtual(VPIN_BUTTON_1);

Blynk.syncVirtual(VPIN_BUTTON_2);

Blynk.syncVirtual(VPIN_BUTTON_3);

Blynk.syncVirtual(VPIN_BUTTON_4);

// When App button is pushed - switch the state

BLYNK_WRITE(VPIN_BUTTON_1) {

toggleState_1 = param.asInt();

if(toggleState_1 == 1){
digitalWrite(RelayPin1, LOW);

else {

digitalWrite(RelayPin1, HIGH);

BLYNK_WRITE(VPIN_BUTTON_2) {

toggleState_2 = param.asInt();

if(toggleState_2 == 1){

digitalWrite(RelayPin2, LOW);

else {

digitalWrite(RelayPin2, HIGH);

}
}

BLYNK_WRITE(VPIN_BUTTON_3) {

toggleState_3 = param.asInt();

if(toggleState_3 == 1){

digitalWrite(RelayPin3, LOW);

else {

digitalWrite(RelayPin3, HIGH);

BLYNK_WRITE(VPIN_BUTTON_4) {

toggleState_4 = param.asInt();

if(toggleState_4 == 1){
digitalWrite(RelayPin4, LOW);

else {

digitalWrite(RelayPin4, HIGH);

void setup()

Serial.begin(115200);

delay(100);

pinMode(RelayPin1, OUTPUT);

pinMode(RelayPin2, OUTPUT);
pinMode(RelayPin3, OUTPUT);

pinMode(RelayPin4, OUTPUT);

pinMode(wifiLed, OUTPUT);

pinMode(SwitchPin1, INPUT_PULLUP);

pinMode(SwitchPin2, INPUT_PULLUP);

pinMode(SwitchPin3, INPUT_PULLUP);

pinMode(SwitchPin4, INPUT_PULLUP);

//During Starting all Relays should TURN OFF

digitalWrite(RelayPin1, HIGH);

digitalWrite(RelayPin2, HIGH);

digitalWrite(RelayPin3, HIGH);

digitalWrite(RelayPin4, HIGH);
digitalWrite(wifiLed, HIGH);

BlynkEdgent.begin();

Blynk.virtualWrite(VPIN_BUTTON_1, toggleState_1);

Blynk.virtualWrite(VPIN_BUTTON_2, toggleState_2);

Blynk.virtualWrite(VPIN_BUTTON_3, toggleState_3);

Blynk.virtualWrite(VPIN_BUTTON_4, toggleState_4);

void loop() {

BlynkEdgent.run();
manual_control(); //Manual Switch Control

Example 3 doing both

About the project


This is IoT-based smart irrigation. We connect a DHT-11 temperature and
humidity sensor in our project that can tell us the values of the temperature and
humidity in the air. If the moisture content of the soil is low then the green led will
glow and the water pump is activated automatically. You can also see the real-time
readings on the Blynk app. All the detailed procedure is given below.

Components Required
• NodeMCU (ESP8266MOD)

• Soil-Moisture sensor
• DHT11 sensor

• Relay module
• Water Pump

• Green Led with resistor

• 12V supply for pump( if needed)

Circuit Diagram:
Code for the Project
NOTE: Please upload this code to the nodemcu.
// BLYNK LIBRARY
// https://github.com/blynkkk/blynk-library
// ESP8266 LIBRARY
// https://github.com/ekstrand/ESP8266wifi
// DHT11 SENSOR LIBRARY
// https://github.com/adafruit/DHT-sensor-library
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#define BLYNK_PRINT Serial
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS D2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
char auth[] =" your auth code";
char ssid[] = "your wifi ssid";
char pass[] = "your wifi password";
#define DHTPIN 2
#define DHTTYPE DHT11 // DHT11 SENSOR CONNECT D4 PIN
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V5, h); //V5 is for Humidity
Blynk.virtualWrite(V6, t); //V6 is for Temperature
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dht.begin();
timer.setInterval(1000L, sendSensor);
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
sensors.begin();
}
int sensor=0;
void sendTemps()
{
sensor=analogRead(A0);
sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0);
Serial.println(temp);
Serial.println(sensor);
Blynk.virtualWrite(V1, temp);
Blynk.virtualWrite(V2,sensor);
delay(1000);
}
void loop()
{
Blynk.run();
timer.run();
sendTemps();
}

Set Up the Blynk App:


Download and install Blynk app from any App store.
You will see main screen after logging into the app.
Then create a new project with any of your desired name.
1/4
after completion you’ll see this type of interface
We hope that you like this project. Thanks for reading.

You might also like