DHT12.ino 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. Description: Use DHT12 Sensor to read temperature, humidity and display the
  3. data on the screen.
  4. */
  5. #include <M5Stack.h>
  6. #include <Wire.h> //The DHT12 uses I2C comunication.
  7. #include "DHT12.h"
  8. DHT12 dht12; // Preset scale CELSIUS and ID 0x5c.
  9. /*
  10. For configuration library:
  11. DHT12 dht12("Scale temperature","ID device for I2C");
  12. On "Scale temperature" you can select the preset scale:
  13. CELSIUS, FAHRENHEIT or KELVIN.
  14. And on "ID device", you can put ID sensor, on DHT12
  15. normally is 0x5c.
  16. Examples:
  17. DHT12 dht12;
  18. The preset scale is CELSIUS and ID is 0x5c.
  19. DHT12 dht12(KELVIN);
  20. the preset scale is KELVIN and ID is 0x5c.
  21. DHT12 dht12(FAHRENHEIT,0x53);
  22. The preset scale is FAHRENHEIT and ID is 0x53.
  23. */
  24. void setup() {
  25. M5.begin();
  26. M5.Power.begin();
  27. Wire.begin();
  28. Serial.println("Prueba de libreria DHT12:");
  29. M5.Lcd.println("Prueba de libreria DHT12:");
  30. }
  31. void loop() {
  32. // Read temperature with preset scale.
  33. Serial.print("Temperatura: ");
  34. M5.Lcd.print("Temperatura: ");
  35. Serial.print(dht12.readTemperature());
  36. M5.Lcd.print(dht12.readTemperature());
  37. // Read humidity.
  38. Serial.print("*C Humedad: ");
  39. M5.Lcd.print("*C Humedad: ");
  40. Serial.print(dht12.readHumidity());
  41. M5.Lcd.println(dht12.readHumidity());
  42. // Read temperature as forced fahrenheit.
  43. Serial.println("%RH");
  44. Serial.println("%RH");
  45. Serial.print("Temperatura: ");
  46. Serial.print(dht12.readTemperature(FAHRENHEIT));
  47. // Read termperature as forced kelvin.
  48. Serial.println("*F");
  49. Serial.print("Temperatura: ");
  50. Serial.print(dht12.readTemperature(KELVIN));
  51. Serial.println("*K");
  52. delay(5000);
  53. }