Intelligent Home diy-Air quality inspection-get temperature and humidity Chapter

Source: Internet
Author: User

Directory

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

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 temperature and humidity

Temperature and humidity sensors use "aosong AM2320", the sensor is characterized by high progress, affordable

Hardware connection

AM2320 altogether has 4 interfaces, 1 Connect 5v power supply, 2 Ardunio a4,3 grounding wire, 4 Ardunio A5

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.

Download AM2320 Ardunio Support Library

Https://github.com/Ten04031977/AM2320-master

Import libraries into the Ardunio IDE

Ardunio IDE Click Project-Load library-add a zip library, select the downloaded zip file to

Writing code

Open the last file or create a new file and copy the following code into the Ardunio IDE

#include <Wire.h>#include<AM2320.h>#include<SoftwareSerial.h>softwareserial pm25serial (8,9);//RX, TXAM2320th;//Newstruct_panteng {unsignedCharlen[2]; unsignedCharpm1_cf1[2]; unsignedCharpm2_5_cf1[2]; unsignedCharpm10_0_cf1[2]; unsignedCharpm1_0[2]; unsignedCharpm2_5[2]; unsignedCharpm10_0[2]; unsignedChard[ -];} Panteng;floatcaiqarr[8]  = {0, -, -, Max, $, -, -, -};floatcpm10arr[8] = {0, -, Max, -, -,420, -, -};floatcpm25arr[8] = {0, *, the, the, Max, -, -, -};intCaculateaiq (float* Aiqarr,float* Contaminatarr,intVal,intsize) {  intFindidx =1;  for(inti=findidx;i<size;i++,findidx++)  {    if(Contaminatarr[i] >=val) Break; }  if(Findidx >=size)return(int) Aiqarr[size-1]; floatAiq = (Aiqarr[findidx]-aiqarr[findidx-1])/(Contaminatarr[findidx]-contaminatarr[findidx-1]) * (VAL-CONTAMINATARR[FINDIDX-1]) + AIQARR[FINDIDX-1]; return(int) Aiq;}voidSetup () {//Put your setup code here, to run once:Serial.begin (9600);//USB serial port sends data to PCPm25serial.begin (9600);//Soft serial Connection sensorPinmode ( -, OUTPUT);//built-in LEDDigitalwrite ( -, high); Delay ( +); Digitalwrite ( -, low); Delay ( +); Digitalwrite ( -, high); Delay ( +); Digitalwrite ( -, low); }voidLoop () {//put your main code here, to run repeatedly:unsignedCharC; Charstr[ -]; Static intState =0; Static intCount =0; Static intTime =0; intPm1_0, Pm2_5, Pm10_0;//PM1.0, PM2.5, PM10  inti;  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 ( -, high);//Start reading lightState =1; }         Break;  Case 1:        if(0x4d==c) { state=2; Count=0; //serial.println (");        }         Break;  Case 2: ((unsignedChar*) &panteng) [count++] =C; sprintf (str,"%02x", c); if(Count > -) { state=0; Pm1_0= panteng.pm1_0[0] * the+ panteng.pm1_0[1]; Pm2_5= panteng.pm2_5[0] * the+ panteng.pm2_5[1]; Pm10_0= panteng.pm10_0[0] * the+ panteng.pm10_0[1]; intPm25aiq = Caculateaiq (Caiqarr,cpm25arr,pm2_5,8); intPm10aiq = 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);
Newif(Th. Read () = =0) {Serial.print ("Humidity:"); Serial.print (TH.H); Serial.print ("%, temperature:"); Serial.print (TH.T); Serial.println ("*c"); } 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 and current temperature and humidity

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.

Intelligent Home diy-Air quality inspection-get temperature and humidity Chapter

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.