So far i tried to combine multiple sensors but i couldnt combine mq131 ozone with others.
#include <MQ131.h>
// Define the serial port for MH-Z19B sensor (Serial2 on Arduino Mega)
#define MHZ19B_SERIAL Serial2
// Define the serial port for Bluetooth (Serial3 on Arduino Mega)
#define BLUETOOTH_SERIAL Serial3
// Define the baud rate for MH-Z19B sensor
#define MHZ19B_BAUDRATE 9600
// Define the command to read CO2 concentration
uint8_t MHZ19B_CMD_READ_CO2[] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
void setup() {
// Initialize Serial Monitor for debugging
BLUETOOTH_SERIAL.begin(9600);
Serial.begin(9600);
Serial1.begin(9600); // For PMS5003
MHZ19B_SERIAL.begin(MHZ19B_BAUDRATE);
MQ131.begin(3, A7, LOW_CONCENTRATION, 1000000);
Serial.println("Calibration in progress...");
MQ131.calibrate();
MQ131.getR0();
MQ131.getTimeToRead();
Serial.println("Calibration done!");
}
void readCO2() {
// Send command to MH-Z19B sensor to read CO2 concentration
MHZ19B_SERIAL.write(MHZ19B_CMD_READ_CO2, sizeof(MHZ19B_CMD_READ_CO2));
// Read response from the sensor
uint8_t response[9];
MHZ19B_SERIAL.readBytes(response, 9);
// Check if response is valid
if (response[0] == 0xFF && response[1] == 0x86) {
// Calculate CO2 concentration (high byte * 256 + low byte)
int co2 = response[2] * 256 + response[3];
// Print CO2 concentration to Serial Monitor
Serial.print("CO2 Level: ");
Serial.print(co2);
Serial.println(" ppm");
BLUETOOTH_SERIAL.print(co2);
BLUETOOTH_SERIAL.print("ppm");
BLUETOOTH_SERIAL.print(",");
} else {
// Print error if response is invalid
Serial.println("Error: Invalid response from sensor");
}
}
void readozon() {
MQ131.sample();
Serial.print(MQ131.getO3(UG_M3));
BLUETOOTH_SERIAL.print(MQ131.getO3(UG_M3));
BLUETOOTH_SERIAL.print("ug/m3");
BLUETOOTH_SERIAL.print(";");
}
void loop() {
readCO2();
delay(2000);
readozon();
delay(2000);
}
After I upload the code, i only get this.
19:21:15.986 -> Calibration in progress...
First i tried to power it up through arduino. After that i hooked it up externally and still won't work. But if i use it alone , it has no problem ( on my uno). I'm kinda done. I found no solution whatsoever. The external source is 9V @ 1A which goes through a dc-dc buck converter and i get 5V so there's no way the problem is on the electrical side. Also, it s the module sensor, not the raw one. The schematic is this:
licenta.pdf (130.2 KB)
Also , the code pins on my sketch aren't the same as my schematic (I mean this code MQ131.begin(3, A7, LOW_CONCENTRATION, 1000000); ) since I had problems with mq131 and i desperately tried to change the pinout of mq131. Same goes with the co2 sensor.