这是一篇论文,请尊重知识产权!
This is a paper, please abide by the Intellectual Property Law!
编写完成于于2017年6月,这样一份从硬件,客户端,再到服务端均为我一人开发的杰作,并且都包含了自己独特的设计和思想的毕业设计。
效果图
硬件端:Arduino
#include "DHT.h"
#include <LiquidCrystal_I2C.h>
#define DHTPIN 3
#define DHTTYPE DHT11
#define BEEP_PIN 7
#define PM_LED 2
#define PM_OUT A0
//Define
const int LCD_ADDRESS = 0x3f;
uint8_t degree[8] = {
0x2, 0x5, 0x2, 0x0, 0x0, 0x0, 0x0 };
uint8_t cube[8] = {
0B00000,0B11000,0B00100,0B01000,0B00100,0B11000,0B00000,0B00000 };
uint8_t down2[8] = {
0B00000,0B00000,0B00000,0B00000,0B11000,0B00100,0B01000,0B11100 };
const int DELAY = 1000;
float thresholds[6] = {
0,50,5,80,1,0.5};
// Initialize
LiquidCrystal_I2C lcd(LCD_ADDRESS, 16, 2);
DHT dht(DHTPIN, DHTTYPE);
float valCH20 = NAN;
float valTem = NAN;
float valHum = NAN;
float valPm2_5 = NAN;
bool allowPrintData = false;
void setup()
{
lcd.init();
lcd.backlight();
lcd.createChar(0, degree);
lcd.createChar(1, cube);
lcd.createChar(2, down2);
lcd.setCursor(2, 0);
lcd.print("* Welcome *");
lcd.setCursor(0, 1);
lcd.print("Initializing...");
tone(BEEP_PIN, 3500);
delay(1000);
tone(BEEP_PIN, 3000);
delay(1000);
noTone(BEEP_PIN);
Serial.begin(9600);
Serial2.begin(115200);
Serial3.begin(9600);
Serial2.setTimeout(1);
dht.begin();
pinMode(BEEP_PIN, OUTPUT);
pinMode(PM_OUT, INPUT);
pinMode(PM_LED, OUTPUT);
}
void loop()
{
requestThreshold();
resetData();
readTemAndHum();
readPm2_5();
readCH2O();
sendData();
delay(DELAY);
}
void resetData()
{
valCH20 = NAN;
valTem = NAN;
valHum = NAN;
valPm2_5 = NAN;
}
void readTemAndHum()
{
valHum = dht.readHumidity();
valTem = dht.readTemperature();
Serial.print("Temprature=");
Serial.print(valTem, 2);
Serial.print("\tHuminity=");
Serial.println(valHum, 2);
printTempAndHum();
}
void printTempAndHum()
{
if (allowPrintData)
{
lcdPrint(true, 0, "Temp ", valTem);
lcd.write(0);
lcd.print("C");
lcdPrint(false, 1, "Hum ", valHum, "%RH");
}
}
/**
CH20
*/
void readCH2O()
{
while ((Serial3.available()) == 0) {
;
}
int buff[9] = {
0 };
for (int i = 0; i < 9; i++)
{
buff[i] = Serial3.read();
}
if (buff[0] == 0xff && buff[1] == 0xff && buff[2] == 0x01 && buff[3] == 0x27)
{
//甲醛
uint8_t verify = (uint8_t)(buff[2] + buff[3] + buff[4] + buff[5] + buff[6] + buff[7]);
valCH20 = (buff[4] * 256 + buff[5]) * buff[6] * 0.01;
if (verify == (uint8_t)buff[8])
{
//校验成功
valCH20 = (buff[4] * 256 + buff[5]) * buff[6] * 0.01;
Serial.print(" Meth=");
Serial.println(valCH20, 2);
printCH2O();
}
}
}
void printCH2O()
{
if (allowPrintData)
{
lcd.setCursor(0, 1);
lcd.print("CH");
lcd.write(2);
lcd.print("O ");
lcd.print(valCH20, 2);
lcd.print("mg/m");
lcd.write(1);
}
}
void readPm2_5()
{
float value = 0;
for (int i = 0; i < 5; i++)
{
digitalWrite(PM_LED, LOW);
delayMicroseconds(280);
float outValue = analogRead(PM_OUT);
delayMicroseconds(40);
digitalWrite(PM_LED, HIGH);
delayMicroseconds(9680);
value += (outValue * 0.00083 -0.1); // = outValue * (5.0/1024.0)*0.17 -0.1
delay(500);
}
valPm2_5 = value / 5;
Serial.print("PM2.5=");
Serial.println(valPm2_5);
printPM();
}
void printPM()
{
if (allowPrintData)
{
lcdPrint(true, 0, "PM2.5 ", valPm2_5);
lcd.print("mg/m");
lcd.write(1);
}
}
void lcdPrint(bool clearFirst, int line, char* type, float value)
{