Introduction: Arduino IOT: Temperature and Humidity ( With ESP8266 WiFi)

Picture of Arduino IOT: Temperature and Humidity ( With ESP8266 WiFi)

Hello everyone! I am Michalis Vasilakis from and in this Instructables I will show you how to make your own Internet Of Things (IOT) thermometer by using the Arduino uno board.

You can use it at home, at the office, or anywhere there is an internet connection, for indoor or outdoor data logging. Ιn this project we will use the DHT-22 sensor to take temperature (oC) and humidity (%) values every one hour. For the internet connection we will use the ESP8266 WiFi (serial) module because it's small,cheap and easy to use, and for data logging we will use the open data platform for the Internet of Things "ThingSpeak" (

You can also make monthly or yearly average charts and see how your climate change affects your area!

So, let's get started!

P.S.: Updates and Q&A here:

Step 1: What We Will Need

Picture of What We Will Need

For this project we will need:

  • Arduino uno board (or any other Arduino board) (link)
  • Small breadboard (or an breadboard shield) (link)
  • DHT-22 sensor (link)
  • ESP8266 WiFi serial module (link)

...and off course some breadboard wires.

Update - Note:

Some users reported me that you may need an external 3.3V power supply for powering up the ESP8266. You can try to use the LD1117V33 (LD33V3) voltage regulator.

Step 2: The Circuit

Picture of The Circuit

The connections are pretty easy, watch the above image with the breadboard circuit schematic.



  • DHT-22 Vcc to Arduino 5V
  • DHT-22 Data to Arduino pin 2


  • Vcc, RST and CH_PD to Arduino 3.3V
  • RXD to Arduino pin 1 (TX)
  • TXD to Arduino pin 0 (RX)

Update - Note:

If you have any power problems with your ESP8266 module use one 3.3V voltage regulator (e.g. LD1117V33), connect the Vin pin of regulator with the Vin pin of Arduino uno board.

Step 3: ThingSpeak Account

Picture of ThingSpeak Account

Visit and click on the "Get Started" button to make a free account.

Now click on the "New Channel" (second image above). Give it a name and select two fields. If you want you can fill more info about your channel, e.g. Latitude and Longitude of your sensor. If you want to share sensor info with your friends (and more..) click on the "Make Public?" check box option. Finally click on the "Save Channel" button.

Click on your new channel and select the API keys tab (third image above). Copy your "Write API Key" , you will need it in the next step.

Step 4: The Code

Picture of The Code

Here's the code, embedded using Codebender!

Before you proceed:

  • Remove the RX and TX cables from the Arduino board
  • Add your information in the code below by pressing the "Edit" button:

  • #define SSID "name" // "SSID-WiFiname"
  • #define PASS "password" // "password"
  • String msg = "GET /update?key=YOUR_WRITE_KEY"; //change it with your key...

Try downloading the Codebender plugin and clicking on the "Run on Arduino" button to program your Arduino board with this sketch. And that's it, you've programmed your Arduino board directly from your browser!

Now you can re-connect the RX and TX cables. Now check your ThingSpeak channel to see the first sensor's info!

The "delay(3600000);" will send data to your ThingSpeak channel every one hour. It's not the best way for counting, but it's working fine ;).

How to find time in milliseconds:

1 minute has 60000ms, so for example: 15 minutes have 60000x15=900000ms

Step 5: Data Logger

Picture of Data Logger

You can see my channel here:

Check it again in one hour!

You can also download the "ThingView" application to your android device!

Step 6: What Next?

Picture of What Next?

You can make your own Arduino-based circuit and put it in a small box, just make sure that the sensor will be out of it.

I made mine and placed it on the wall outside of my house, you can check my temperature and humidity values here!

Future updates:

  • add a real clock circuit to control the time of data sending with accuracy
  • add a rechargeable battery and one small solar panel
  • add more charts for monthly and yearly average values

Step 7: Well Done!

Picture of Well Done!

You have successfully completed this guide and now you have your own Arduino IOT device up and running!

For more Arduino tutorials and cool projects you can visit our web page:

I hope you liked this, let me know in the comments!


payasonegro made it! (author)2017-01-05

Hi, I made two sensors last march. They work great, But... now in winter both don't record data below 10º C. ESP8266 sent data to thingspeak every hour but emty. I tried to put different DHT22 and same problem, no data are sending. I used your code and nothing. It's frustrating. Some idea?

NickC41 (author)payasonegro2018-01-08

Hi payasonegro!

I noticed a similar problem with my build in that it was working fine all night long last night whilst the temperature was below zero here but stopped working today the moment it rose above zero.

