Professional Documents
Culture Documents
IoT Note 7th Eee
IoT Note 7th Eee
IoT Note 7th Eee
"
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
I've also found that if you just Google "what is IoT," many of the answers are
unnecessarily technical.
also serve as a resource to share with others who need an introduction to IoT (like
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" ;)
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
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
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?
stored somewhere else, but your phone can send information (asking for that song)
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
And all three of these have enormous benefits that feed on each other.
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
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
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
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
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.
After this you are require to add esp8266 boards in your Arduino
IDE software, use following link
or you can easily find other tutorials for these two steps.
1. DHT11 or DHT22
2. NodeMCU
3. 5V supply (micro USB cable or you can use Vin pin of nodemcu
for input supply)
Connections:
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.
#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[] = "";
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);
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:
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
Terminal Connectors
5V DC supply
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.
The D3 pin should not be connected with GND during the booting
process of NodeMCU.
You can control, monitor the real-time status of the relays from
anywhere in the world with the Blynk App.
#define BLYNK_DEBUG
//#define APP_DEBUG
#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
#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() {
Blynk.syncVirtual(VPIN_BUTTON_1);
Blynk.syncVirtual(VPIN_BUTTON_2);
Blynk.syncVirtual(VPIN_BUTTON_3);
Blynk.syncVirtual(VPIN_BUTTON_4);
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);
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
Components Required
• NodeMCU (ESP8266MOD)
• Soil-Moisture sensor
• DHT11 sensor
• Relay module
• Water Pump
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();
}