#10 NodeMCU: Display Realtime Temperature graph on ThinkSpeak cloud (using LM35 and ESP8266) | APDaga Tech

#10 NodeMCU: Display Realtime Temperature graph on ThinkSpeak cloud (using LM35 and ESP8266) | APDaga Tech

IoT Tutorial #10 [ NodeMCU Tutorials #2 ]
In this program,
Analog Temperature sensor (LM35) is connected to the NodeMCU ESP8266 board and Its output will be sent to https://thingspeak.com server (Cloud) where we can see the visual graph of Temperature vs Time.

ESP8266MOD NodeMCU 1.0 (ESP-12E Module) Board is used to connect to the Internet and send data to https://thingspeak.com server 


The output is shown using GRAPH (Temperature vs Time)on thinkspeak server.

Note:

Internal 10 bit ADC (A0) is used to read the Analog output of the Temperature Sensor (LM35).

you can visit the following link to check the step to configure Arduino IDE to connect to NodeMCU board and burn the first program in it:
http://www.apdaga.blogspot.com/2017/12/nodemcu-connect-to-arduino-ide-and-burn.html 


Requirements:
- NodeMCU board - 1.0 ESP8266 (ESP-12E Module)
- Micro USB Cable
- LM35 (Analog Temperature Sensor)
- Arduino IDE installed on your PC.
- Active Internet Connection

Physical Connections:
 NodeMCU Board  ->  LM35 (Analog Tempt Sensor)
3V3 -> Vcc (Left Pin - Flat side facing towards you)
A0 -> Analog Out (Middle Pin) (10mV / degree Celcious)
GND -> Gnd (Right Pin - Flat side facing towards you)


PIN Diagram of ESP8266MOD NodeMCU 1.0 (ESP-12E Module) Board:
+-------------------------------------------------------------------------------+
| o . o . o . o . o . o . o . o . o . o . o . o . o . o . o |
| Vin GND RST EN 3V3 GND CLK SD0 CM0 SD1 SD2 SD3 RSV RSV A0 |
| ANTENA |
| Facing ur side |
| |
| 3V3 GND Tx Rx D8 D7 D6 D5 GND 3V3 D4 D3 D2 D1 D0 |
| o . o . o . o . o . o . o . o . o . o . o . o . o . o . o |
+-------------------------------------------------------------------------------+

Serial Communication with PC through MicroUSB cable (Tx0 and Rx0)



Steps:
  1. Sign up at https://thingspeak.com
  2. Channels > New Channel > Update "Name" and "Field 1" field names > Save Channel
  3.  Click On API keys > Copy "Write API key"
  4.  Make all the Connections to Arduino Mega board mentioned Above.
  5.  Change Following 3 fields in the below-written program.
    a. apiKey by above copied "Write API key" (in step 3)
    b. ssid_name (Name of you WiFi)
    c. password (Password of your WiFi)
  6.  Upload Program to NodeMCU 1.0 (ESP-12E Module)
  7.  Open Arduino Serial Monitor on PC (Set Baud Rate to 115200 and set "Both NL & CR"
  8.  Go to https://thingspeak.com and login 
     Channels > My Channels > Click on Channel Name (created in step 2) > Private View
Here you can observe the Graph of Temperature Vs Day.

For Better understanding you can watch the demonstration video given below:

Downloads:
Download link is given in the Description of the YouTube video shown below.

Demonstration:




Program:

#include <ESP8266WiFi.h>      // Import NodeMCU Libraries

const char* host = "api.thingspeak.com"; // Your cloud domain
String ApiKey = "UUC6ZAZTL28P9SFU"; // Change this key to your "Write API key"
String path = "/update?key=" + ApiKey + "&field1="; // API Format


const char* ssid = "SuiteUp"; // Change this to your ssid_name (WiFi Name)
const char* pass = "welcome@10"; // Change this to your WiFi password

int sensor = A0; // Analog Input LM35 Output

float tempc;
float Digital_mVolt;


void setup(void){
Serial.begin(115200); // PC Arduino Serial Monitor
Serial.println("");

WiFi.begin(ssid, pass); // Func to Connect to WiFi

while (WiFi.status() != WL_CONNECTED) { // Wait for connection
delay(100);
Serial.print(".");
}

Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid); // Display confirmation msg to PC
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); // Display IP Address to PC
}


void loop() {

float analog_val = analogRead(sensor); // Read Analog Input


Digital_mVolt = (analog_val*3100.0)/1023; // Analog temperature to mVolt //Max Analog Input = 3.1V
tempc = Digital_mVolt/10; // Temperature from mVolt to degree Celsius
Serial.println(tempc); // Display Temperature to PC



WiFiClient client; // Create object of Class WiFiClient
const int httpPort = 80; // Port No. 80
if (!client.connect(host, httpPort)) { // If Couldn't connect
Serial.println("connection failed"); // Display error msg to PC
return;
}

client.print(String("GET ") + path + String(tempc) + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: keep-alive\r\n\r\n"); // Send Temperature data to Cloud

// thingspeak free version needs 16 sec delay between updates
delay(16000); // wait for 16sec

}




Click here to see more codes for NodeMCU ESP8266 and similar Family.
&
Click here to see more codes for Arduino Mega (ATMega 2560) and similar Family.

Feel free to ask doubts in the comment section. I will try my best to solve it.
If you find this helpful by any mean like, comment and share the post.
This is the simplest way to encourage me to keep doing such work.

Thanks and Regards,
-Akshay P. Daga
Post a Comment (0)
Previous Post Next Post