0% found this document useful (0 votes)
29 views8 pages

Exp 9 Cloud

Uploaded by

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

Exp 9 Cloud

Uploaded by

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

Experiment 9

OBJECTIVE: Write an Arduino/Raspberry Pi program to upload temperature and humidity


data to the thingspeak cloud.

RESOURCE REQUIRED: ESP32 development board, Breadboard, USB Cable, Arduino IDE.

Procedure:
ThingSpeak Setup for ESP32

ThingSpeak is a free web service that helps us with IoT-based projects. Using the
ThingSpeak server, we can monitor our data over the internet using the API and channels
provided by ThingSpeak. In this section I am explaining about how to send sensor data of
ESP32 to ThingSpeak server. For this you have to follow following steps:

1. Firstly go to https://thingspeak.com/ and create an account and sign in to this server.

2. After signing in you will find below window in which number of channels are listed
in this go to New channel.

3. After clicking on New Channel you will find a window in which you have to enter
some details about the channel, in this project we want to analyze the temperature and
Hall sensor value of ESP32 so you will require 2 fields. So enter the details as shown
and save the channel.
4. After saving of channel you will find a channel stats window showing details about
your channels.

5. Now go to API key menu which shows you Write API keys and Read API key,
Copy Write API key as you will required this API during programming of ESP32.
Programming ESP32 using Arduino IDE
This section of programming will measure temperature by including
temperature_sens_read() library.

Now, by including WiFi.h library I am allowing my controller to connect to the internet.


In this section you have to enter your Write API key from ThingSpeak server and give SSID
and password of your hotspot.

This section allows connecting your ESP to your hotspot.


In this section initialize the required parameters:

In the below section I am defining my ThingSpeak server fields that on which field I want to
obtain temperature or Hall sensor value as defined previously in ThingSpeak field number.

In the below code I am giving details about host and API key. And print temperature and hall
sensor values on serial monitor as well.
ARDUINO CODE

#ifdef __cplusplus
extern "C" {
#endif
uint8_t temprature_sens_read();
#ifdef __cplusplus
}
#endif
uint8_t temprature_sens_read();
#include <WiFi.h>
String apiKey = "BE7U15RJYY57AV91"; // Enter your Write API key from
ThingSpeak
const char *ssid = "Ashish"; // replace with your wifi ssid and wpa2
key
const char *pass = "12345678";
const char* server = "api.thingspeak.com";
WiFiClient client;
void setup()
{
Serial.begin(115200);
delay(10);
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()
{

int h = 0;
float t =0;
h = hallRead();
t = ((temprature_sens_read()-32)/1.8); //changing temperature parameter to celsius
if (client.connect(server,80)) // "184.106.153.149" or
api.thingspeak.com
{

String postStr = apiKey;


postStr +="&field1=";
postStr += String(h);
postStr += "&field2=";
postStr += String(t);
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("Hall: ");
Serial.println(h);
Serial.print("Temperature:");
Serial.print(t);
Serial.println(" C");

Serial.println("%. Send to Thingspeak.");


}
client.stop();
Serial.println("Waiting...");
delay(10000);
}

Setting Your Network Credentials:

Now to upload the program in ESP32 we have to follow some steps as follows:

1. Open your Arduino IDE and create a new file and save it where you want.
2. Copy the given code.

3. Now go to Tools--> Board--> ESP32 Dev Module.

4. Now go to Tools-->Port and select port to which your ESP32 is connected.


5. Now click on upload to upload the code.
6. After complete uploading you will find message like this in your output console.

7. Now open your serial monitor and press reset button of your ESP32, it starts
connecting to your hotspot.

8. After connecting successfully it starts displaying temperature and hall sensor


value on your serial monitor window and sending these values to ThingSpeak.
Observations:

Now open your ThingSpeak account in your browser and you will find graphs
displaying temperature and hall sensor values.

This is how you are successfully able to send temperature and hall sensor values to
ThingSpeak cloud using ESP32. Now you can simply add any sensor to ESP32 and can send
the sensor value to ThingSpeak IoT cloud to be monitored from anywhere.

RESULT AND CONCLUSION:


We have created a standalone web server cloud with an ESP32 to upload temperature and
humidity data to the thingspeak cloud.

You might also like