SmartHome, Your own weatherstation with ESP8266 to measure temperature and humidity

Started on the old forum in July 2016 · view the original in the archive · old links redirect here

#dht21 #esp8266 #smarthome #smarthouse #weatherstation

3 replies · 448 views · started 10 years ago · 2 min read

2 participants
GumSlone Administrator Principal · 1,690 posts #1

Before you start, please read my previous topics how to program and prepare your esp8622 here: http://coding-talk.com/forum/main-fo...ows-is-similar Screenshot 2016-07-08 11.09.15.png

to make your weatherstation, you need:

  • Breadboard
  • some cables
  • 104 ceramic capacitor
  • 10kOhm resistor
  • dht11 or dht22 temperature and humidity sensor, (dht22 is more accurate but more expensive)
  • AMS1117
  • USB to TTL Programmer
  • ESP8266 ESP-03 (or other) Solder additional the 104 ceramic capacitor between VCC and GND pin of esp8266-03 to use it as decoupling capacitor for more stability and prevent unexpected restarts.

Download the attached weatherstation.zip php script and upload it to your webhost, remember the url of the receive_data.php file, you will need it in next steps.

Make sure you have correct firmware installed, this setup requires the dht and http module included in your build.

upload this init.lua code to your esp8266

--init.lua
wifi.setmode(wifi.STATION)
wifi.sta.config("your_wifi_ssid", "password")
wifi.sta.connect()

-- Connect
tmr.alarm(1, 1000, 1, function()
    if wifi.sta.getip()== nil then
        print("IP unavaiable, Waiting...")
    else
        tmr.stop(1)
        print("IP avaiable:"..wifi.sta.getip())
        dofile ("main.lua")
    end
end)

and main.lua

-- main.lua --
tmr.delay(5*1000000)

sensor = 1 --define the sensor number if you use multiple
pin = 4
  
 -- send data every 10 minutes
tmr.alarm(2, 600000, 1, function()    

status, temp, humi, temp_dec, humi_dec = dht.read(pin)

http.get("http://yoursite.net/weatherstation/sensors/receive_data.php?temp="..temp.."&humi="..humi.."&sensor="..sensor.."&key=blabla", nil, function(code, data)
    if (code < 0) then
      print("HTTP request failed")
    else
      print(code, data)
    end
end)

end)

change yoursite.net in the code to your domain name, you can also define your custom key in the url instead blablaand do the same in the receive_data.php file which is located in the attached php script.

Now connect everything like on the image: Untitled Sketch_Steckplatine.jpg

if you have done everything correctly, you should be able to view your sensor data in the generated graph with a php script.

There is another better, battery saving setup with esp8266 sleep mode, if you are interested in such setup please post your request here.

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Attachments: Screenshot 2016-07-08 11.09.15.png weatherstation.zip
GumSlone Administrator Principal · 1,690 posts #3

andre3 wrote: Love it man, maybe I should start posting basics about doing different stuff with android; Which in return will index more pages in search engines for users..

will be cool

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close