I then noticed a slight oversight in the coding - here's an example of the string it was trying to pass to ThinkSpeak which was failing: 1.4&field2=63

See that space before the temperature? When the temp was below zero that space would have been filled with a minus sign. For 10 degrees or over it would have a digit there. URLs hate spaces!

Thankfully there's a really simple fix - just add the following line of code in the updateTemp function just before line 72 (the one that reads "cmd += tempC;"):


This removes any leading or trailing spaces from the temperature value.

hymcode (author)2018-01-04

Hi their I tried following your guide to see if I could get my Grove DHT11 Temp & Humidity sensor to capture and upload data to my ThingSpeak account, but unfortunately no data is showing up on the site.

The only modifications I have made to the code is the pin i'm using and the code specific to my DHT11. Any help would be greatly appreciated.

nishabe (author)2017-12-30

Here is the direct link for the source code hoping that it will help others:

nishabe (author)2017-12-30

The code is no longer accessible in the codebender link.

Could you please check?

AlexandraS25 (author)2017-08-25

Is there a way to hook up two DHT22 sensors to an Arduino?

Electronicsnakes (author)2016-03-03

Tried everything and still getting





this is seriously p*ssin me off.

Hey...were you able to solve this issue?

JanD149 made it! (author)2017-07-23

Great code, thanks a lot, I added extra measurement for inside and outside temp. Great code example!. I only had to add ESP-01 fow V management.

Only problem I observed - I had to disconnect wifi module while uploading the code. Is ther some way to avoid it? Thanks!

HudhaifahD (author)2017-04-09

will this work with a dht11

Skymag (author)2016-03-16

Nice tutorial but I have a problem.

It looks like to work cause I obtain :



GET /update?key=F0DQUK7K9EMHJAGK&field1=21.0&field2=43



but nothing happen on Thingspeak :/

Channel Stats

Createdabout an hour agoUpdatedabout an hour ago

0 Entries

Can you help me ?

Ardumotive_com (author)Skymag2016-03-16

Try to change the delay time, use the delay(5000); this will send data every 5sec, and notice your channel.

One more thing, did you try the Serial.begin(115200); ?

Skymag (author)Ardumotive_com2016-03-16

Thanks for your help ! I change my ESP firmware from LUA to the initial AT firmware and now it works !! Thx for this tutorial :)

GharredH (author)Skymag2017-04-02

Hi, Could you please explain it to me, how did you do that ? I got the same message and I don't kow how to fix it.

Shankar AnanthA (author)Skymag2016-04-23

Thanks @Skymag . Changing the ESP firmware from LUA to AT did the trick. It now works for me :)

Skymag made it! (author)Shankar AnanthA2016-04-23

Happy to help you ;) Here is my weather station too !

Ardumotive_com (author)Skymag2016-05-28

Hi! I think that the write key that you are using is wrong.

Ardumotive_com (author)Skymag2016-03-16

Try to change the delay time, use the delay(5000); this will send data every 5sec, and notice your channel.

One more thing, did you try the Serial.begin(115200); ?

Odysseas_Lamtzidis (author)2016-08-16

Hey man,

Cool tutorial though you can do all these without the use of an arduino by programming directly the esp through the Arduino environment . (

Also as esp tends to be a bit unstable and power-hungry I would advice to power it externally and use a buck-converter instead of a regulator to ensure stability and minimise random reboots.


Shankar AnanthA made it! (author)2016-04-23

Thanks! Nice tutorial. A note on the ESP firmware can help users. I was stuck with that step till I read one of the users feedback.

payasonegro (author)2016-03-24

Works great in an UNO (only change and try bauds) but... it doesn't work with a Nano... some idea?

tschoep (author)2016-03-04


did some testing and got the following result:

When I do all steps manually, meaning loading up a clean sketch an sending each AT-Command manually, it works!!!!

So, I tried to find the problem in the sketch, but all that I found was, that the lines with Serial.find seem not to work. Wether the Serial.find("OK") nor the Serial.find(">") do what they are supposed to.

Ardumotive_com (author)tschoep2016-03-16

I don't know... maybe you have a different version of esp8266 or different firmware ...

tschoep (author)tschoep2016-03-04

Just to make clear:

while sending the data manually I got an "OK" in the monitor, but the program does NOT find it, because I can't see the lines of the connectWifi routine (AT+CWMODE=1 and AT+CWJAP=...)

The same with the Serial.find(">"). Doing all steps manually I find the ">" after sending the AT+CIPSEND command,

but the sketch does not and goes on with the AT+CIPCLOSE without sending cmd.

thompsms (author)2016-03-02

Well done! I am getting compile errors from your code associated with the DHT22 library that I have installed. I see there are several alternatives on GitHub. Can you please identify the particular one you used (perhaps a URL would do it?).

Many Thanks


Ardumotive_com (author)thompsms2016-03-02

Hi! Did you try to use Codebender? Codebender is the online Arduino IDE and it has already all necessary libraries about this project! Try it and let me know ;)


