Smart Home diy-Air quality inspection-get air pollution index

Source: Internet
Author: User

Objective

The landlord finally upgraded when the father, the baby is now 5 months, the baby was born in the winter, it is the devil is the air pollution serious time, then want to make an automatic open air purifier, because of various reasons have no time to make, recently finally idle down this thing finally put on the agenda, now is summer, air is OK, All kinds of air quality related electronic products are discounted, it is a good time to do.

The main features of the program are:
    1. Automatic detection of air quality (PM2.5,PM10)
    2. Automatic detection of temperature, humidity, air pressure
    3. Regularly upload air quality data to the server and display it via the mobile app
    4. When the air quality is poor, automatically open the air purifier and alarm to close the window
    5. Automatically shuts down the air purifier when the air quality has been purified.

Architecture

Plans to use the Ardunio to connect air quality sensors, temperature, humidity, barometric pressure sensors, via the WiFi module via HTTP upload to the server backend, the server using the. NET MVC architecture. The app uses the interface provided by the website to get the data and display

The hardware you plan to use is:

Ardunio Mini Pro

Climbing Vine G5 Air quality sensor

Relays

Temperature and humidity sensor

Barometric pressure sensor

WiFi module

Power Module

Some friends may ask why with Ardunio Pro Mini, there are two main reasons, one cheap, one performance enough.

Air quality sensors the reason for using climbing vine is that the sensor market feedback performance is good, after testing really good performance, the other is now buy cheap:-)

Why the power supply module to use two reason is that some sensors use 3.3v voltage, some sensors use 5v voltage, plan to use AC to 5v module to obtain 5V point, and then 5v electricity and then a buck module to get 3.3v power

I will use a series of articles to record my this DIY, interested friends can add me buckle-1942916494, we discuss together.

Get Air Pollution index hardware connection

First connect the Vine G5 sensor and the Ardunio, as long as the 3 lines, VCC,GND, the G5 of the climbing the TX line to Ardunio D8 Port

Note that the Ivy's VCC and GND are purple and yellow, not red and black.

The VCC and GND of the vine are purple and yellow, not red and black.

The VCC and GND of the vine are purple and yellow, not red and black.

Important Words three times, The Ivy's TX is a green line, the green wire connection D8, theoretically can be connected to any digital port, but do not pick 4, 5, because the Arduino i²c is through this two digital interface, many of our sensors are using I²C to communicate with Ardunio, So don't take two of these mouths.

Connect your computer

Ardunio Mini Pro requires FTDI-232 connection to PC, Wired Ardunio vcc-ftdi VCC, Ardunio gnd-ftdi gnd, Ardunio tx-ftdi Rx, Ardunio rx-ftdi TX, Ardunio Rst-ftdi rst

If you have already used the buck module to connect the Ardunio power supply, do not connect VCC and GND, if you have already used the buck module to connect the Ardunio power supply, do not connect VCC and GND, if you have used a buck module connected to the Ardunio power supply, do not connect VCC and GND

After the connection, the FTDI connected to the computer's USB, if the first connection will install the driver, installed, will be virtual out of a COM port

Mine is COM5.

Writing code

Write code using the official IDE: Https://www.arduino.cc/en/Main/Software

Can download the green version, decompression can be used

After opening the interface is like this

Point Tool, Development Board Select Ardunio Mini or Ardunio Mini Pro, Port select virtual out of that COM port.

Create a new file, copy the following code into the Ardunio IDE

#include <softwareserial.h>softwareserial pm25serial (8, 9);  RX, txstruct _panteng {unsigned char len[2];  unsigned char pm1_cf1[2];  unsigned char pm2_5_cf1[2];  unsigned char pm10_0_cf1[2];  unsigned char pm1_0[2];  unsigned char pm2_5[2];  unsigned char pm10_0[2]; unsigned char d[20];} Panteng;float Caiqarr[8] = {0,50,100,150,200,300,400,500};float Cpm10arr[8] = {0,50,150,250,350,420,500,600};float Cpm25arr[8] = {0,35,75,115,150,250,350,500};int Caculateaiq (float * aiqarr, float * contaminatarr,int val, int size) {in  t findidx = 1;  for (int i=findidx;i<size;i++,findidx++) {if (Contaminatarr[i] >= val) break;    } if (findidx >= size) return (int) aiqarr[size-1]; float Aiq = (aiqarr[findidx]-aiqarr[findidx-1])/(Contaminatarr[findidx]-contaminatarr[findidx-1]) * (Val-contam    INATARR[FINDIDX-1]) + aiqarr[findidx-1]; return (int) Aiq;}        void Setup () {//Put your setup code here, to run Once:Serial.begin (9600); USB serial port sends data to PC pM25serial.begin (9600);    Soft serial Connection Sensor Pinmode (, OUTPUT),//built-in LED Digitalwrite (high);    Delay (1000);     Digitalwrite (, low);      Delay (1000);       Digitalwrite (high);    Delay (1000); Digitalwrite (, low);  }void Loop () {//Put your main code here, to run repeatedly:unsigned Char C;  Char str[100];  static int state = 0;  static int count = 0;  static int time = 0;        int Pm1_0, pm2_5, Pm10_0;  PM1.0, PM2.5, PM10 int i;    while (Pm25serial.available ()) {c = Pm25serial.read ();    Say what got://serial.print ("I Received:");    Serial.println (c, DEC);    Serial.println ("read");         Switch (state) {case 0:if (0x42 = = c) {digitalwrite (+);//start reading the light state = 1;      } break;          Case 1:if (0x4d = = c) {state = 2;          Count = 0;        Serial.println (");      } break;        Case 2: ((unsigned char *) &panteng) [count++] = c; sprintf (str, "%02x", c);          if (Count >) {state = 0;          PM1_0 = panteng.pm1_0[0] * + panteng.pm1_0[1];          Pm2_5 = panteng.pm2_5[0] * + panteng.pm2_5[1];          Pm10_0 = panteng.pm10_0[0] * + panteng.pm10_0[1];          int Pm25aiq = Caculateaiq (caiqarr,cpm25arr,pm2_5,8);          int Pm10aiq = Caculateaiq (caiqarr,cpm10arr,pm10_0,8);          sprintf (str, "%d\t%d\t%d\t%d\t%d\t%d", time++, Pm1_0, Pm2_5, Pm10_0, Pm25aiq, Pm10aiq);          Serial.println (str);          snprintf (str, +, "pm2.5=%d", pm2_5); Digitalwrite (, low);      End read Lights out} break;    Default:break; }  }}

  

Click Upload, the IDE will automatically compile and upload the code to Ardunio.

After uploading, click on the tool, serial monitor, in the pop-up window can see the current air quality

Forcibly inserting a hard ad

http://www.51bilin.com/, Billy Cattle Aggregation network discount, for your online shopping save money, automatic collection of the current major e-commerce most preferential activities, shopping before searching, help you save money, provide chrome plugin, Android client, iOS client is coming soon.

Smart Home diy-Air quality inspection-get air pollution index

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.