ESP8266 Air quality sensor

Everything about esp8266 and more.
User avatar
Corvax
Posts: 2
Joined: Friday 24 June 2016 20:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

ESP8266 Air quality sensor

Post by Corvax » Friday 24 June 2016 20:40

Hi,

I have "made" an air quality sensor by using a MH-Z19 module bought on Aliexpress for around 25 USD and a ESP8266 201 board.

Sensor
http://www.aliexpress.com/wholesale?cat ... ext=MH-z19

The code is updating a dummy air quality sensor around every 30 seconds.


The software is a mashup from different sources...and some written by me.......probably some room for some more tweaking.....

Code: Select all


#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <SoftwareSerial.h>
const char* ssid     = "YourSSID";  
const char* password = "YourPassword";
const char* idx      = "300";				//IDX of dummy air quality sensor
const char* host     = "192.168.1.40"; //     	//IP Address of domoticz server

SoftwareSerial mySerial(12, 13); // RX, TX


void(* resetFunc) (void) = 0; //declare reset function @ address 0


void setup() {

      
   Serial.begin(115200);

    mySerial.begin(9600);       //C02 sensor read serial


 
  delay(1000);
  
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);
  int wifi_ctr = 0;
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("WiFi connected");  
  Serial.println("IP address: " + WiFi.localIP());

}

void loop() {
      
  Serial.print("connecting to ");
  Serial.println(host);
  
  WiFiClient client;
  const int httpPort = 8080;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");

    Serial.println("Reset everything");
   ESP.reset();
    return;
  }

  int ppm = readCO2();

   delay(1000);
  bool dataError = false;
  Serial.println("  PPM = " + String(ppm));

  if (ppm < 100 || ppm > 6000)
  {
    Serial.println("PPM not valid");

    return;         //start over again
  }

  delay(1000);

  

  client.print(String("GET ") + "/json.htm?type=command&param=udevice&idx=" + idx + "&nvalue=" + ppm + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" + 
               "Connection: close\r\n\r\n");

  delay(1000); // wait for server to respond

  // read response

  String section="header";

  while(client.available()){
    
    String line = client.readStringUntil('\r');
    Serial.print(line);


 if (section=="header") { // headers..
      Serial.print(".");
      if (line=="\n") { // skips the empty space at the beginning 
        section="json";
      }
    }
    else if (section=="json") {  // print the good stuff
      section="ignore";
      String result = line.substring(1);

      // Parse JSON
      int size = result.length() + 1;
      char json[size];
      result.toCharArray(json, size);
      StaticJsonBuffer<200> jsonBuffer;
      JsonObject& json_parsed = jsonBuffer.parseObject(json);
      if (!json_parsed.success())
      {
        Serial.println("parseObject() failed");
        return;
      }
       if (strcmp(json_parsed["status"], "OK") == 0) {
        Serial.println("Returned OK");
       
      }
      else if (strcmp(json_parsed["status"], "ERR") == 0){
                Serial.println("Returned ERR or");
      }
      else{
                Serial.println("Not working at all");
      }

  }


  }
   
  Serial.println("closing connection");
  client.stop();
  delay(20000);
  
}

int readCO2()
{

  byte cmd[9] = {0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
  // command to ask for data
  char response[9]; // for answer

  mySerial.write(cmd, 9); //request PPM CO2
  mySerial.readBytes(response, 9);
  if (response[0] != 0xFF)
  {
    Serial.println("Wrong starting byte from co2 sensor!");
    return -1;
  }

  if (response[1] != 0x86)
  {
    Serial.println("Wrong command from co2 sensor!");
    return -1;
  }

  int responseHigh = (int) response[2];
  int responseLow = (int) response[3];
  int ppm = (256 * responseHigh) + responseLow;
  return ppm;
}



User avatar
Derik
Posts: 2115
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: ESP8266 Air quality sensor

Post by Derik » Friday 24 June 2016 22:57

a printscreen from Domoticz?
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups

User avatar
gizmocuz
Posts: 8649
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi
Domoticz version: beta
Location: Top of the world
Contact:

Re: ESP8266 Air quality sensor

Post by gizmocuz » Sunday 26 June 2016 13:10

Great job!
But its an expensive sensor ;)
Quality outlives Quantity!

