Exp 9 Cloud
Exp 9 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:
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.
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
{
Serial.print("Hall: ");
Serial.println(h);
Serial.print("Temperature:");
Serial.print(t);
Serial.println(" C");
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.
7. Now open your serial monitor and press reset button of your ESP32, it starts
connecting to your hotspot.
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.