thompsms (author)Ardumotive_com2016-03-03

Ah yes! So Codebender effectively sets you up with an online default suite of libraries, making for a stable compile, so long as you can work within this default list. Neat, but captivity within this environment is both the upside and downside. I'm giving it a try. Thanks for your quick reply.

Murray Locksmith (author)2016-03-03

thanx for this collection

KazakosX (author)2016-03-03


astoichkov (author)2016-02-25

I did it many times and still nothing

Check these:

A. Check SSID/PASSWORD of your network and Write key from thinkspeak

B. Did you connect the esp8266 RX pin with Arduino TX pin and the esp8266 TX pin with Arduino RX pin? (cross connection)

C. Try with baud rate 115200 ( Serial.begin(115200); )

A. Checked
B.Cross connection. YES
C. Done

ESP8266 powered by YwRobot V2 (breadboard power) .ESP8266 can't connect.I've tried with another router( mobile phone hotspot) and no connection :(

toogo (author)2016-02-26

PS: I also needed a 3v3 external power, my ESP8266 draws to much for the Arduino.

Ardumotive_com (author)toogo2016-02-27

I will add a note in the guide about that ;) Thank you toogo!

toogo (author)2016-02-26

Found my problem.

I pasted the whole string between the brackets (" ") with the API key (what is normal in a code, but NOT here)

You need to replace ONLY the part YOUR_WRITE_KEY


String msg = "Frank own key here"; //change it with your key...


String msg = "GET /update?key=Frank own key here"; //change it with your key...

So leave "GET /update?key=

Hope this help others.


Ardumotive_com (author)toogo2016-02-27

Nice! Good work!

tschoep (author)2016-02-26

I got nearly the same problem as reported





But I was able to do 2 transmissions which I can see on my ThingSpeak Channel.

So, api_key and programming must be ok. Could it be a power supply issue?

toogo (author)2016-02-26

Same here:





I think it has to do with the kind of firmware is loaded on the ESP8266.

Does it need to be the AT firmware or LUNA firmware.

Better, can you tell us which firmware there is on your ESP8266 (there are so many).



Ardumotive_com (author)toogo2016-02-26

Well... I don't know.. my ESP8266 it's working fine, no need to change anything in firmware. Please try it with baud rate 115200 (Serial.begin(115200);) Also make sure that you have connected RX and TX cables correctly.

Also, the esp8266 is a serial device, so you don't need to consider witch firmware is uses.

erikhamburg (author)2016-02-26

The Arduino can source max. 50 mA on 3.3 V line, but an ESP-Module may take up to 250 mA.

A separate 3.3 V regulator must be used instead.

I am using it 2 days now with no problems.

Ardumotive_com (author)tschoep2016-02-26

hi! did you use the same program as mine?

If you can, try it with another 3.3V power supply (the esp8266).

But, I don't have problems with mine device... maybe they are many "esp8266" versions on the market..

astoichkov (author)2016-02-25

Doesn't work for me... Serial Monitor says:



Any ideas?

Re program it again, make sure that you copy paste the WRITE api key from your thinkspeak channel.

astoichkov (author)2016-02-25

Doesn't work for me... Serial Monitor says:



Any ideas?

Ardumotive_com (author)2016-02-25

that's correct! diy_bloke thank you for your comment ;)

toogo (author)Ardumotive_com2016-02-25

Clear, thank you.

toogo (author)2016-02-24

Wich code did you program the ESP8266?

Ardumotive_com (author)toogo2016-02-25

you don't need to program the esp8266

diy_bloke (author)Ardumotive_com2016-02-25

basically you are using the ESP8266 to connect teh Arduino to a network and then indeed one doesnt need to program the ESP8266.
However as the ESP8266 has input pins it can be used standalone, but then indeed it needs its own program

About This Instructable




More by Ardumotive_com:MIKE - Arduino Line Following Robot for Beginners "GRECO" - Arduino Object Avoiding Robotfor BeginnersArduino 3D Printed Digital Thermometer With DHT-22 Sensor
Add instructable to: