Begin typing your search above and press return to search. Press Esc to cancel.

Upload DS18b20 Temperature Sensor Data to Thingspeak from Esp8266 (nodemcu)

Hello all in this tutorial you will know how to use Ds18b20 Temperature data to, you can follow above fritzing circuit diagram to control the Ds18b20 temperature sensor, This sensor follows one wire protocol which means you can connect many sensors as you want to the single pin and access temperature data calling the sensor by address.

check the video below on how to work with this sensor and also proof of code working .

There is no much work to get work with this sensor, as there are plenty of example library that already available in the internet which anyone can make use and get started to work with this sensor. 

Test the below code to know check whether you can get reading from the temperature sensor with ESP8266 or Nodemcu

if you get any error , make sure you have downloaded library for Ds18b20 Temperature sensor. 
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices 
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
void setup(void)
  // start serial port
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
void loop(void)
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures

  Serial.print("Temperature for Device 1 is: ");
  Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? 
    // You can have more than one IC on the same bus. 
    // 0 refers to the first IC on the wire


copy paste above code to your Arduino IDE and upload to your ESP8266 or Nodemcu if you are not sure about how to do this please check the video about to know how things work, if you don't know yet to search search on this blog for getting started with Esp8266 in Arduino IDE.

below you can see the code for sending temperature data to from Esp8266 or Nodemcu to do this you need have thingspeak api key which can get easily by registering to the website.

change SSID and password to your router password and also update the Nodemcu api key.

