const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// pin for pwm reading
#define CO2_IN 10
// pin for uart reading
#define MH_Z19_RX 4 // D7
#define MH_Z19_TX 0 // D6
MHZ co2(MH_Z19_RX, MH_Z19_TX, CO2_IN, MHZ19B);
Hi @red_aka_anxiety !
I was a little bit puzzled by the following observations:
- The defined RX/TX pins (SoftwareSerial input and output used by the co2 sensor)
- pin 0 is dedicated for HardwareSerial
- pin 4 is connected to D5 of the LCD
The picture you posted shows that two lines go from the sensor board to D7 and D6 of the Arduino. Coincidently these pins have been commented out in the definition of MH_Z19_RX and MH_Z19_TX ...
Your latest code from post 22 does not comply to the wiring in post 9.
I assume you are using this library
https://github.com/tobiasschuerg/MH-Z-CO2-Sensors/tree/master
and the example provided there ...
Unfortunately that example already contains the issues regarding the wrong pin for SoftwareSerial on an Arduino where Serial is used for other purposes. Actually SoftwareSerial is not required at all when the data are only taken from a pwmPin.
It would be much cleaner to initialize the sensor class with this constructor so that the SoftwareSerial is not initialized at all and remove the wires from/to RX/TX of the sensor board.
//MHZ(uint8_t pwmpin, SensorType type, MeasuringRange range = RANGE_5K);
// should look like this
MHZ co2(CO2_IN, MHZ19B, RANGE_5K);