mq135_dht11_example.py 811 B

12345678910111213141516171819202122232425262728
  1. import time
  2. from dht import DHT11
  3. from machine import Pin
  4. from mq135 import MQ135
  5. # setup
  6. mq135 = MQ135(Pin(0)) # analog PIN 0
  7. dht11 = DHT11(Pin(14))
  8. # loop
  9. while True:
  10. dht11.measure()
  11. temperature = dht11.temperature()
  12. humidity = dht11.humidity()
  13. rzero = mq135.get_rzero()
  14. corrected_rzero = mq135.get_corrected_rzero(temperature, humidity)
  15. resistance = mq135.get_resistance()
  16. ppm = mq135.get_ppm()
  17. corrected_ppm = mq135.get_corrected_ppm(temperature, humidity)
  18. print("DHT11 Temperature: " + str(temperature) +"\t Humidity: "+ str(humidity))
  19. print("MQ135 RZero: " + str(rzero) +"\t Corrected RZero: "+ str(corrected_rzero)+
  20. "\t Resistance: "+ str(resistance) +"\t PPM: "+str(ppm)+
  21. "\t Corrected PPM: "+str(corrected_ppm)+"ppm")
  22. time.sleep(1)