#include <ESP8266WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define myPeriodic 15 //in sec | Thingspeak pub is 15sec
#define ONE_WIRE_BUS 2  // DS18B20 on arduino pin2 corresponds to D4 on physical board

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);
float prevTemp = 0;
const char* server = "";
String apiKey ="Things speak api key";
const char* MY_SSID = "your router name "; 
const char* MY_PWD = "your wifi password";
int sent = 0;
void setup() {

void loop() {
  float temp;
  //char buffer[10];
  temp = DS18B20.getTempCByIndex(0);
  //String tempC = dtostrf(temp, 4, 1, buffer);//handled in sendTemp()
  Serial.print(String(sent)+" Temperature: ");
  //if (temp != prevTemp)
  //prevTemp = temp;
  int count = myPeriodic;

void connectWifi()
  Serial.print("Connecting to "+*MY_SSID);
  WiFi.begin(MY_SSID, MY_PWD);
  while (WiFi.status() != WL_CONNECTED) {
}//end connect

void sendTeperatureTS(float temp)
   WiFiClient client;
   if (client.connect(server, 80)) { // use ip or
   Serial.println("WiFi Client connected ");
   String postStr = apiKey;
   postStr += "&field1=";
   postStr += String(temp);
   postStr += "\r\n\r\n";
   client.print("POST /update HTTP/1.1\n");
   client.print("Connection: close\n");
   client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
   client.print("Content-Type: application/x-www-form-urlencoded\n");
   client.print("Content-Length: ");
   }//end if
}//end send


if you like the above tutorial and if you want try out with cool projects you can also check this link here , that's the amazon book link where you can use that book to make IoT with Esp8266 or Nodemcu, that books gives you basic coverage on how to do simple things and get yourself started with arduino and goes on developing projects like sending data to webserver and creating a webserver, uploading and controlling data from a webpage, how to interface TFT LCD and I2C devices and many more things can find on the link.

Thanks for stopping by and read this blog. 


  1. Very nice and helpful information has been given in this article. I like the way you explain the things. Keep posting. Thanks..

  2. hello.


    ""exit status 1
    Error compiling for board Arduino/Genuino Uno.""


    1. MY ALSO SHOWING SAME PROBLEM.. have you got any solution

    2. Install the wificlient board from board manager and make sure that the spelling is spelled in correct way

  3. Hello!
    Why I have this erorr ?? : #error "Please define I/O register types here"
    Thanks !


  5. in arduino software i am unable to see port:COM14 it is showing COM3 for me .so how to change the port to COM14 you mentioned in the video .if any change i have to do please send it to

  6. This is gigantic thus exact here. Much obliged to you for posting them. Extraordinary bit of writing given that much drawing closer into the part. These sorts of articles are truly prepared to assist for the humanity and one who are secretive with these. Custom essay Writing Service is an accomplished, multitasking and solid online custom writing affiliation, went for giving competent writing help to understudies wherever all through the world. this service center their endeavors on the understudies' most astonishing results, smart illuminating improvement and information change.

  7. Hi, I have problem: stray '\302' in program. Any ideas?

  8. I think that all it's correct but always temperature is -127. I tried with differents DS18b.... Some ideas?

  9. Hi,

    I've got the same probems like nelun and Abhinav. (#error "Please define I/O register types here")
    I saw that dubnikov replied with a solution but I still don't understand.
    Can I have more information about that. Thanks

  10. Hi, Problem solved for the I/O register.
    Now got problem that connect wifi was not declared. Anybody some info?

  11. Thanks for this. I've been trying to do this by various means but this work straight off. Just needed to change the pin number. I would say that a delay in the first code is needed because it reads too quickly. Thank you.

  12. I have enjoyed reading through the article and the comments. I have learned a lot and understood the topic under discussion from a different point of view. I take this opportunity to thank the author for the continual commitment to keep us updated with quality articles that are not only entertaining but also educative. Feel free to hire our professional writers by clicking on PhD Dissertation Data Analysis Using Stata Software.

  13. The internet has changes the way the people apply their thinking into the development of their own ideas. I am very sure that the scholars are one of the categories of people who are applying the internet of thinking into their Research Paper Sentences so as to produce high-quality research content. this article has clearly unveiled the importance of the internet of thinking.

  14. Nice work with good ideas and concepts, lots of great information which we all need, helpful information. I would like to thank you for the efforts you shown remarkable writing skill in this article Custom Essay Writing Service

  15. I enjoyed the artical.I learn lot of topics under discussion from a point of view Iot is the inter networking of physical device and electronics,software, sensors,actuators,and network connectivity which enable objects to collect and exchange data.
    If you are looking for the internetofthinkings and sevices then very big company

  16. Thanks for posting your valuable thoughts with us & our readers. Please keep continue writing on this blog.
    Bulk SMS Service Provider

  17. Thanks for sharing this post, this post is really very informative
    Private Detective Agency In Punjab

  18. i got code compiled and uploaded and serial monitor is showing this result
    {⸮⸮⸮{⸮_⸮{⸮_⸮{⸮_⸮{⸮_{Ÿ⸮{⸮_⸮{Ο⸮⸮⸮_⸮{⸮⸮⸮{⸮⸮⸮⸮Λ⸮{Ÿ⸮{⸮_⸮⸮_⸮⸮⸮_⸮{⸮_⸮⸮⸮_⸮⸮⸮_⸮⸮_⸮. any help is much appreciated. Thank you very much for posting this huge code block. I would never have been able to do it. This really helps me to focus on the project, not the code.

    1. i got the answer to this on another site. I had to increase the speed of the monitor to match the coded level of 115,200. Still have not been able to update my channel but now know the wifi is connected via the message on the serial monitor.

    2. This comment has been removed by the author.

    3. how to increase the speed of monitor?

  19. waoo well written post regarding "Upload DS18b20 Temperature Sensor Data to Thingspeak from Esp8266 (nodemcu)"


    Commodity Tips Free Trial

  20. Thanks a lot for posting this post, Your post has always been an informative source for me.
    v belts manufacturers in india

  21. pls help with this error
    error: Failed to open COM1
    error: espcomm_open failed
    error: espcomm_upload_mem failed
    I cant select any port.What could be the reason

  22. This comment has been removed by the author.

  23. " Board nodemcuv2 (platform esp8266, package esp8266) is unknown

    Error compiling for board NodeMCU 1.0 (ESP-12E Module). "

    i have this problem. what should i do?? please help me.

  24. Can you help me to add more sensor and send data to another field under same channel on

  25. hai seeing video would you please share me mobile number or call me 9940594278

  26. hi Thanks for sharing this valuable Information.
    Charter Speed Test Result

  27. thanks for sharing the more valuable information.
    Indian Cyber Army credibility in Ethical hacking training & Cybercrime investigation training is acknowledged across nation as we offer hands on practical knowledge and full assistance with basic as well as advanced level ethical hacking & cybercrime investigation courses. The training is conducted by subject specialist corporate professionals with wide experience in managing real-time ethical hacking/ cyber security projects. Indian Cyber Army implements a blend of academic learning and practical sessions to give the candidate optimum exposure.Ethical hacking training ,Ethical hacking course

  28. It is a very valuable piece of data. I believe it can have a great impact in the field of the internet of things development. We need to take great care to never let any information or attachment go to waste hence it's vital we are able to use such pieces of code to fix the rest of it.