900| 2
|
[ESP8266/ESP32] esp32 C6基于Blynk的物联网气象站 |
前两天做一个Blynk的点灯小程序,在这个基础上拓展一下。连接了五合一环境传感器, 焊接上太阳板和3.7V锂电池电池可以实现一个具有持续供电功能的物联网气象站。至在Blynk里面添加4个Label组件和2个Gauge组件最后放一个Slider来显示电池电量。 下面看效果。 下面是程序代码 /************************************************************* ESP32-C6基于Blynk的物联网气象站 2024年4月22日 源启 *************************************************************/ #define BLYNK_TEMPLATE_ID "TMP" //修改为你的TEMPLATE_ID #define BLYNK_TEMPLATE_NAME "Quick" //修改为你的TEMPLATE_NAME #define BLYNK_AUTH_TOKEN "hEqqn" ////修改为你的BLYNK_AUTH_TOKEN #define BLYNK_PRINT Serial #include "DFRobot_EnvironmentalSensor.h" #define MODESWITCH 0 #include <WiFi.h> #include <WiFiClient.h> #include <BlynkSimpleEsp32.h> char ssid[] = ""; //设置wifi名称 char pass[] = ""; //设置wifi密码 DFRobot_EnvironmentalSensor environment(/*addr = */SEN050X_DEFAULT_DEVICE_ADDRESS, /*pWire = */&Wire); int temperature; int humidity; int atmospheric; int light; int power; BlynkTimer timer; void myTimer() { Blynk.virtualWrite(V0, temperature); Blynk.virtualWrite(V1, humidity); Blynk.virtualWrite(V2, atmospheric); Blynk.virtualWrite(V3, light); Blynk.virtualWrite(V4, power); } void setup() { #if MODESWITCH #if defined(Arduino_AVR_UNO)||defined(ESP8266) mySerial.begin(9600); #elif defined(ESP32) Serial1.begin(9600, SERIAL_8N1, /*rx =*/D3, /*tx =*/D2); #else Serial1.begin(9600); #endif #endif Serial.begin(115200); while(environment.begin() != 0){ Serial.println(" Sensor initialize failed!!"); delay(1000); } Serial.println(" Sensor initialize success!!"); Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); timer.setInterval(1000L, myTimer); } void loop() { int analogValue = analogRead(0); int analogVolts = analogReadMilliVolts(0); Serial.println(temperature); // Reading sensor from hardware analog pin A0 temperature = environment.getTemperature(TEMP_C); humidity = environment.getHumidity(); atmospheric = environment.getAtmospherePressure(HPA); light = environment.getLuminousIntensity(); power = ((analogVolts* 2.1218 + 1000)/1000); Blynk.run(); timer.run(); } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed