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

Hello everyone! I am Michalis Vasilakis from www.ardumotive.com 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" (www.thingspeak.com).

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: http://www.ardumotive.com/iot-wifi-temp-and-humidity.html

Step 1: 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

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

Notes:

DHT-22

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

ESP8266

  • 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

Visit www.thingspeak.com 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

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

You can see my channel here: https://thingspeak.com/channels/90526

Check it again in one hour!

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

Step 6: 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!

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: www.ardumotive.com

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

Comments

author
Electronicsnakes (author)2016-03-03

Tried everything and still getting

AT+CIPCLOSE

AT+CIPSTART="TCP","184.106.153.149",80

AT+CIPSEND=55

AT+CIPCLOSE

this is seriously p*ssin me off.

author

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

author
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!

IMG_9571.JPG
author
HudhaifahD (author)2017-04-09

will this work with a dht11

author
Skymag (author)2016-03-16

Nice tutorial but I have a problem.

It looks like to work cause I obtain :

AT+CIPSTART="TCP","184.106.153.149",80

AT+CIPSEND=56

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

AT+CIPSTART="TCP","184.106.153.149",80

AT+CIPSEND=56

but nothing happen on Thingspeak :/

Channel Stats

Createdabout an hour agoUpdatedabout an hour ago


0 Entries

Can you help me ?

author
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); ?

author
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 :)

author
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.

author
Shankar AnanthA (author)Skymag2016-04-23

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

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

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

edited_1461343842781.jpg
author
Ardumotive_com (author)Skymag2016-05-28

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

author
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); ?

author
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?

20170105_145155711_iOS.jpg20170105_145130867_iOS.jpg
author
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 . (https://github.com/esp8266/Arduino)

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.

Cheers!

author
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.

IMG_20160423_162313.jpg
author
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?

author
tschoep (author)2016-03-04

Hi,

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.

author
Ardumotive_com (author)tschoep2016-03-16

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

author
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.

author
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

Martin

author
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 ;)

Thanks!

author
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.

author
Murray Locksmith (author)2016-03-03

thanx for this collection

author
KazakosX (author)2016-03-03

clever

author
astoichkov (author)2016-02-25

Doesn't work for me... Serial Monitor says:
AT+CIPCLOSE

AT+CIPSTART="TCP","184.106.153.149",80

AT+CIPSEND=55

AT+CIPCLOSE
Any ideas?

author

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

author

I did it many times and still nothing

author

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); )

author

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 :(

author
toogo (author)2016-02-26

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

author
Ardumotive_com (author)toogo2016-02-27

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

author
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

WRONG:

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

CORRECT:

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

So leave "GET /update?key=

Hope this help others.

//Frank

author
Ardumotive_com (author)toogo2016-02-27

Nice! Good work!

author
tschoep (author)2016-02-26

I got nearly the same problem as reported

AT

AT+CIPSTART="TCP","184.106.153.149",80

AT+CIPSEND=56

AT+CIPCLOSE

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?

author
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..

author
toogo (author)2016-02-26

Same here:

AT

AT+CIPSTART="TCP","184.106.153.149",80

AT+CIPSEND=39

AT+CIPCLOSE

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).

Thanx

Frank

author
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.

author
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.

author

I am using it 2 days now with no problems.

author
astoichkov (author)2016-02-25

Doesn't work for me... Serial Monitor says:
AT+CIPCLOSE

AT+CIPSTART="TCP","184.106.153.149",80

AT+CIPSEND=55

AT+CIPCLOSE
Any ideas?

author
toogo (author)2016-02-24

Wich code did you program the ESP8266?

author
Ardumotive_com (author)toogo2016-02-25

you don't need to program the esp8266

author
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

author
Ardumotive_com (author)diy_bloke2016-02-25

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

author
toogo (author)Ardumotive_com2016-02-25

Clear, thank you.

author
Sub field (author)2016-02-24

Sorry for talking with different field but i need arduino code for pwm for single phase inverter with 4 igbts
Thanks in advance

author
diy_bloke (author)Sub field2016-02-25

isnt that just "analogWrite(pin);" ?

author
Ardumotive_com (author)Sub field2016-02-24

I don't know what is that :P

author
Sub field (author)Ardumotive_com2016-02-24

A pulse width modulation code

author
Ardumotive_com (author)Sub field2016-02-25

I know what is PWM, I don't know how you can "control a single phase inverter with 4 igbts"