LM35 data to Thingspeak with Node MCU

Let’s learn how to plot LM35 temperature data to Thingspeak using Node MCU developer board which is Arduino compatible with ESP8266 in-built to access the internet. With the use of the internet, we can upload the data to free cloud database and analytic’s platform like Thingspeak. For this, you need to create a Thingspeak ID. After creating an account you need get our API key to push the data into Thingspeak server. To upload the data to this IoT analytics platform you need to create a channel for each device. Go to channels and create a new channel for your NodeMCU and LM35. While you are creating a channel you need to give the details of the channel for example Name, Description Fields, Metadata, tags, and link to external site.  After filling up the details click on the save channel which will give you channel ID and other settings for the channel. By default, the channel will be private if you wish to share the data to the public you can do that as well. After creating the channel thingspeak allows you to create visualizations of your data in different forms using MATLAB.

Learn How to Blink Using NodeMCU

Also, earn How to Blink Led Using NodeMCU/ESP8266 WebServer

Connections:

The NodeMCU have 10 GPIO pins connect the LM35 the data pin to Node MCU.  Node MCU has a micro USB for connecting to system use this MicroUSB to dump or programming and power supply for the board, Insert the NodeMCU board into the breadboard and connect the LM35 sensor to Node MCU board using male to male jumper wires the output pin of LM35 is connected to Node MCU of A0 pin. The pin is used to analyze the data the Esp8266 Wifi shield is used for connecting to internet used to upload the data to the cloud.

The temperature Sensor LM35 is now connected to the Node MCU via the breadboard. LM35 has three pins. They are supplied, ground (GND) and output pin. The supply pin of LM35 is connected to +5V of Node MCU The output pin of LM35 is connected to the A0 pin of Node MCU. The GND pin of LM35 is connected to the GND of Node MCU.

Next Step:

Go to Tools -> Board (where you’d select your version of Arduino) -> Boards Manager, find the ESP8266 and click Install. You now should be able to use the ESP8266 as an Arduino. Simply select the NODEMCU 1.0 as your board with Port and you should be ready to code.

Now, with the ESP8266 board installed to Arduino IDE, we can program NodeMCU using Arduino IDE directly.

Setup for installing Node MCU software and ThingSpeak libraries:

GoTo Sketch > Include Library > Manage Libraries

> Search for Thingspeak> Click on it > Click Install 

Program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ThingSpeak.h>
const char* ssid = "My ASUS";
const char* password = "123456780";
int val;
int tempPin = A0;

WiFiClient client;
unsigned long myChannelNumber = 345148;
const char * myWriteAPIKey = "FBOED9JHDAJNZ3SQ";
void setup() {
Serial.begin(115200);
delay(10);

WiFi.begin(ssid, password);
// Connect to WiFi network
ThingSpeak.begin(client);
}

void loop() {
val = analogRead(tempPin);
float mv = ( val/1024.0)*5000;
float cel = mv/10;
Serial.print("TEMPRATURE = ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
delay(1000);
ThingSpeak.writeField(myChannelNumber, 1,cel, myWriteAPIKey);

delay(100); }

Upload Code to Node MCU

After applying the code you need to change the board to  NodeMCU 1.0(ESP-12Emodule) and port also select the com port where your ESP8266 is connected to that com port.

ThingSpeak:

ThingSpeak is a platform providing various services exclusively targeted for building IoT applications. It offers the capabilities of real-time data collection, visualizing the collected data in the form of charts, ability to create plugins and apps for collaborating with web services, social network and other APIs

The data will store into ThingSpeak so you need to log into  ThingSpeak account after logging in the account automatically the API keys and channel number will come. You need to change your channel number and API keys into the program , In the ThingSpeak, you can store and retrieve the data from ThingSpeak in ThingSpeak 8 fields you can select the fields.

ThingSpeak channel :

Selecting the Fields:

 

Output in ThingSpeak:

The figure shows the live temperature that is sensed by the sensor in a graphical presentation. Out of the eight channels present in the cloud, the said system uses only one channel for monitoring. 

Conclusion and future scope:

The article presented here is based on the project work carried by us. This project is an implementation of Internet of Things. The said project is able to sense the temperature and monitor it remotely. The proposed use of Internet of Things will help the researchers in the field to come up with solutions that are inexpensive and more reliable. The project can be further expanded to control things. The sensed temperature can be used for various projects such as home automation, lab monitoring, etc.

 

2 Comments

  1. faizan

    i just use this code we see the outpiut on serial monitor but on thing speak on my channel there is no plot of sensors value please resolved that issue?

    1. Rithvik Podduturi

      Check Your Internet connection change the values Highlighted below

      const char* ssid = “Put Your WiFi SSID“;
      const char* password = “Your WiFi Password“;

      unsigned long myChannelNumber = Put Your Channel ID;
      const char * myWriteAPIKey = “Put Your Write API Key“;

Leave a Reply