Jump to content
Automate Life
Larry Underwood

Indoor Air Quality Sensor

Recommended Posts

I created this project for 2 reasons, the main one was that my allergies were really bad this year, I heard that this season has been the worst for them. The second is after looking for a IoT device that I could integrate into my smartthings automation system I found few of them could and the prices for the ones that could were in the hundreds of dollars.

So this project was born.

I have built a Indoor Air Quality sensor. This IoT device can monitor IAQ (Indoor Air Quality), Temperature, Humidity and I also have it monitoring the voltage of the battery it run's off of.

This is not the finial version. I still need to make some mods on the 3D printed case but all the other parts are as I want them.

Here is a picture of the unit. It's a lot smaller then it looks in the picture only measures about 3 1/4 inches by 2 inches

20200412_104013.thumb.jpg.64d0c082a642eebf8f7ef25b057dba52.jpg

The switch (turns the unit on and off) you see inside the box will be mounted so it can be turned off through a hole in the side of the case of the next version.

The Main board is a D1 mini pro Version 2. It has 4 wires going from it to the sensor. The sensor is a BME680 sensor. The battery is a 18650 3.7 volt rechargeable battery.

 

Here is a screen shot on my phone screen. This is the app i use to see all the readings

939848003_Screenshot_20200412-104026_OneUIHome.thumb.jpg.76b1bea4fced08b764156ec4f1a9a217.jpg

The app is called IoT Thingspeak Monitor Widget. It is free on the andriod store. As you can see it can monitor all the values of the sensor. Updates automatically.

The website i have my Arduino sketch (program that runs on the D1 mini pro) reporting the sensor values to is called Thingspeak. Here is a screenshot of that.

540866080_ThingSpeakIAQSensorPNG.thumb.PNG.7c314dfca1c14c9a2e8c6d7432ce4c95.PNG

Using the thingspeaks websites app option i can set it so that it sends a http post to webCoRE so when the Indoor air quality gets to high for example it can run a webCoRE piston that turns on a smarthings WiFi switch that is connected to my Air Purifier. After the reading go's down it turn's off the air purifier. Also have it turn my humidifier on and off when needed. And the same for when the battery in the device needs to be recharged. The D1 mini pro V2 has a built in battery charging circuit.

The battery, D1 mini pro V2, BME680 sensor and the switch cost me around 30 dollars US. The 3D printed case was printed free of charge for me by a friend if i would make him one of these (he bought the parts).

This has helped my allergy's a great deal. I even use it to turn my ceiling fan on/off when the temp gets to high.and when I'm in the room.

If anyone wants to build this for themselves let me know and i can go into more detail on where to buy the parts, i can also share my arduino sketch as well.

If anyone has any questions about this project let me know.

 

Edited by Larry Underwood

Share this post


Link to post
Share on other sites

Hey Larry!  I'm putting together a little video of projects Automaters are taking on during this time.  I think I have a ton here, but I'd love the parts source for sure.  Can I feature it???

Share this post


Link to post
Share on other sites

 

4 hours ago, AYL_Brian said:

Hey Larry!  I'm putting together a little video of projects Automaters are taking on during this time.  I think I have a ton here, but I'd love the parts source for sure.  Can I feature it???

Sure no problem. Here is the parts list

$5.00   --  D1 mini pro V2.0.0  ---  https://www.aliexpress.com/item/32724692514.html        

$10.54  -- BME680 Sensor -- https://www.aliexpress.com/item/33031493434.html

$4.99  --  18650 Battery  --  https://www.aliexpress.com/item/32839709993.html

$7.39  --  On/Off Micro Switch  --  https://www.amazon.com/gp/product/B075RC6TFB/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1

$2.29  --  JST PH 2.0MM 2 Pin Female Single Connector  --  https://www.amazon.com/gp/product/B07F2YC6YJ/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1

---------- 

$30.21  <-- Total

 

And no I don't have any problems with you featuring it.

Except for the 3D printed box that was it. Took me a while to get the Arduino sketch created and working like i wanted it to. At first i had a display on it but took to much power to run it. Like the Thingspeak option better anyway.

If you need any further information about it let me know.

 

 

Edited by Larry Underwood

Share this post


Link to post
Share on other sites

Here are some updated pics of the Air Quality Sensor Project. This is the final version. Got the mods for the case to my friend and he printed this new one for me. As you can see the On/Off switch is now mounted and you can turn it on and off with the switch from the outside. The very small M1.5 screws came in as well and have mounted the board with 3 screws to the mounting post inside the box. Made the hole bigger where you plug in the power to charge the unit so any USB cable will fit. Finally made the slot between the main compartment and the sensor compartment deeper so the wires between the main board and the sensor fit better.

Here are the pictures

20200415_163051.thumb.jpg.9284f3ca34da0e06fc51aa2ebe7264b8.jpg

