NodeMCU Projects: Difference between revisions

Content added Content deleted
Line 92: Line 92:


== DHT11 Temp Sensor ==
== DHT11 Temp Sensor ==

Source: [https://github.com/lvidarte/esp8266/wiki/MicroPython:-DHT11 github.com]


*Use DHT11 Module driectly, Do not use Sensor board with Pull Up resistor.
*Use DHT11 Module driectly, Do not use Sensor board with Pull Up resistor.
Line 110: Line 112:


<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
import time
from machine import I2C, Pin
from dht import DHT11
from esp8266_i2c_lcd import I2cLcd


d = DHT11(Pin(14)) # Pin D5
from machine import Pin
from dht import DHT11


d = DHT11(Pin(14)) # Pin D5
i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) # Pin D1 & D2
lcd = I2cLcd(i2c, 63, 2, 16)


while True:
d.measure()
d.measure()
d.temperature() d.humidity()
lcd.putstr("Temp is: " + str(d.temperature()) + "'C \nHum is: " + str(d.humidity()) + "%")
time.sleep(10)
lcd.clear()


</syntaxhighlight>
</syntaxhighlight>