už několik dní se pokouším zkalibrovat senzor MQ-135, ale pořád to propisuje nesmyslné hodnoty. Dle doporučení jsem nechal senzor na 24h "zahořet", dal jej ven a po hodině jsem vyčetl hodnotu RZERO, kterou jsem vepsal do souboru mq135.h a nahrál do arduina. Teď mi zobrazuje správnou hodnotu (cca 400ppm) venku, ale když jej nechám měřit doma, tak to propisuje hodnoty až 50000ppm, tedy smrtelné prostředí.
Posílám to přes po WIFI přes MQTT do Home Assistant. Teplotu a vlhkost to propisuje správně, ale nemůžu prostě docílit toho vzduchu. Potřebuji to funkční, abych mohl spouštět rekuperaci na základě kvality vzduchu.
Poradíte laikovi?
Děkuji
Arduino
Kód: Vybrat vše
//WiFi
#include <ESP8266WiFi.h>
const char* ssid = "xxxxx";
const char* password = "xxxxx";
WiFiClient espClient;
//MQTT
#include <PubSubClient.h>
#define mqtt_server "xxxxx"
#define mqtt_clientId "xxxxx"
#define mqtt_user "xx"
#define mqtt_password "xx"
PubSubClient client(espClient);
// MQTT Topics
#define humidity_topic "sensor/humidity_loz"
#define temperature_topic "sensor/temperature_loz"
#define co2_topic "sensor/co2_loz"
//DHT
#include <DHT.h>
#include <DHT_U.h>
#define DHTTYPE DHT22 // Тип датчика
#define DHTPIN 4 //К какому пину подключен датчик DHT
DHT dht (DHTPIN, DHTTYPE);
//MQ135
#include <MQ135.h>
MQ135 gasSensor = MQ135 (A0); //Датчик газа подключен к аналоговому пину
//BH1750
#include <Wire.h>
#define I2C_SDA_PIN (4) // D2 pin (SDA / GPIO-4)
#define I2C_SCL_PIN (5) // D1 pin (SCL / GPIO-5)
//Timer
#include <TimeLib.h>
#include <SimpleTimer.h>
SimpleTimer timer;
unsigned long lastSampleTime = 0;
const long sampleDelay = 30000;
void setup() {
Serial.begin(115200);
dht.begin();
Wire.begin( I2C_SDA_PIN, I2C_SCL_PIN );
setupWifi();
client.setServer(mqtt_server, 14331);
timer.setInterval(5000L,sendTemps);
}
void sendTemps (){
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)){
return;
}
float rzero = gasSensor.getRZero();
float ppm = gasSensor.getPPM();
float rzeroc = gasSensor.getCorrectedRZero(t, h);
float ppmc = gasSensor.getCorrectedPPM(t, h);
Serial.print("Humidity: ");
Serial.println(h);
Serial.print("Temperature: ");
Serial.println(t);
Serial.print("A0: ");
Serial.println(analogRead (A0));
Serial.print("Rzero: ");
Serial.println(rzero);
Serial.print("Rzeroc: ");
Serial.println(rzeroc);
Serial.print("PPM: ");
Serial.println(ppm);
Serial.print("PPMC: ");
Serial.println(ppmc);
}
void setupWifi() {
delay(10);
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect(mqtt_clientId, mqtt_user, mqtt_password)) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
unsigned long currentMillis = millis();
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)){
return;
}
float rzero = gasSensor.getRZero();
float ppm = gasSensor.getPPM();
float rzeroc = gasSensor.getCorrectedRZero(t, h);
float ppmc = gasSensor.getCorrectedPPM(t, h);
if (currentMillis - lastSampleTime >= sampleDelay) {
lastSampleTime = currentMillis;
if (isnan(t)) {
Serial.println("Error reading temperature!");
}
else {
client.publish(temperature_topic, String(t).c_str(), true);
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
}
// Get humidity event and print its value.
if (isnan(h)) {
Serial.println("Error reading humidity!");
}
else {
client.publish(humidity_topic, String(h).c_str(), true);
Serial.print("Humidity: ");
Serial.print(h);
Serial.println("%");
}
client.publish(co2_topic, String(ppm).c_str(), true);
Serial.print("CO2: ");
Serial.print(ppm);
Serial.println("ppm");
Serial.print("Light: ");
}
timer.run();
}
Kód: Vybrat vše
/**************************************************************************/
/*!
@file MQ135.h
@author G.Krocker (Mad Frog Labs)
@license GNU GPLv3
First version of an Arduino Library for the MQ135 gas sensor
TODO: Review the correction factor calculation. This currently relies on
the datasheet but the information there seems to be wrong.
@section HISTORY
v1.0 - First release
*/
/**************************************************************************/
#ifndef MQ135_H
#define MQ135_H
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
/// The load resistance on the board
#define RLOAD 10.0
/// Calibration resistance at atmospheric CO2 level
#define RZERO 263
/// Parameters for calculating ppm of CO2 from sensor resistance
#define PARA 116.6020682
#define PARB 2.769034857
/// Parameters to model temperature and humidity dependence
#define CORA 0.00035
#define CORB 0.02718
#define CORC 1.39538
#define CORD 0.0018
/// Atmospheric CO2 level for calibration purposes
#define ATMOCO2 397.13
class MQ135 {
private:
uint8_t _pin;
public:
MQ135(uint8_t pin);
float getCorrectionFactor(float t, float h);
float getResistance();
float getCorrectedResistance(float t, float h);
float getPPM();
float getCorrectedPPM(float t, float h);
float getRZero();
float getCorrectedRZero(float t, float h);
};
#endif