Hey all,
I'm new to using Arduino's.
I purchased a MH-Z16 Co2 sensor, I hooked it up and when I run the demo code that is from the manufacturer and when i go to monitor it says error: failed to connect to sensor...
So I have it going from Ground to Ground, VCC to 5V, RX to pin 1 and TX to pin 2.
This is the code i'm using.
#include <SoftwareSerial.h>
#include <NDIR_SoftwareSerial.h>
//Select 2 digital pins as SoftwareSerial's Rx and Tx. For example, Rx=2 Tx=3
NDIR_SoftwareSerial mySensor(0, 1); // RX, TX
void setup()
{
pinMode(0, OUTPUT);
pinMode(1, INPUT);
Serial.begin(9600);
if (mySensor.begin()) {
Serial.println("Wait 10 seconds for sensor initialization...");
delay(10000);
} else {
Serial.println("ERROR: Failed to connect to the sensor.");
while(1);
}
}
void loop() {
if (mySensor.measure()) {
Serial.print("CO2 Concentration is ");
Serial.print(mySensor.ppm);
Serial.println("ppm");
} else {
Serial.println("Sensor communication error.");
}
delay(1000);
}
Any thoughts?