MicroPython Codes of the PicoBricks
from machine import Pin
from picobricks importDHT11import utime
LIMIT_TEMPERATURE=20 #define the limit temperature
dht_sensor =DHT11(Pin(11, Pin.IN, Pin.PULL_DOWN))
m1 =Pin(21, Pin.OUT)
m1.low()
dht_read_time = utime.time()
#define input-output pins
while True:if utime.time()- dht_read_time >=3:
dht_read_time = utime.time()
dht_sensor.measure()
temp= dht_sensor.temperature
print(temp)if temp >=LIMIT_TEMPERATURE:
m1.high()
#operate if the room temperature is higher than the limit temperature
else:
m1.low()
Arduino C Codes of the PicoBricks
#include
#define LIMIT_TEMPERATURE27
#define DHTPIN11
#define DHTTYPEDHT11DHTdht(DHTPIN,DHTTYPE);
float temperature;voidsetup(){// put your setup code here, to run once:
Serial.begin(115200);
dht.begin();pinMode(21,OUTPUT);}voidloop(){// put your main code here, to run repeatedly:delay(100);
temperature = dht.readTemperature();
Serial.print("Temp: ");
Serial.println(temperature);if(temperature >LIMIT_TEMPERATURE){digitalWrite(21,HIGH);}else{digitalWrite(21,LOW);}}9
GitHub Project Page
Tags: