@@ -13,6 +13,12 @@ SoftwareSerial sensorSerial(sensor_receiver_pin, sensor_transmitter_pin);
13
13
LiquidCrystal_I2C lcd (0x27 , 16 , 2 );
14
14
Sds011SensorHandler sensorHandler (sensorSerial);
15
15
16
+ unsigned long measurement_start_time = 0 ;
17
+ bool is_work_mode_active = false ;
18
+
19
+ String pm25Output = " " ;
20
+ String pm10Output = " " ;
21
+
16
22
void setup () {
17
23
Serial.begin (115200 );
18
24
sensorSerial.begin (9600 );
@@ -24,16 +30,33 @@ void setup() {
24
30
lcd.print (" Starting..." );
25
31
sensorHandler.sendQueryReportModeCommand ();
26
32
delay (1000 );
33
+ sensorHandler.sendActiveReportModeCommand ();
34
+ delay (1000 );
27
35
}
28
36
29
37
void loop () {
30
- sensorHandler.sendWorkModeCommand ();
31
- delay (45000 ); // Wait for sensor stabilization
32
- sensorHandler.sendQueryDataCommand ();
33
- delay (1000 );
34
- readMeasurementData ();
35
- sensorHandler.sendSleepModeCommand ();
36
- delay (60000 );
38
+ if (millis () - measurement_start_time > 60000 ) {
39
+ sensorHandler.sendQueryReportModeCommand ();
40
+ delay (1000 );
41
+ sensorHandler.sendSleepModeCommand ();
42
+ lcd.clear ();
43
+ lcd.setCursor (0 , 0 );
44
+ lcd.print (pm25Output);
45
+ lcd.setCursor (0 , 1 );
46
+ lcd.print (pm10Output + " slp" );
47
+ delay (60000 );
48
+ measurement_start_time = millis ();
49
+ is_work_mode_active = false ;
50
+ } else {
51
+ if (is_work_mode_active == false ) {
52
+ sensorHandler.sendWorkModeCommand ();
53
+ delay (1000 );
54
+ sensorHandler.sendActiveReportModeCommand ();
55
+ delay (1000 );
56
+ is_work_mode_active = true ;
57
+ }
58
+ readMeasurementData ();
59
+ }
37
60
}
38
61
39
62
String getDateTime () {
@@ -53,8 +76,8 @@ uint8_t esp32_data_head = 0xAA;
53
76
54
77
void readMeasurementData () {
55
78
PmResult pmResult = sensorHandler.readPmResult ();
56
- String pm25Output = " PM2.5:" + String (pmResult.pm25 ) + " ug/m3" ;
57
- String pm10Output = " PM10:" + String (pmResult.pm10 ) + " ug/m3" ;
79
+ pm25Output = " PM2.5:" + String (pmResult.pm25 ) + " ug/m3" ;
80
+ pm10Output = " PM10:" + String (pmResult.pm10 ) + " ug/m3" ;
58
81
59
82
lcd.clear ();
60
83
lcd.setCursor (0 , 0 );
0 commit comments