In this post we are going to learn how to send LM35 sensor’s temperature data to Thingspeak using: 1) Generic ESP8266, 2) using GSM modem and 3) using NodeMCU. We will explore each method in detail and you may utilize any one of the method mentioned here.
There is a good chance that you are a beginner in IoT project and you have chosen LM35 and Arduino development environment, if so you landed on the right place. We will walk you through all the little things that you need to take care while constructing one of your first IoT project and we will also guide you where you may go wrong, in the end of this article you will be able to upload temperature data to thingspeak successfully.
We will see:
- Setting up Thingspeak account for receiving LM35 data.
- Installing ESP8266 package to Arduino IDE.
- Installing CH340G driver.
- Sending LM35 data to thingspeak using NodeMCU.
- Sending LM35 data to thingspeak using GSM.
- Sending LM35 data to thingspeak using Generic ESP8266.
Setting up Thingspeak account for LM35 sensor:
Before we proceed towards construction details we need to setup our thingspeak account correctly to receive LM35 temperature data, this procedure need to be done for all three methods mentioned here.
You can sign up for thingspeak account here, if you haven’t signed up yet.
- You need to create a new channel by clicking “New Channel” button and in the channel you should do the changes as shown:
1) Go to Channel settings tab and edit the name.
2) Enable Field 1 by checking the box and write the label as “Temperature”.
3) Scroll down and click save.
- Now click on API keys tab:
API keys are the access keys to your channel using which you can write and read values. In this project we are using only write API key which is already generated for your channel. You need to take note of it and this write API key need to be inserted to the given program codes.
- Now by clicking “Private View” tab you will see a blank channel. You will see some data once we send to it.
Installing ESP8266 package to Arduino IDE:
This process needs to be done if you are using NodeMCU or generic ESP8266 to connect to thingspeak. If you are going to use GSM modem to send LM35 data, this step is irrelevant for you, but for NodeMCU and ESP8266 boards this step is mandatory.
- In this step you need internet; we are going to install core files to Arduino IDE for IoT based boards.
- Copy this link: http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Now open Arduino IDE and click on “File” >> “Preferences”.
- A window will open like this:
- Paste the URL on the box and click “OK”.
- Now go to tools > Board > Boards Manager.
- Now a window will popup:
- Type ESP8266 on the box as shown and you will get an installation option, select the latest version and click install.
Downloading files may take several minutes depending on your internet connection.
Downloading Thingspeak library:
You need to download Thingspeak library for projects using NodeMCU and generic ESP8266, this library is irreverent if you are going to use GSM module in this project.
Download Thingspeak library here.
Installing CH340 driver:
This step is relevant only if you are going to use NodeMCU to send LM35 data to thingspeak. You may skip for other two mentioned methods.
Installing CH340 driver is mandatory not only for NodeMCU but also for all Arduino clones, Uno R3, nano etc. without it you cannot upload any program.
We have explained the steps how to install CH340 driver here.
Once you completed the mentioned relevant steps, we are good to go with construction details.
Send LM35 Data to Thingspeak using NodeMCU
The circuit is so simple that we didn’t consider drawing one. Connections are mentioned below:
- Vcc of LM35 connects to ‘VU’ pin of NodeMCU. VU pin provides 5V output.
- The output terminal of LM35 connects to ‘A0’ of NodeMCU.
- GND of LM35 connects to GND of NodeMCU.
Program code for NodeMCU:
In the code you need to change the following:
You need to insert your Wi-Fi credentials in the place of XXXX and YYYY.
You need to change “00000” with your channel ID and replace “ZZZZZZZZZ” with your write API key.
How to upload this program code to NodeMCU properly?
- Go to Tools > Board. Select NodeMCU 1.0 (ESP-12E Module).
- Select baud rate “115200”.
- Select the right COM port.
- Now press and hold flash button on the NodeMCU and press reset button once and leave the flash button. Only by doing this you can upload program to NodeMCU.
- Now press upload, uploading code to NodeMCU will take a minute. On successful program upload you will see this:
- If you failed to upload the code, you will see something similar to this:
If you fail to upload the code, you did not press the “flash” and “reset” button in the correct sequence.
LM35 NodeMCU Output (at thingspeak):
Send LM35 Data to Thingspeak Using GSM modem
Here we are going to explore how to send LM35 temperature data to thingspeak using GSM module. Using NodeMCU or generic ESP8266 we need a Wi-Fi router beside them for providing internet, but using GSM modem we can access GPRS internet anywhere without the need for Wi-Fi, only requirement is that GSM module must be within the cellular network range.
The circuit consists of Arduino and GSM modem (SIM 900 or SIM 800 or you can use any other model of GSM modem). The Arduino can be powered via USB or DC jack; however GSM modem must be power only through DC jack by applying 9V at 1 ampere.
You need to insert a valid SIM card that can access GPRS (2G) with pre-activated mobile data. Rest of the circuit is self-explanatory.
Note: Don’t insert Jio SIM card or any SIM card whose network is not 2G backward compatible.
NOTE 1: Insert your write API key here.
Note 2: You need to insert the APN for your SIM card’s cellular network.
LM35 GSM thingspeak output:
What is APN? What is APN for my network? Why data is not getting updated on thingspeak? These are some of the frequent question raised by beginner in IoT projects. These questions are answered clearly in this post. Scroll down to the FAQ.
Send LM35 data to thingspeak using generic ESP8266
In this section we are going to see how to send LM35 temperature data to thingspeak using Arduino and generic ESP8266. The generic ESP8266 is the name of the board illustrated below:
Pin diagram is also labelled at the back side:
ESP8266 is an IoT board it has its own CPU and memory and it works on 3.3V (not 5V). We have to upload an appropriate code to this board to make it functional. It also has two GPIO pins which can be used for any digital input and output purposes.
Since it has just two GPIO pins we don’t use them for big or medium scale IoT projects, instead we use Arduino or any other microcontroller to collect data from sensors and send data to ESP8266 via UART (Serial data). The received data will be sent to an IoT server, in this case we are sending to thingspeak server.
Here we are uploading a program code to ESP8266 and one more program code to Arduino board. Since ESP8266 don’t have built-in hardware programmer like Arduino or NodeMCU, we need to setup a circuit by which we can upload appropriate code to ESP8266.
How to Upload Code to Generic ESP8266:
You need to setup the above circuit to upload any program to ESP8266. Make sure that you removed ATmega328P IC from Arduino board otherwise program won’t get uploaded and don’t connect Vcc of ESP8266 to 5V line.
Once you setup this circuit, power the Arduino via USB, now you need to press the two buttons in a sequential manner, only then the program code get uploaded.
- Press and hold the flash button.
- Now press reset button once, while holding flash button.
- Now you can leave the flash button, but don’t leave flash button while leaving reset button.
Now ESP8266 is ready to upload program code.
Program code for Generic ESP8266:
Note: Don’t forget to insert your channel ID, write API key, WI-FI SSID and password in the above code.
- Go to Tools > Board > select Generic ESP8266.
- Select baud rate as 115200.
- Hit the upload button.
If you successfully upload the code you will see a success message:
If you failed to upload the code, you will get some error message. If you get error message, you didn’t press the reset and flash buttons in the mentioned sequence or you did not wire the circuit correctly.
Full circuit diagram:
Once you uploaded the code to ESP8266, you need to wire the circuit as shown above and insert the IC back to Arduino board and upload the below given code to Arduino.
Program code for Arduino:
Now you know how to send LM35 temperature data to thingspeak using GSM, NodeMCU and generic ESP8266.
If you have any questions regarding these projects comment your questions below, you will get a guaranteed reply from us.