User avatar
sincze
Posts: 940
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: ESP8266 Air quality sensor

Post by sincze » Sunday 26 June 2016 13:43

Great coding.
However I agree, it must be able to achieve this under $5 :D
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

User avatar
Corvax
Posts: 2
Joined: Friday 24 June 2016 20:16
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: ESP8266 Air quality sensor

Post by Corvax » Monday 27 June 2016 17:43

Derik wrote:a printscreen from Domoticz?
Hi, I see attached devices setup and a chart.

regards
Devices.png
Devices.png (140.5 KiB) Viewed 9154 times
Co2 sensor.jpeg
Co2 sensor.jpeg (48.3 KiB) Viewed 9154 times

User avatar
ThinkPad
Posts: 1754
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: ESP8266 Air quality sensor

Post by ThinkPad » Saturday 13 August 2016 21:59

How accurate is this sensor compared to something like a more expensive sensor like a SenseAir K30 ? Any idea?
And what about calibration? Does it need calibration?
ThinkTheme - theme for Domoticz
My (Dutch) blog: http://thinkpad.tweakblogs.net - My Domoticz scripts: Bitbucket
I'm not (very) active anymore on this forum as i don't use Domoticz anymore.

madrian
Posts: 239
Joined: Saturday 27 August 2016 1:18
Target OS: -
Domoticz version:
Contact:

Re: ESP8266 Air quality sensor

Post by madrian » Sunday 04 September 2016 22:04


User avatar
ThinkPad
Posts: 1754
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: ESP8266 Air quality sensor

Post by ThinkPad » Monday 05 September 2016 7:28

MQ135 sucks if i have to believe blogs online. Really hard to get a trustworthy result.
MH-Z19 is most valueable option for now, good price and readings seem to be accurate.
ThinkTheme - theme for Domoticz
My (Dutch) blog: http://thinkpad.tweakblogs.net - My Domoticz scripts: Bitbucket
I'm not (very) active anymore on this forum as i don't use Domoticz anymore.

nixalsschrott
Posts: 39
Joined: Tuesday 11 July 2017 10:26
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Germany
Contact:

Re: ESP8266 Air quality sensor

Post by nixalsschrott » Monday 14 August 2017 11:39

As I understand, you are using WIFI only, right?
Is there any option to build this CO2 sensor with z-wave plus compatibility to integrate into z-wave plus meshed network?
Perhaps also with temperature and humidity reporting?

Kind regards
matty
Domoticz Beta v3.9317 for DSM 6.1 | Aeon Labs Z-Wave USB Stick | Cyrus SmartHome 4-in-1 Multisensor | Qubino ZMNHCD1 - Roller Shutter | NEO COOLCAM NAS-WR01ZE Power Plug | WEMOS D1 MINI (ESP8266) Sensors CO2/TEMP/BARO | Denon AVR

randytsuch
Posts: 98
Joined: Sunday 20 March 2016 19:56
Target OS: Raspberry Pi
Domoticz version: Beta
Location: LA, Ca USA
Contact:

Re: ESP8266 Air quality sensor

Post by randytsuch » Monday 14 August 2017 16:45

nixalsschrott wrote:
Monday 14 August 2017 11:39
As I understand, you are using WIFI only, right?
Is there any option to build this CO2 sensor with z-wave plus compatibility to integrate into z-wave plus meshed network?
Perhaps also with temperature and humidity reporting?

Kind regards
matty
zwave is a proprietary interface, you have to pay a large license fee to use it, so really no DIY options with zwave.
ESP's use the wifi network you already have, they are really nice, inexpensive little boards

