TTL to ESP01 thingspeak DTH11   Arduinesp esp8266 arduino
Shopping list
– 1 ESP8266 (for example version ESP01)
– DHT11
– 1 USB to TTL (I use FT232RL)
– 8 wires
– 1 breadboard
– a 3.3V power source (I use an battery in this example, power from your USB TTL will most likely might NOT work)

The hardware is based on a  USB to TTL with DTR and RST
If you do not have this have look at the Blink Manual Flash example, and add 2 buttons.
TTL to ESP01 thingspeak DTH11

TX     — RX
RX    — TX

+3.3V                     — CH_PD
battery –               — GND
battery +              — VCC
DHT11 VDD (1)   — VCC
DHT11 data  (2) — GPIO2
DHT11 (3)             —  not used
DHT11 (4)             — GND

Create an account on . It is very easy.
After login, create a new channel.

setup ThingSpeak

Add field1 and field2 in the tab “Chanel settings” like the picture above


Copy this code. Change ssid into your wifi accesspoint, and change the password into yours. And do not forget to change the API key into yours
and compile.


// Plot DTH11 data on using an ESP8266
// April 11 2015
// Author: Jeroen Beemster
// Website:

#include <DHT.h>
#include <ESP8266WiFi.h>

// replace with your channel’s thingspeak API key,
String apiKey = "4XZ9NA14HQZ7BYD7";
const char* ssid = "ssid";
const char* password = "password";

const char* server = "";
#define DHTPIN 2 // what pin we’re connected to

DHT dht(DHTPIN, DHT11,15);
WiFiClient client;

void setup() {

WiFi.begin(ssid, password);

Serial.print("Connecting to ");

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi connected");


void loop() {

float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");

if (client.connect(server,80)) { // "" or
String postStr = apiKey;
postStr +="&field1=";
postStr += String(t);
postStr +="&field2=";
postStr += String(h);
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: ");

Serial.print("Temperature: ");
Serial.print(" degrees Celcius Humidity: ");
Serial.println("% send to Thingspeak");

// thingspeak needs minimum 15 sec delay between updates

Download sorce code here: ThingspeakESP8266
DHT library (from adafruit) can be downloaded here

Press upload in the Arduino IDE, arduino will compile and upload.

Open the serial monitor from the menu tools. You will see if the data will be send to

The strange characters on the first line after a reset is normal.

Go to and open your channel. - ThingSpeak -

When you have uploaded the sketch, you may remove all the wires required for uploading.
This is what is left.
ESP01 thingspeak DTH11

Good luck.



29 thoughts on “ThingSpeak

  1. In the picture there are 2 AA batteries. I found out that this is 0.3 volt too less. So I used the power of my TTL to USB for the DTH11. The battery is still in use to power the ESP8266

  2. Thank you very much for this sketch, worked perfectly first time, I did change the sensor to a DHT22 without any problem (the DHT library includes both), after having spend the last 2 days struggling to get a similar sketch running reliably under Lua this has been so much easier, I had a problem under Lua causing the program to randomly lock up.
    The plan now is to see if I can add a motion sensor to the other pin and use this to help monitor a couple of vacation homes I looked after for friends.
    I’m using a 3.3v power supply for the DHT22 and ESP

  3. Hello!

    Could you please show a link to where I can download:

    What I could find that does not work with your program.
    It works fine with the example provided with the library (c:

  4. Thank you for writing this project up. It was useful to me.
    A note to any other beginners, the DHT library used here is the Adafruit DHT-sensor-library, not the libraries found on the main Arduino site.

    1. That was a useful information. I request admin to mention this with link in the main topic so that beginners like me will be benefited without any confusion.

      Thanks NigelTow!

  5. Thank You, Thank You, Thank You… Have been looking for a “simple” esp8266 talking to the dhtXX sensors. Your post gives a great start / foundation to expand…

  6. is it possible using a arduino for this ? i connected the esp8266 to the arduino uno then setting it up to dht11 but the problem is i dont have #include because im using arduino uno as the board

  7. Thanks for this code and the introduction to ThingSpeak – a great service. Your code worked the first time on an ESP8266-12, however, a few refinements may be helpful:

    – The WiFi.begin() at line 27 is redundant with line 34. Comment out line 27.
    – The & in front of field1= in line 56 is unnecessary.
    – The “\r\n\r\n” in line 60 is unnecessary.
    – The delay() in line 82 is problematic. It could block ESP8266 background processes. Better to use a timer based on millis(). See article at

    See my project in development at

    1. Well, in fact, just removing the & in front of field1= in line 56 does not work.
      This is because the previous line includes (wrongly) the API key, probably because the code prevously used the GET method. It is now useless as the key is part of the headers.
      So lines 55-56 should simply be replaced by :
      String postStr = “field1=”;

  8. Hello,
    Thank you for these posts.

    I followed your instructions and I get these warnings/errors continuously during Uploading:
    warning: espcomm_sync failed
    error: espcomm_open failed
    error: espcomm_upload_mem failed

    What could be the problem?

    What I tried:
    – change ESP module
    – change TX/RX wires
    – connect CH_P to ground/+3.3V
    – connect RST to ground/+3.3V

    The Arduino IDE is the latest (1.6.7).

    Thank you. 🙂

  9. Hi, This sketch worked also fine on my NodeMcu board (dev. kit v0.9). On the NodeMcu board v1.0 the values of the temperature and the humidity are both equal to zero. Has anyone any idea what to change?

    regards, Vincent

  10. Thanks a lot ! Your example helped a lot to figure out how to do this things.
    Based on your example – everything is up and running , but TEMP sensor failing
    and reporting 0 values for temperature and humidity.
    I was thinking that there are low power and connected DHT to 5V and placed resistor 220om between Vcc and Data (which connected to GPIO02).
    What can go wrong – to have “0” values and fail reading data from sensor ?

Leave a Reply