20200415_163105.thumb.jpg.211820cfb8441232b963c72f918c001e.jpg

20200415_163115.thumb.jpg.06323f41a4c4d60b1c9fba6752237772.jpg

20200415_163133.thumb.jpg.ab9d205537f8e8731c54ad4fd2f8e35b.jpg

Any questions or comments about the project please leave them here.

Edited by Larry Underwood

Share this post


Link to post
Share on other sites
On 4/12/2020 at 2:45 PM, AYL_Brian said:

Hey Larry!  I'm putting together a little video of projects Automaters are taking on during this time.  I think I have a ton here, but I'd love the parts source for sure.  Can I feature it???

Brian when you post the video if it's not on your YouTube channel can you please leave the link to where it is. I'd like to see that one.

Edited by Larry Underwood

Share this post


Link to post
Share on other sites
On 4/15/2020 at 3:58 PM, Larry Underwood said:

Brian when you post the video if it's not on your YouTube channel can you please leave the link to where it is. I'd like to see that one.

It'll be on the main channel!  I am just gathering a few extra projects after this one and we should be good to go!  Thank you so much Larry!  This is amazing.

  • Thanks 1

Share this post


Link to post
Share on other sites

Made a couple more changes on the software side of this to extend battery life. The battery level is now shown in percent instead of Volts and the unit now go's into deep sleep mode for 10 minutes which turns off everything except the Real time clock. So processor, WiFi, sensor are all shut down. It's only running for about 20 seconds out of every 10 minutes. This makes the battery last for about 69 days between charges.

2039391765_thingspeakV2.thumb.PNG.083716fed0671dd7b3a63bbbafbbb361.PNG 

Share this post


Link to post
Share on other sites

Made a few changes to the software. Now when the battery voltage go's below 3.3 volts it will automatically send me a text message on my phone that the battery needs charging and it will automatically increase it's time between sensor reads to 1 hour instead of every 10 minutes. This will make the battery last longer until i can charge the battery.

If you want to see the sensor readings in real time check out this link. Updates every 10 minutes. Show's Temperature, Indoor Air Quality, Humidity, and Battery Level of the IoT device.

https://thingspeak.com/channels/1013680

 

Edited by Larry Underwood

Share this post


Link to post
Share on other sites
On 8/8/2020 at 1:56 AM, Gelo said:

Would you please provide more info about soft?

To program the D1 mini I use a program called Arduino IDE it's free to download here. https://www.arduino.cc/en/main/software

I made my own code and that's the code below.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <SPI.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>

unsigned int raw=0;

// Time to sleep (in seconds):
int sleepTimeS = 600;

const char* ssid = "YourSSID";
const char* password = "YourPassword";

const char* server = "api.thingspeak.com";
const char* api_key = "YourThingSpeakAPIKey";

// Optional - you can define air pressure correction for your altitude
#define ALT_CORRECTION 3144

SoftwareSerial mySerial(D6, D5);
uint16_t temp1=0;
int16_t temp2=0;

unsigned char Re_buf[30],counter=0;
unsigned char sign=0;
int led = 13;
int Precent = 0;

WiFiClient client;

unsigned long prev = millis();

void setup()
{
  Serial.begin(115200);
  delay(1000);
   
  //---------------------------------
  Serial.println("Connecting to wifi...");
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED){
    delay(150);
    if(millis() > 30000) {
      Serial.println("Could Not Connect to WiFi Sleeping For 10");
      ESP.deepSleep(sleepTimeS * 1000000);
    }
  }
  Serial.println("WiFi connected");
  Serial.println(WiFi.localIP());
  //---------------------------------
  // put your setup code here, to run once:
   
  mySerial.begin(9600);
  mySerial.listen();  
  delay(5000);    
 
  mySerial.write(0XA5);
  mySerial.write(0X55);    
  mySerial.write(0X3F);    
  mySerial.write(0X39);
  delay(100);

  mySerial.write(0XA5);
  mySerial.write(0X56);    
  mySerial.write(0X02);    
  mySerial.write(0XFD);
  Serial.println("Setup complete");

  delay(100);  
}

