IOTCC

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

IOT WITH CLOUD COMPUTING LAB

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

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
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.");
}
//--------- 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");
}
delay(100);
//-------------- End of Channel 2 -------------//
}
WEEK 9:

AIM: Write a program to create TCP Server on cloud using Arduino and Respond with
humidity data to TCP Client when requested.

Description : An IoT device can be made to communicate with a cloud or server using TCP/IP
protocol without any hassle of network programming and network administration.

The IoT device designed in this project is built using Arduino UNO. The Arduino is just a
microcontroller board and cannot connect to an internet network on its own. For internet
connectivity, the Arduino UNO is interfaced with ESP8266 module. The ESP8266 Wi-Fi
Module is a self contained SOC with integrated TCP/IP protocol stack that can access to a Wi-Fi
network.
The Arduino board controls all the functionalities of the IoT device like counting visitors,
reading temperature and humidity values from DHT-11 sensor, displaying temperature and
humidity data on OLED, implementing TCP/IP protocol, connecting with ThingSpeak platform
and sending data to the cloud server.

Software Required –
• ThingSpeak server
• Arduino IDE

The IoT device that communicates with the ThingSpeak Cloud is built on Arduino UNO.
The DHT-22 Sensor, IR sensor, Photodiodes, ESP8266 module and OLED module are interfaced
with the Arduino board to make the IoT device.
Arduino: It is an Atmega 328 based controller board which has 14 GPIO pins, 6 PWM
pins, 6 Analog inputs and on board UART, SPI and TWI interfaces. The Atmega 328 is the
sitting MCU on the Arduino board. There are two GPIO pins (external interrupt pins INT0 and
INT1) of Arduino board used to interface photodiodes, TX and RX pins (pins 3 and 2
respectively)are used interface ESP module, SDA and SCL (pins 27 and 28 respectively) pins
used to interface the OLED module.
OLED Module – The OLED module is used to display the temperature and humidity
information as well as the count of the visitors (occupants) in the house. The module
communicates with the Arduino board using I2C protocol. This is a two wire protocol. The
module has four pins – SDA, SCL, VCC and GND. The VCC and Ground are connected to 5V
DC and common ground respectively.
ESP8266 Module – The ESP8266 Wi-Fi Module is a self contained SOC with integrated
TCP/IP protocol stack that can access to a Wi-Fi network. The ESP8266 is capable of either
hosting an application or off loading all Wi-Fi networking functions from another application
processor.
DHT-22 Sensor – DHT-22 is a temperature and humidity sensor. The DHT22 sensor
consists of two main components – one is Humidity sensing component and other is NTC
temperature sensor (or Thermistor). The Thermistor is actually a variable resistor that changes its
resistance with change in temperature.
ThingSpeak Server – The ThingSpeak server is used to visualize the data received from
the IoT device. The data is displayed in the form of graphs on the platform. The ThingSpeak
generates the read and write API key.
. it uses a capacitive humidity sensor and a Thermistor to measure the surrounding air and spits
out a digital signal on the Data pin.

Source code:

#include "ESP8266WiFi.h"
#include "DHT.h"
const char* ssid="";
const char* password ="";
WiFiServer wifiServer(8080);
DHT dht(D3, DHT22);
void setup() {
Serial.begin(115200);
delay(1000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting..");
}
Serial.print("Connected to WiFi. IP:");
Serial.println(WiFi.localIP());
wifiServer.begin();
dht.begin();
}

void loop() {
WiFiClient client = wifiServer.available();
if (client) {
while (client.connected()) {
while (client.available()>0) {
float t=dht.readTemperature();
float h = dht.readHumidity();
client.print("humidity :");
client.print("temperature :");
client.println(h);
Serial.println(h);
client.println(t);
Serial.println(t);
delay(2000);
}
}
client.stop();
Serial.println("Client disconnected");

}
}

You might also like