Display Temperature and Humidity on Website and OLED(D-duino)

Last class I show the class how to use web control led at D-duino platform.

This class I will show how to use D-duino display temperature and humidity at the same time. D-duino will restart automatically every several seconds. So you can see the temperature and humidity directly from OLED. At the same time you can get this data from website.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Prepare

D-duino x1

dht11 sensor x1

Connect dht11 VCC to D-duino 3v3 pin

Connect dht11 GND to D-duino GND pin

Connect dht11 data to D-duino 5 pin

First I think you need to burn a new version firmware to D-duino. Please refer to this http://nodemcu.readthedocs.org/en/dev/en/build/

Step 2: Code

Then open ESPlorer write 2 files into D-duino:

init.lua

<p>wifi.setmode(wifi.STATION) <br>wifi.sta.config("Your wifi name","Your wifi password")
wifi.sta.connect() 
print("Setting up WIFI...")
tmr.alarm(1, 1000, 1, function() 
if wifi.sta.getip()== nil then 
print("IP unavaiable, Waiting...") 
else 
tmr.stop(1)
print("Config done, IP is "..wifi.sta.getip())
dofile("wifidht.lua")
end 
end)</p>

wifidht.lua

<p>pin = 5 -- The pin you connected the DHTXX<br>status, temp, humi, temp_dec, humi_dec = dht.read11(pin)
bimb = 1</p><p>function init_OLED(sda,scl,sla) --Set up the u8glib lib
 i2c.setup(0, sda, scl, i2c.SLOW)
 disp = u8g.ssd1306_128x64_i2c(sla)
 disp:setFont(u8g.font_6x10)
 disp:setFontRefHeightExtendedText()
 disp:setDefaultForegroundColor()
 disp:setFontPosTop()
end
function display() 
 disp:firstPage()
 repeat
 if wifi.sta.getip()== nil then
 disp:drawStr(0,0,"Wait")
 else
 disp:drawStr(0,0,wifi.sta.getip())
 disp:drawStr(0,12,"WiFi Connected")
 disp:drawStr(0,24,"Temperature")
 disp:drawStr(0,36,"Humidity")
 disp:drawStr(70,24,temp)
 disp:drawStr(70,36,humi)
 end
 until disp:nextPage() == false 
 end
 
 
 init_OLED(1,2,0x3c)
 display()</p><p>function sendData()
dht.read11(pin)
srv=net.createServer(net.TCP) 
srv:listen(80,function(conn) 
conn:on("receive", function(client,request)
 local buf = ""; 
 local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP"); 
 if(method == nil)then 
 _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP"); 
 end 
 local _GET = {} 
 if (vars ~= nil)then 
 for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do 
 _GET[k] = v 
 end 
 end 
 buf = buf.."
</p> Hello Dongsen Technology <p>"; 
 buf = buf.."
</p>"; 
 buf = buf.."
Tempurature<p>"..temp;
 buf = buf.."
</p>Humidity<p>"..humi.."%";
 client:send(buf);
 client:close(); 
 collectgarbage(); 
 conn:close()
 end) 
end)
end</p><p>tmr.alarm(2, 6000, 1, function() sendData() end )</p>

You can go to my website to find more interesting thing.

Then just restart D-duino check the IP and Temperature and humidity.
Not so hard but very funny!

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    Discussions

    0
    None
    hemam03

    Question 7 months ago on Step 2

    Hi!! do you something similar on Arduino IDE. I'm using a ESP32 wroom D-duino32-v3. trying to display the sensor values on oled. The board doesnt have proper documentation and it is hard to figure out which are SDA and SCL pins. Thank you.