2016年12月28日 星期三

Blynk + pm2.5空氣品質 + DH11 溫度 濕度 感測器

Blynk + pm2.5空氣品質 + DH11 溫度 濕度 感測器


目的:

使用ESP8266  ESP-12 Tools Board 類比輸入A0來讀取PM2.5感測器的電壓值,轉換成PM2.5 之值,GPIO16 讀取DHT11溫度溼度感測器


硬體 (電子元件):

1)麵包板 x 1
2)ESP8266  ESP-12 Tools Board 主板 x 1
3)DHT11 x1 溫度溼度感測器
4)SHARP 原裝夏普 GP2Y1010AU0F PM2.5感測器 x1

5) 3.3V/5V Linear Regulator Voltage x1

6) 220uf  150歐姆


軟體: 

1)Arduino IDE 1.6.5版本
2) DHT.zip
3) Blynk
4) Android 手機安裝Blynk 軟體  App程式
5) 留意  ESP8266  ESP-12 Tools Board --uploading 接線
6) Arduino IDE  ESP8266 board from Tools > Board > Generic ESP8266 Module

  http://www.whatimade.today/esp8266-easiest-way-to-program-so-far/





















/*
=================================================================
Connect the USB-TTL to pc and upload sketch to ESP-12
Note: GPIO0 should be LOW 
      CH_PD and RST should be HIGH for first time flashing the board

GPIO0 should be LOW when uploading sketches
Remember use a 3.3V USB-TTL 
connect RX of board to TX of usb and TX of board to RX
SKETCH: 
edit auth code, ssid and pass 
================================================================= 
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <dht.h>   
#define dht_dpin 16  //定義DHT11訊號要從GPIO16進來  
dht DHT;   
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int measurePin = A0; // ADC  Connect dust sensor to Arduino A0 pin 
int ledPower = 14;   //Connect 3 led driver pins of dust sensor to Arduino D2
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
long updateInterval = 250;               //傳送資料時間間隔)
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "605989b5204247989352d86301a4c4e9";    //Blynk Auth Token : 605989b5204247989352d86301a4c4e9
char ssid[] = "74170287";
char pass[] = "24063173";

void setup() {
  Serial.begin(9600); //Set console baud rate
  pinMode(ledPower,OUTPUT);
  pinMode(dht_dpin,OUTPUT);
  Blynk.begin(auth, ssid, pass);   // auth, ssid, pass ;
  }

void loop() {
  Blynk.run();

  digitalWrite(ledPower,LOW); // power on the LED
  delayMicroseconds(samplingTime);
  voMeasured = analogRead(measurePin); // read the dust value
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(sleepTime);
  // 0 - 5V mapped to 0 - 1023 integer values
  // recover voltage
  calcVoltage = voMeasured *  (3.3 / 1024.0);    //5V change into 3,3V
  // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
  // Chris Nafis (c) 2012
  if (calcVoltage < 0.583) {
       dustDensity = 0;
       }
   else{
        dustDensity = 6 * calcVoltage / 35 - 0.1;
         }
   Serial.print("Raw Signal Value (0-1023): ");
   Serial.print(voMeasured);
   Serial.print(" - Voltage: ");
   Serial.print(calcVoltage);
   Serial.print(" - Dust Density: ");
   Serial.print(dustDensity * 1000); // 這裡將數值呈現改成較常用的單位( ug/m3 )
   Serial.println(" ug/m3 ");
   float T=dustDensity * 1000 ;
  
  Blynk.virtualWrite(V0, voMeasured);   
  Blynk.virtualWrite(V1, calcVoltage);   
  Blynk.virtualWrite(V2, T);

//++++++++++++++++++++++++++++++++++++++++++++++
  DHT.read11(dht_dpin);   //去library裡面找DHT.read11  
  float h = DHT.humidity;
  float t = DHT.temperature;
  float f = t * 9/5 + 32;
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
    }
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print("%\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print("*C\t");
  Serial.print(f);
  Serial.print("*F\n");

  Blynk.virtualWrite(V3, h);   
  Blynk.virtualWrite(V4, t);

//++++++++++++++++++++++++++++++++++++++++++++++
   
}

沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...