void loop(){

  float volt=0.0;
    
  pinMode(A0, INPUT);
  raw = analogRead(A0);
  volt=raw/1023.0;
  volt=volt*4.35;
  Precent=raw/1023.0*100;
 
  float Temperature ,Humidity;
  unsigned char i=0,sum=0;
  uint32_t Gas;
  uint32_t Pressure;
  uint16_t IAQ;
  int16_t  Altitude;
  uint8_t IAQ_accuracy;
 
  //Serial.println("Checking serial...");
  while (mySerial.available()) {
    //Serial.println("mySerial available");   
    Re_buf[counter]=(unsigned char)mySerial.read();
    
    if(counter==0&&Re_buf[0]!=0x5A) {
      Serial.println("Sensor not reporting in. Going to sleep for 30 seconds");
      sleepTimeS = 30;
      ESP.deepSleep(sleepTimeS * 1000000);
        }         
    if(counter==1&&Re_buf[1]!=0x5A)
  {
    counter=0;
     return;
   };           
    counter++;       
    if(counter==20)               
    {    
       counter=0;                  
       sign=1;
    }      
  }
  if(sign)
  {  
    sign=0;
    if(Re_buf[0]==0x5A&&Re_buf[1]==0x5A )        
     {      
       for(i=0;i<19;i++)
         sum+=Re_buf;
       if(sum==Re_buf )
         {
           temp2=(Re_buf[4]<<8|Re_buf[5]);   
           Temperature=(float)temp2/100;
           temp1=(Re_buf[6]<<8|Re_buf[7]);
           Humidity=(float)temp1/100;
           Pressure=((uint32_t)Re_buf[8]<<16)|((uint16_t)Re_buf[9]<<8)|Re_buf[10];
           float altPressure=(float(Pressure)+ALT_CORRECTION)/100;
           IAQ_accuracy= (Re_buf[11]&0xf0)>>4;
           IAQ=((Re_buf[11]&0x0F)<<8)|Re_buf[12];
           Gas=((uint32_t)Re_buf[13]<<24)|((uint32_t)Re_buf[14]<<16)|((uint16_t)Re_buf[15]<<8)|Re_buf[16];
           Altitude=(Re_buf[17]<<8)|Re_buf[18];
           Serial.print("Temperature:");
           Serial.print(Temperature * 9 / 5 + 30);
           Serial.print(" ,Humidity:");
           Serial.print(Humidity);
           Serial.print(" ,Pressure:");
           Serial.print(Pressure);
           Serial.print("|");
           Serial.print(altPressure);      
           Serial.print("  ,IAQ:");
           Serial.print(IAQ);
           Serial.print(" ,Gas:");
           Serial.print(Gas);
           Serial.print("  ,Altitude:");
           Serial.print(Altitude);
           Serial.print("  ,Battery:");
           Serial.print(Precent);                       
           Serial.print("  ,IAQ_accuracy:");
           Serial.println(IAQ_accuracy);
                     
             
             postData(Temperature,Humidity,volt,altPressure,IAQ,Precent,IAQ_accuracy);
             if(volt < 3.33) {
             sleepTimeS = 3600;
           }
             //Sleep
            Serial.println("ESP8266 in sleep mode");
            ESP.deepSleep(sleepTimeS * 1000000);
         }            
         delay(1000);           
     }
  }
}

void postData(int temperature, int humidity, float altPressure, int volt, int iaq, int Precent, int iaq_accuracy){
  digitalWrite(LED_BUILTIN, HIGH);
 
  // Send data to ThingSpeak
  if (client.connect(server,80)) {
  Serial.println("Connect to ThingSpeak - OK");

  String dataToThingSpeak = "";
  dataToThingSpeak+="GET /update?api_key=";
  dataToThingSpeak+=api_key;
   
  dataToThingSpeak+="&field1=";
  dataToThingSpeak+=String(temperature * 9 / 5 + 32);

  dataToThingSpeak+="&field2=";
  dataToThingSpeak+=String(humidity);

  dataToThingSpeak+="&field3=";
  dataToThingSpeak+=String(altPressure);

  dataToThingSpeak+="&field4=";
  dataToThingSpeak+=String(iaq);

  dataToThingSpeak+="&field5=";
  dataToThingSpeak+=String(Precent);

  dataToThingSpeak+="&field6=";
  dataToThingSpeak+=String(iaq_accuracy);

  dataToThingSpeak+="&field7=";
  dataToThingSpeak+=String(volt);
 
  dataToThingSpeak+=" HTTP/1.1\r\nHost: a.c.d\r\nConnection: close\r\n\r\n";
  dataToThingSpeak+="";
  client.print(dataToThingSpeak);

  int timeout = millis() + 5000;
  while (client.available() == 0) {
    if (timeout - millis() < 0) {
      Serial.println("Error: Client Timeout Going to Sleep for 30 seconds!");
      client.stop();
      sleepTimeS = 30;
      ESP.deepSleep(sleepTimeS * 1000000);
      return;
      }
    }
  }
  while(client.available()){
    String line = client.readStringUntil('\r');
    //Serial.print(line);
  }
  digitalWrite(LED_BUILTIN, HIGH);
}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Just copy ever thing between the dotted lines into arduino IDE change the SSID and Password and Thingspeak IDE keys.

If you have any more questions just let me know. their is a learning curve to get this working but once you do a lot of normally expensive devices become very cheap to make for yourself.

 

Edited by Larry Underwood

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...