Post-DHT12.ino 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*************************************************************
  2. Download latest Blynk library here:
  3. https://github.com/blynkkk/blynk-library/releases/latest
  4. Blynk is a platform with iOS and Android apps to control
  5. Arduino, Raspberry Pi and the likes over the Internet.
  6. You can easily build graphic interfaces for all your
  7. projects by simply dragging and dropping widgets.
  8. Downloads, docs, tutorials: http://www.blynk.cc
  9. Sketch generator: http://examples.blynk.cc
  10. Blynk community: http://community.blynk.cc
  11. Follow us: http://www.fb.com/blynkapp
  12. http://twitter.com/blynk_app
  13. Blynk library is licensed under MIT license
  14. This example code is in public domain.
  15. *************************************************************
  16. This example shows how value can be pushed from Arduino to
  17. the Blynk App.
  18. NOTE:
  19. BlynkTimer provides SimpleTimer functionality:
  20. http://playground.arduino.cc/Code/SimpleTimer
  21. App project setup:
  22. Value Display widget attached to Virtual Pin V5
  23. *************************************************************/
  24. #include <BlynkSimpleEsp32.h>
  25. #include <M5Stack.h>
  26. #include <WiFi.h>
  27. #include <WiFiClient.h>
  28. #include <Wire.h> //The DHT12 uses I2C comunication.
  29. #include "DHT12.h"
  30. DHT12 dht12; // Preset scale CELSIUS and ID 0x5c.
  31. // You should get Auth Token in the Blynk App.
  32. // Go to the Project Settings (nut icon).
  33. char auth[] = "auth";
  34. char ssid[] = "SSID";
  35. char pass[] = "PASSWD";
  36. BlynkTimer timer;
  37. // This function sends Arduino's up time every second to Virtual Pin (5).
  38. // In the app, Widget's reading frequency should be set to PUSH. This means
  39. // that you define how often to send data to Blynk App.
  40. void myTimerEvent() {
  41. // You can send any value at any time.
  42. // Please don't send more that 10 values per second.
  43. // Blynk.virtualWrite(V9, millis() / 1000)
  44. float tmp = dht12.readTemperature();
  45. float hum = dht12.readHumidity();
  46. Serial.printf("Temperatura: %2.2f*C Humedad: %0.2f%%\r\n", tmp, hum);
  47. Blynk.virtualWrite(V0, tmp);
  48. Blynk.virtualWrite(V1, hum);
  49. M5.Lcd.setCursor(0, 0);
  50. M5.Lcd.setTextColor(WHITE, BLACK);
  51. M5.Lcd.setTextSize(3);
  52. M5.Lcd.printf("Temperatura:%2.1f \r\nHumedad: %2.0f%%", tmp, hum);
  53. }
  54. void setup() {
  55. // Debug console
  56. M5.begin();
  57. M5.Power.begin();
  58. Wire.begin();
  59. // Blynk start
  60. Blynk.begin(auth, ssid, pass, "blynk.m5stack.com");
  61. // Setup a function to be called every second
  62. timer.setInterval(2000L, myTimerEvent);
  63. M5.Lcd.setBrightness(10);
  64. }
  65. void loop() {
  66. Blynk.run();
  67. timer.run(); // Initiates BlynkTimer
  68. }