Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 9 // Read ID
- 10 uint8_t id = readByte(0x00);
- 11 Serial.print("ID: ");
- 12 Serial.println(id, HEX);
- 13
- 14 // Check sensor status
- 15 uint8_t sts = readByte(0x01);
- 16 Serial.print("Sensor status: ");
- 17 Serial.println(sts, HEX);
- 18
- 19 // Idle mode
- 20 writeByte(0x04, 0x00);
- 21 delay(400);
- 22
- 23 // Set measurement rate to 10 s
- 24 writeByte(0x02, 0x00);
- 25 writeByte(0x03, 0x0A);
- 26
- 27 // Configure continous mode
- 28 writeByte(0x04, 0x02);
- 29 }
- 30
- 31 void loop() {
- 32
- 33 // Poll measurement status
- 34 uint8_t meas_sts = readByte(0x07);
- 35 delay(100);
- 36
- 37 if (meas_sts == 0x10) {
- 38
- 39 // Get PPM value
- 40 uint8_t value1 = readByte(0x05);
- 41 delay(5);
- 42 uint8_t value2 = readByte(0x06);
- 43 delay(5);
- 44
- 45 // Calculate ppm value
- 46 int16_t result = value1 << 8 | value2;
- 47 Serial.print("CO2: ");
- 48 Serial.print(result);
- 49 Serial.println(" ppm");
- 50 }
- 51 delay(1000);
- 52 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement