Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
16 views4 pages

Week 8

Uploaded by

21r01a6782
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views4 pages

Week 8

Uploaded by

21r01a6782
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

III-II SEMESTER CMR INSTITUTE OF TECHNOLOGY

WEEK-8

Aim: Write a program on Arduino or Raspberry Pi to retrieve temperature and humidity data
from the Cloud
Hardware Requirements:

1. Arduino UNO board


2. NodeMCU ESP8266 Breakout Board
3. DHT-11 temperature and humidity sensor
4. Jumper wires
5. Bread board

Procedure:

1. Open up the Arduino IDE and head over to the library manager.

2. Install the DHT library (You can also install it by going to Sketch > Include Library > Manage
Libraries, and search for adafruit dht library).

DHT sensor with 3 pins:

1. Power supply 3.5V to 5.5V.

2. Data, Outputs both Temperature and Humidity through serial Data.

3. Ground, Connected to the ground of the circuit.

Set up in source code:

1. Set your Wi-Fi SSID and password.

2. Set the API Key

3. Save->Compile->upload->now us can visualize our data in cloud

Source code:

#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
const char ssid[] = "Redmi Note 11 Pro+ 5G"; // your network SSID (name)
const char pass[] = "mani@123"; // your network password

IOT with Cloud Computing Lab manual Page 1


III-II SEMESTER CMR INSTITUTE OF TECHNOLOGY

int statusCode = 0;
WiFiClient client;

//---------Channel Details---------//
unsigned long counterChannelNumber = 2062499; // Channel ID
const char * myCounterReadAPIKey = "W5564YQ3MJPU0S7V"; // Read API Key
const int FieldNumber1 = 1; // The field you wish to read
const int FieldNumber2 = 2; // The field you wish to read
//-------------------------------//

void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}

void loop()
{
//----------------- Network -----------------//
if (WiFi.status() != WL_CONNECTED)
{
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.println(" ....");
while (WiFi.status() != WL_CONNECTED)
{
WiFi.begin(ssid, pass);
delay(5000);
}
Serial.println("Connected to Wi-Fi Succesfully.");

IOT with Cloud Computing Lab manual Page 2


III-II SEMESTER CMR INSTITUTE OF TECHNOLOGY

}
//--------- End of Network connection--------//

//---------------- Channel 1 ----------------//


long temp = ThingSpeak.readLongField(counterChannelNumber, FieldNumber1,
myCounterReadAPIKey);
statusCode = ThingSpeak.getLastReadStatus();
if (statusCode == 200)
{
Serial.print("Temperature: ");
Serial.println(temp);
}
else
{
Serial.println("Unable to read channel / No internet connection");
}
delay(100);
//-------------- End of Channel 1 -------------//

//---------------- Channel 2 ----------------//


long humidity = ThingSpeak.readLongField(counterChannelNumber, FieldNumber2,
myCounterReadAPIKey);
statusCode = ThingSpeak.getLastReadStatus();
if (statusCode == 200)
{
Serial.print("Humidity: ");
Serial.println(humidity);
}
else
{
Serial.println("Unable to read channel / No internet connection");

IOT with Cloud Computing Lab manual Page 3


III-II SEMESTER CMR INSTITUTE OF TECHNOLOGY

}
delay(100);
//-------------- End of Channel 2 -------------//
}

Output:

Connected to wifi Successfully

Humidity :63

Temperature : 9

IOT with Cloud Computing Lab manual Page 4

You might also like