How to Stream real-time data to ThingSpeak | ESP32 temperature sensor tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome to Robo in this video we are going to make a basic iot project we are going to send data from esp32 to a website which is called thinkspeak so the way we are going to do it is by using API so API stands for application programming interface it is a link between our software and the website so to get data from website we need API and so to give you example consider website as a restaurant another program as a customer so all our customer need to do is you just need to provide the menu right dish from the menu to the restaurant waiter and it will give you the food the data which you want in the similar way so the information that we give from our esp32 to our website is a single text which is what we want and that data we get from the website so that is API so let's see how you can also operate API through our computer like pasting it in the URL it's just a link so apis are provided by websites they charge for it but some are free so things be provided it for free they also provide tools to visualize data like graph and everything else so we can post it to their website and it will be visualized so let's use thinkspeak let's create our account on thingspeak so let's create our account on thingspeak so I'll open this thinkspeak website and here just I will sign out to show you how it's done so when you first click on the sign in it will tell you to create a math work account okay so if you don't have account no account create one click on create one so you just follow the steps and account will be created so the entire steps are given in the blog link is in the description right now we'll just log into my account and show you how to create a channel a thing speak channel the channel will contain API key that you will use in our Arduino code so I will just log into my [Music] thank you [Music] so I have logged in and as you can see I've created one channel room temperature because I'm going to send temperature data to this channel but for now you must not be having any channel so you click on new channel and you will be directed toward this page so here you can see one field chart so in this chart right now you must be having no data I've uploaded many data to it so what you do is you click on API keys this is very important so API click on API is this right API key is very important you just copy and paste it somewhere so later it will be used in the code and the next thing is this so write a channel feed under this you will get this URL https URL you will get you just copy it and I will show you how to send data from computer to this things big channel so you just create a new tab and copy and paste that URL in the search bar and here you can see that the field one is zero that means I am publishing data 0 to the website but I don't want 0 I want 100 so right here 100 I'll never hit enter and yes it's been updated so now I will go to private View and you can see that my data is updated so earlier it was 26 temperature now I manually put 100 and it's showing me 100. so right now it's 100 okay so that means my API is working so this is to test whether the API is working or not so how to use this API in our code Arduino code that we are going to see so before that let's connect our esp32 with this dht11 temperature sensor so this dht11 temperature sensor is operating voltage is 3.3 volts anywhere between three to five volts will work and it sends calibrated temperature output in degree celsius so you don't need to worry about means calibrating the temperature so now let's connect it VCC goes to 3.3 volts [Music] ground goes to ground okay and data goes to pin 5. so I'll connect it to pin 5. so this dht11 is now connected to asp32 the connection diagram is very easy okay but the circuit diagram is also given in the blog link is given in the description if you have any problem you can refer the blog now we will connect the esp32 to other com port com8 so if you are new to ESP boards and how to make it compatible with Arduino IDE so the video link and the blog link is given in the description go through that video and blog it will be helpful so I've connected the esp32 to com8 and now this is the code to send the data temperature data from esp32 to the website so I will explain your line balance how this code works okay so right now we are not having any dht11 sensor Library so how to install that you just click on this Library search dht11 and then install this Library dht11 by Adafruit okay you will find here dht11 by Ada fruit yes C and then you have to install this after installing this Library then we'll start writing the code so first is we'll include Wi-Fi dot h because we are using Wi-Fi right and then we will include the HTTP client.h Library then we will include the dht11 library which is we will be using this sensor right that's why so on pin 5 I have connected dht11 so I've written here five then DHT type will dht11 then I will write the SSID which is my name okay then I will write the Wi-Fi name okay this is my Hotspot and the password [Music] then the server name which is http apithingspeak.com update so how to get this server name so you just open this thing speed you go to API keys here you can see this URL right earlier which we copied and pasted so copy only till this part till update so everything before the question mark should be copied you just hit Ctrl C and here you can notice https but in our code we are not using https we have imported the HTTP client Library not https so here when you paste this you just make one difference you can cancel out the S okay from https because we are using HTTP then just copy the right API key write AP write API key is also provided here just copy this write API key and paste it installing API key here okay so everything that we write are in string in double quotes even the server name and the API key so in the avoid setup we set the baud rate which is one one five two zero zero then we write Wi-Fi dot begin Wi-Fi is connected means we are searching for a Wi-Fi network then DHT dot begin so we start this sensor mini print serial dot print in connecting so when we get connected to Wi-Fi until then the dots are printed then we get connected the IP address is printed and this message is printed connected to Wi-Fi network so now we go to the white Loop in the white Loop if we are connected to internet Wi-Fi then only we will import this client library and http Library means we call this objects and then we give delay of 10 seconds and then we'll store the temperature in T so we're reading temperature from this dht11 and storing it in a variable t so if we did not get any temperature from this sensor then we print fail to read from dht11 sensor after that we will start the HTTP begin we'll assign our server the client this thing speak and then we will add HTTP ad header so our the data is in url encoded format so right here you are encoded but suppose if you have a Json format so beyond this you can see all these lines so you just uncomment it and comment this much part so you can also send Json data so there are two ways you can also send data through URL and also through Json which is Javascript object notation but right now we are not using this Json we are just using a simple URL so inside this string HTTP request data this is very important we are we are encapsulating our API key and the field the data which temperature data which we are going to send we are creating a package and then we are going to post it using this function HTTP dot post and when there when we are and then we are posting this HTTP request data to the thingspeak server so after this is posted if you are successful in the Response Code will be okay and this will indicate us that we are successful and then we will enter communication and if the Wi-Fi is not connected obviously it will be printed Wi-Fi disconnected so we'll upload this code now to the chp32 board yes now it's completely uploaded now we'll open the serial monitor and you can see this dot dots are getting printed that means the it's searching for the Wi-Fi network now I will turn on my hotspot [Music] so it's connected to the Wi-Fi network and now it will start sending data to the thingspeak server so you can see right now the temperature is 26 the sender data and you can see 26.2 is sent to the server earlier we sent 100 so now it's showing 26.2 so we'll warm up the sensor little bit okay with my hands so I will see rise in temperature let's see whether temperature rises so after every 10 seconds the temperature will rise yes you can see that earlier temperature was 26.2 does not rise so that means the samples are getting taken and the temperature is getting updated on the thinkspeak server okay so after every 10 seconds the values are updated and if the response code is -1 or minus 11 that means it's okay it means your data is getting published so in this way after every 10 seconds the data is getting published on the things Peak server you can view this temperature data from anywhere in this world okay if you have access to this things Peak site okay so this was a simple iot project in which we stream live temperature data where thingspeak server [Music] [Music]
Info
Channel: Robu.in
Views: 5,771
Rating: undefined out of 5
Keywords: Robu, robu.in, esp8266, esp8266 and esp32 cam, stream real time data to thingspeak, how to stream real time data to thingspeak, ESP32 cam thingspeak tutorial, ESP32 cam temperature sensor tutorial
Id: f4ps1oCYeKk
Channel Id: undefined
Length: 12min 58sec (778 seconds)
Published: Tue May 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.