Randy

woodtrix
Posts: 37
Joined: Saturday 18 February 2017 18:54
Target OS: -
Domoticz version:
Contact:

Re: ESP8266 Air quality sensor

Post by woodtrix » Tuesday 15 August 2017 3:42

I currently using a couple of vlads co2 monitors

http://vair-monitor.com

and quite happy with it... he offers various co2 sensors (also sells the individual chips for diy) options include dustsensors humiditybetc, the works...

the dude building them is also on this forum.

manjh
Posts: 334
Joined: Saturday 27 February 2016 13:49
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: NL
Contact:

Re: ESP8266 Air quality sensor

Post by manjh » Friday 18 August 2017 9:55

I am using a Senseair S8 coupled to an ESP unit, and can see the values coming into Domoticz when I use a "user defined" sensor device. But when I link it to an "Air quality" device, values stay zero. What is wrong?
Hans

Toulon7559
Posts: 451
Joined: Sunday 23 February 2014 18:56
Target OS: Raspberry Pi
Domoticz version: latest
Location: Hengelo(Ov)/NL
Contact:

Re: ESP8266 Air quality sensor

Post by Toulon7559 » Tuesday 22 August 2017 12:57

Could this reasonably priced dust-measuring device be meaningful for a DIY-realisation for measuring air-quality?
Set1 = RPI-B+RFXCom433+S0PCM+Linksprite-shield for BMP180/DS18B20/RS485+DDS238ZN1
Set2 = RPI-3+RFLinkGTW+ESP8266s+PWS_WS7000
Common = 2*PVLogger+PWS_TFA_Nexus+KAKUs
=> Energy & Data Management based on Time and on PV&Consumption&Meteo

manjh
Posts: 334
Joined: Saturday 27 February 2016 13:49
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: NL
Contact:

Re: ESP8266 Air quality sensor

Post by manjh » Tuesday 22 August 2017 13:31

Toulon7559 wrote:
Tuesday 22 August 2017 12:57
Could this reasonably priced dust-measuring device be meaningful for a DIY-realisation for measuring air-quality?
Air quality is determined by a number of things. The most important are CO2 percentage and dust.
Using a dust sensor alone does not cut it: you could have very clean air (in the sense of dust content) but a very high CO2 percentage.
I currently have a CO2 sensor running, but I have a dust sensor on order and will add that to the ESP as soon as I have it.
https://www.banggood.com/DIY-GP2Y1010AU ... mds=search
Hans

manjh
Posts: 334
Joined: Saturday 27 February 2016 13:49
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: NL
Contact:

Re: ESP8266 Air quality sensor

Post by manjh » Tuesday 22 August 2017 13:32

manjh wrote:
Friday 18 August 2017 9:55
I am using a Senseair S8 coupled to an ESP unit, and can see the values coming into Domoticz when I use a "user defined" sensor device. But when I link it to an "Air quality" device, values stay zero. What is wrong?
I solved it by using a json command in the rules section of ESPEasy. Not really a solution, but a good workaround.
Hans

User avatar
LouiS22
Posts: 482
Joined: Friday 27 February 2015 14:21
Target OS: Raspberry Pi
Domoticz version: beta
Location: Budapest, Hungary
Contact:

Re: ESP8266 Air quality sensor

Post by LouiS22 » Tuesday 22 August 2017 16:19

woodtrix wrote:
Tuesday 15 August 2017 3:42
I currently using a couple of vlads co2 monitors

http://vair-monitor.com

and quite happy with it... he offers various co2 sensors (also sells the individual chips for diy) options include dustsensors humiditybetc, the works...

the dude building them is also on this forum.
Sadly he recently stopped building and selling new devices (will continue it later).

woodtrix
Posts: 37
Joined: Saturday 18 February 2017 18:54
Target OS: -
Domoticz version:
Contact:

