Sending Temperature data to ThingSpeak Cloud and Visualize

by Apr 3, 2021IoT Cloud, Projects

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world.

But “What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows you to visualize and analyze data in the cloud. One can send data to ThingSpeak. Then, one can visualize data through available interesting widgets. Lastly, one can take suitable action after reading the data.

Sending temperature data to ThingSpeak requires hardware configuration to get the temperature data from the sensor and software configuration to upload temperature data to ThingSpeak cloud.

Hardware Configuration

Hardware connection demands a temperature sensor to measure temperature and a microcontroller to interface temperature sensor.

Components Required

In this project, we are using the following hardware components:

  1. LM35 (Temperature Sensor)
  2. NodeMCU (Microcontroller)
  3. Breadboard
  4. Jumping wires (To connect temperature sensor with Microcontroller)

Most Internet of things (IoT) projects use NodeMCU as a Microcontroller. Because NodeMCU has a built-in Wi-Fi Module (ESP8266). This Wi-Fi Module helps to connect with the internet and provides a path between the device and the internet. Moreover, it is easily programmable on Arduino IDE.

To measure temperature, the LM35 sensor is the best option. It is cheap and reliable. This sensor has three pins. These pins can easily be connected to the microcontroller.

Circuit Diagram

The left pin of LM35 is a power pin and connect it to the 3.3V pin of NodeMCU. The Right pin of LM35 is a ground pin and connect it to the GND pin of NodeMCU. The middle pin is an output pin of LM35 that provides temperature value in analog. Connect this pin to the analog pin (A0) of NodeMCU.

The Circuit diagram of connection is shown below:

Software Configuration

Software Configuration requires access to ThingSpeak to send data and to program NodeMCU using Arduino IDE.

Starting with ThingSpeak

First of all, we need an account in ThingSpeak. Go to ThingSpeak website and click on Get started for free.

Then fill up all the details to sign up. Ignore if you have an account already.

Once you sign in to ThingSpeak. Create a Channel. Channel can be said as a stream of data. It identified by a numerical channel ID using which data can be inserted or retrieved using ThingSpeak APIs.

Go to Channels>My Channels> New Channel

Moving further, enter the Name of Channel and add the description of Channel. Tick the field 1 to show LM35 temperature sensor output. We are using only one field because there is only one sensor reading.

Now, click on the ‘API keys’ tab and note the Write and Read API key, here we are only using the Write key. Because we are going to write temperature data to ThingSpeak. It is a 16 digit API key code that allows an application to write data to a channel. We can use this API in Arduino IDE coding.

Programming NodeMCU

Lastly, there is a code for NodeMCU to send connected LM35 output to field1 of the ThingSpeak channel.

Converting Output Voltage to Temperature in Celsius Degree

The output pin of LM35 gives voltage. But we need to show temperature in Celsius degree as an output. There is a basic conversion to do this.

  • NodeMCU analog pins can calculate up to 3.3 volts
  • ​NodeMCU analog pin resolution is 1023 starting from 0. On 3.3 volts input, it counts to 1023.
  • Lm35 max voltage output is 1.5 volts (At 150 degrees centigrade).
  • NodeMCU analog pin count for 1.5 volts equals to (1.5 / 3.3)*1023 = 465.
  • So, Nodemcu-LM35 Resolution = 465 / 150 = 3.1. Now if NodeMCU analog pin counts 3.1 its equal to 1 degree change in Celsius temperature of LM35.

Code

The code is mentioned below with comments for better understanding.

#include <ESP8266WiFi.h> //Library
String apiWritekey = "52KRVUKXLQUIS29T"; //Write your writeAPI here
const char* ssid = "******"; //Write your SSID
const char* password = "*******" ; //Write your Wifi Password
const char* server = "api.thingspeak.com"; //To initializing the device with Thingspeak API
WiFiClient client;
void setup()
{
  Serial.begin(115200);
  WiFi.disconnect(); //disconnecting previously connected Wifi
  delay(10);
  WiFi.begin(ssid, password); //connecting to provided Wifi
  while (WiFi.status() != WL_CONNECTED) 
  { 
    delay(500); 
  }
  Serial.println("NodeMcu connected to wifi"); //NodeMCU connected to Wifi
}
void loop() 
{
float temp = analogRead(A0)/3.1; //temperature in Celsius degree
  if (client.connect(server,80)) //connecting to Thingspeak Server
  {
    String tsData = apiWritekey;
    tsData +="&field1=";  
    tsData += String(temp);
    tsData += "\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: "+apiWritekey+"\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(tsData.length());
    client.print("\n\n");
    client.print(tsData); //temperature value sent to field1 of Thingspeak channel
    
    Serial.print("Temperature: "); //Displaying the temperature in serial monitor
    Serial.print(temp);
  }
  client.stop();
  delay(15000);
}

Output

Now open the ThingSpeak server and observe the monitored temperature value on created channel graph.

One can also change the way of representing data by clicking on Add Widgets button. For Example, one can represent data in the form of “Numeric display” and “Gauge”.

Discover more exciting Internet of Things (IoT) blogs here.

Creating a multiplication Skill in Alexa using python

Written By Monisha Macharla

Hi, I'm Monisha. I am a tech blogger and a hobbyist. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. Thank you for reading my blog! Happy learning!

RELATED POSTS

Creating REST API CRUD with Node.js, Express and MongoDB

Creating REST API CRUD with Node.js, Express and MongoDB

In our previous blog, we explored the fundamentals of creating a REST API with in-memory CRUD operations using Node.js and Express. Now, we're taking a significant step forward by integrating our product data with a database. This transition is pivotal for achieving...

How to create REST API using Node.js and Express?

How to create REST API using Node.js and Express?

In the vast landscape of web development, creating a robust API is a fundamental skill. APIs, or Application Programming Interfaces, serve as the communication bridge between different software applications. Today, we'll embark on a journey to build a simple blog API...

APIs Vs. Microservices: What is the difference?

APIs Vs. Microservices: What is the difference?

You've probably heard two extravagant terms thrown around when discussing software design and integrations: APIs and microservices. Both topics are important in web application development and design nowadays, and their applications overlap. In this article, we will...

How to Simulate IoT projects using Cisco Packet Tracer

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

Understanding Salesforce IoT and Its Importance

Understanding Salesforce IoT and Its Importance

In this post, we are going to discuss Salesforce IoT. All across the globe, people are connecting to the Internet to access information, communicate with other people, and do business. But it's not just people that are using the Internet: objects use it too....

How to design a Wireless Blind Stick using  nRF24L01 Module?

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

VIDEOS – FOLLOW US ON YOUTUBE

EXPLORE OUR IOT PROJECTS

IoT Smart Gardening System – ESP8266, MQTT, Adafruit IO

Gardening is always a very calming pastime. However, our gardens' plants may not always receive the care they require due to our active lifestyles. What if we could remotely keep an eye on their health and provide them with the attention they require? In this article,...

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

All you need to know about integrating NodeMCU with Ubidots over MQTT

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

All you need to know about integrating NodeMCU with Ubidots over Https

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

Sending Temperature data to ThingSpeak Cloud and Visualize

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world. But "What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows...

Amaze your friend with latest tricks of Raspberry Pi and Firebase

Introduction to our Raspberry Pi and Firebase trick Let me introduce you to the latest trick of Raspberry Pi and Firebase we'll be using to fool them. It begins with a small circuit to connect a temperature sensor and an Infrared sensor with Raspberry Pi. The circuit...

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....