Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

IoTAssignment 2

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

Assignment no 2

AIM: Design and implement parameter monitoring IoT system keeping


records on Cloud such as 'environment humidity and temperature
monitoring'.
Theory:
NodeMCU-ESP 8266 WiFi System:
The NodeMCU (Node MicroController Unit) is open-source software and
hardware development environment built around an inexpensive System-on-a-Chip
(SoC) called the ESP8266. The ESP8266, designed and manufactured by Espressif
Systems, contains the crucial elements of a computer: CPU, RAM, networking
(WiFi), and even a modern operating system and SDK. That makes it an excellent
choice for Internet of Things (IoT) projects of all kinds.

However, as a chip, the ESP8266 is also hard to access and use. You must
solder wires, with the appropriate analog voltage, to its pins for the simplest tasks
such as powering it on or sending a keystroke to the “computer” on the chip. You
also have to program it in low-level machine instructions that can be interpreted by
the chip hardware. This level of integration is not a problem using the ESP8266 as
an embedded controller chip in mass-produced electronics. It is a huge burden for
hobbyists, hackers, or students who want to experiment with it in their own IoT
projects.

But, what about Arduino? The Arduino project created an open-source


hardware design and software SDK for their versatile IoT controller. Similar to
NodeMCU, the Arduino hardware is a microcontroller board with a USB
connector, LED lights, and standard data pins. It also defines standard interfaces to
interact with sensors or other boards. But unlike NodeMCU, the Arduino board can
have different types of CPU chips (typically an ARM or Intel x86 chip) with
memory chips, and a variety of programming environments. There is an Arduino
reference design for the ESP8266 chip as well. However, the flexibility of Arduino
also means significant variations across different vendors. For example, most
Arduino boards do not have WiFi capabilities, and some even have a serial data
port instead of a USB port.
Pin out Diagram of NodeMCU-ESP8266 (CP2102 USB Drivers):

DHT11 Humidity & Temperature Sensor:


The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It
uses a capacitive humidity sensor and a thermistor to measure the surrounding air
and spits out a digital signal on the data pin (no analog input pins needed).

It’s fairly simple to use but requires careful timing to grab data. The only real
downside of this sensor is you can only get new data from it once every 2 seconds,
so when using the library, sensor readings can be up to 2 seconds old.

Circuit Diagram & Connection:

Setting Thingspeak & Getting API Key:

1. Go to https://thingspeak.com/ and create an account if you do not have one.


Login to your account.
2. Create a new channel by clicking on the button. Enter the basic details of the
channel. Then Scroll down and save the channel.
3. Then go to API keys copy and paste this key to a separate notepad file. You will
need it later while programming.
Source Code/Program:
The program for Humidity & Temperature Monitoring using
DHT11 & NodeMCU on ThingSpeak is given below.

#include <DHT.h> // Including library for dht


#include <ESP8266WiFi.h>
String apiKey = "H535I914Y8LY0ZJ0"; // Enter your Write API key from
ThingSpeak

const char *ssid = "Public"; // replace with your wifi ssid and wpa2 key
const char *pass = "public1234";
const char* server = "api.thingspeak.com";

#define DHTPIN 0 //pin where the dht11 is connected

DHT dht(DHTPIN, DHT11);

WiFiClient client;

void setup()
{
Serial.begin(115200);
delay(10);
dht.begin();

Serial.println("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED)


{
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}

void loop()
{

float h = dht.readHumidity();
float t = dht.readTemperature();

if (isnan(h) || isnan(t))
{
Serial.println("Failed to read from DHT sensor!");
return;
}

if (client.connect(server,80)) // "184.106.153.149" or
api.thingspeak.com
{

String postStr = apiKey;


postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
postStr += "\r\n\r\n";

client.print("POST /update HTTP/1.1\n");


client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n");
client.print("Content-Type: application/x-www-form-
urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);

Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius, Humidity: ");
Serial.print(h);
Serial.println("%. Send to Thingspeak.");
}
client.stop();

Serial.println("Waiting...");

// thingspeak needs minimum 15 sec delay between updates


delay(1000);
}

1. Copy this program and paste it on Arduino IDE.


2. Download the DHT11/DHT22 library from GitHub and add it to your library
manager.
3. Select the NodeMCU ESP-12E board from the board manager.
4. Paste your API Key from thingspeak which you created earlier on a
programming section line.
5. Edit the program to change the wifi SSID and password with your own.
6. Compile the code and Upload it to NodeMCU board.
7. Then Open you thingspeak channel on your mobile phone and check the output
result as follows.
Out Put on Thingspeak Platform:

Conclusions:
In this way, we have designed and implemented environmental parameters
like humidity and temperature monitoring IoT system which keeping records on
Cloud using Thingspeak- IoT cloud platforms successfully.

You might also like