Re: ESP8266 Air quality sensor

Post by woodtrix » Wednesday 06 September 2017 21:10

Did any of ever thinking about how to expand this?

I hvae CO, CO2 and dust sensors all over (and of the course humidity and temperature) to monitor and control the ventilation system (& the vacuum robot, air purifier, heating)

But there are two areas in the air quality that I have not figured out yet...

I want to know the difference between nr 1 and nr 2, in a bathroom which has no windows,... so i was thinking a methane sensor (or something like that, that works... (no idea of any of the mq series works) placed at the bottom of the resevoir... ass to sensor is like 20-30 centimeters... and would be close enough to detect early...

(I already detect flushings, by using a flood sensor without the alarm beeb (broken off), and exploiting the internal flushing mechanism, such that when you flush the sensor makes contact, but it would be nice to be a little earlier with nr 2, and do nothing, or maybe a lower setting, when you have to piss

Second I want to know when cooking takes place so when one bake some sausages,the ventilation goes on, I could attach a humidity sensor (i would also like to detect things like burning a patato)

Do you guys have any thoughts or ideas on this?

Topcase1
Posts: 3
Joined: Sunday 29 October 2017 14:47
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Maassluis, Zuid-Holland
Contact:

Re: ESP8266 Air quality sensor

Post by Topcase1 » Sunday 29 October 2017 15:13

Omdat ik hier nieuw ben zeg ik Hallo tegen iedereen,

De luchtkwaliteitssensor gemaakt van een ESP8266 en een MH-Z19 staat mij wel aan.
Wat ik begrijp is dat je zo'n combinatie "stand alone" kunt gebruiken en koppelen via wifi aan mijn Raspberrypi waarop Domoticz staat?
Nu zag ik de afdruk van een CO2 grafiek en dat wil ik ook.
Maar op diezelfde afdruk zie ik als hardware de Volcraft co-20 in Domoticz staan.
Kan iemand mij uitleggen hoe dit zit? Is het zo dat als je de software inlaad vanzelf als hardware Volcraft in Domoticz hebt?

Alvast bedankt,

Topcase1

SweetPants
Posts: 2174
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.9895
Location: The Netherlands
Contact:

Re: ESP8266 Air quality sensor

Post by SweetPants » Sunday 29 October 2017 15:16

Topcase1 wrote:
Sunday 29 October 2017 15:13
Omdat ik hier nieuw ben zeg ik Hallo tegen iedereen,

De luchtkwaliteitssensor gemaakt van een ESP8266 en een MH-Z19 staat mij wel aan.
Wat ik begrijp is dat je zo'n combinatie "stand alone" kunt gebruiken en koppelen via wifi aan mijn Raspberrypi waarop Domoticz staat?
Nu zag ik de afdruk van een CO2 grafiek en dat wil ik ook.
Maar op diezelfde afdruk zie ik als hardware de Volcraft co-20 in Domoticz staan.
Kan iemand mij uitleggen hoe dit zit? Is het zo dat als je de software inlaad vanzelf als hardware Volcraft in Domoticz hebt?

Alvast bedankt,

Topcase1
English please!!
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

Topcase1
Posts: 3
Joined: Sunday 29 October 2017 14:47
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Maassluis, Zuid-Holland
Contact:

Re: ESP8266 Air quality sensor

Post by Topcase1 » Sunday 29 October 2017 15:23

Because I'm new here I say Hello to everyone,

The air quality sensor made of an ESP8266 and an MH-Z19 is true to me.
What I understand is that you can use and pair this combination of stand alone with Wi-Fi to my Raspberrypi on which Domoticz stands?
Now I saw the print of a CO2 chart, and I want that too.
But on the same print, I see hardware as the Volcraft co-20 in Domoticz.
Can anyone explain how this is? Is it that if you download the software by itself, if you have Volcraft in Domoticz?

Thanks in advance,

Topcase1

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests