For a school research paper I have to measure the CO2 value of a given room. I thought it would be easiest to do with Arduino and a CO2 sensor. Luckily the school still had a MH-Z19C lying around so i got to use that.
I am now programming the sensor to give me relevant data like CO2 value (ppm) and temperature (°C).
I have searched online and found a piece of code i thought would work well. It was written for use with Arduino Mega so I adapted it to work with Arduino uno. But every time I try to upload it i get:
exit status 1
'Serial' does not name a type
This is my code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
// Start serial in setup routine
Serial.begin(9600);
// Command and response
byte cmd[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
byte response[9];
// Clear serial buffer
while (Serial.available() > 0) {
Serial.read();
}
// Send command and read response
Serial.write(cmd, 9);
Serial.readBytes(response, 9);
// Check if response is valid
if (response[0] != 0xFF) {
// wrong starting byte from co2 sensor
}
if (response[1] != 0x86) {
// Wrong command from co2 sensor
}
int ppm = (256 * response[2]) + response[3];
int temp = response[4]-40;
byte status = response[5];
int minimum = (256 * response[6]) + response[7];