1. Trang chủ >
  2. Kỹ Thuật - Công Nghệ >
  3. Kĩ thuật Viễn thông >

15 Kết luận đề tài

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (994.71 KB, 42 trang )


ĐỒ ÁN TỐT NGHIỆP

Trang 33/40



Internet:

[2]



Velleman (1972)







“Amply Max9812L”, Link: http://nshopvn.com/cam-



bien-am-thanh-tich-hop-amly-max9812l.html.

[3]



Sharp



(2006)







“GP2Y1010AUOF



DATASHEET”,



Link:



http//pdf1.alldatasheet.com/datasheet/pdf/pdf/412700/SHARP/GP2Y1010AU0F.

[4]



ESP8266 Opensource Community



ESP8266 ESP12E”,

[5]



Semtech



(2013)







“NODEMCU v1.0 Lua –



Link: https://iotmaker.vn/nodemcu.html.

(2012)







“SX1278



DATASHEET”,



shop.adafruit.com/product-files/3179/sx1276_77_78_79.pdf.



Hệ thống giám sát và cảnh báo mức độ ồn và ơ nhiễm khơng khí



Link:



https://cdn-



ĐỒ ÁN TỐT NGHIỆP

Trang 34/40



PHỤ LỤC A

Code khối con:

#include

#include

#include

#define n_times 10

char i,j;

float dust=0, noise=0;

int16 dustint=0;

int16 noiseint=0;

float dB, ADC;

void _CaiDat(void);

void hien_thi();

void dust_measure()

{

SET_ADC_CHANNEL(0);

unsigned int16 dust_tmp; dust=0;

unsigned int8 n;

for(n=0;n
{

output_low(led_trig); delay_us(280);

dust_tmp=read_adc(); delay_us(40);

output_high(led_trig);

dust=dust+dust_tmp; delay_ms(400);

if(dust>300)

{

output_high(pin_b2);

lcd_putc("\f");

lcd_gotoxy(0,1);

lcd_putc("DO BUI QUA NGUONG");

delay_ms(4000);

}

else

output_low(pin_b2);

}



Hệ thống giám sát và cảnh báo mức độ ồn và ơ nhiễm khơng khí



ĐỒ ÁN TỐT NGHIỆP

Trang 35/40



void _noise()

{

SET_ADC_CHANNEL(1);

unsigned int16 noise_tmp; noise=0;

unsigned int8 n;

for(n=0;n
{

noise_tmp=read_adc();

delay_us(100);

noise= noise + noise_tmp;

}

noise=noise/n_times;

dB = (noise + 83.2073) / 11.003;

if(noise<50)

{

noise = noise + 5;

}

if(dB>50)

{

output_high(pin_b3);

lcd_putc("\f");

lcd_gotoxy(1,2);

lcd_putc("DO ON QUA NGUONG");

//lcd_putc("DO ON QUA NGUONG");

delay_ms(4000);

}

else

output_low(pin_b3);



}

void main(void)

{

_CaiDat();

lcd_init();

while(true)//vong lap vo han

{

Hệ thống giám sát và cảnh báo mức độ ồn và ơ nhiễm khơng khí



ĐỒ ÁN TỐT NGHIỆP

Trang 36/40



dust_measure();

_noise();

hien_thi();

//printf("%lu DO ON: %lu",dustint,dBint);

}

void _CaiDat(void)

{

SETUP_ADC(ADC_CLOCK_INTERNAL);

SETUP_ADC_PORTS(ALL_ANALOG);

SETUP_TIMER_0(T0_INTERNAL|T0_DIV_16);

}

void hien_thi()

{

delay_ms(3000);

lcd_putc("\f");

lcd_gotoxy(0,1);

printf(lcd_putc,"DUST:%f",dust);

lcd_gotoxy(1,2);

printf(lcd_putc,"dB:%f",dB);

}



Code khối trung tâm:

#include ;

#include

#include ;

LiquidCrystal_I2C lcd(0x27, 20, 4);

const char* ssid = "TRAN MINH TRI";

const char* password = "41302431";

String c, noise, noise2, dust, dust2;

uint16_t noiseint, dustint;



Hệ thống giám sát và cảnh báo mức độ ồn và ô nhiễm không khí



ĐỒ ÁN TỐT NGHIỆP

Trang 37/40



float phfloat;

byte moc;

unsigned long tx, tt;

float dem = 1;

int them = 0;

int i = 1, j = 3;

int n = 1;

int btnPin = 14;

int buzze = 12;

int node = 0;



WiFiClient client;

// ThingSpeak Settings

String writeAPIKey = "RTGKP5VNIAEU5U06"; ThingSpeak Channel

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

const int postingInterval = 2 * 1000;

void setup()

{

lcd.init();

lcd.backlight();

tx = millis();

tt = millis();

pinMode(btnPin, INPUT);

pinMode(buzze, OUTPUT);

digitalWrite(buzze, 0);



Hệ thống giám sát và cảnh báo mức độ ồn và ơ nhiễm khơng khí



ĐỒ ÁN TỐT NGHIỆP

Trang 38/40



//pinMode(btnPin, INPUT_PULLUP);

Serial.begin(9600);

Serial.print("Connecting");

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

Serial.print(".");

delay(100);

}

Serial.println("\r\nWiFi connected");

Serial.write("begin");

lcd.clear();

}

void loop()

{

truyen();

uart();

String body = "field1=" + String(noise) + "&field2=" + String(dust) + "&field3="

+ String(noise2) + "&field4=" + String(dust2);

delay(postingInterval);

if (client.connect(server, 80)) {

client.print("POST /update HTTP/1.1\n");

client.print("Host: api.thingspeak.com\n");

client.print("Connection: close\n");

client.print("X-THINGSPEAKAPIKEY: " + writeAPIKey + "\n");

client.print("Content-Type: application/x-www-form-urlencoded\n");

client.print("Content-Length: ");



Hệ thống giám sát và cảnh báo mức độ ồn và ô nhiễm khơng khí



ĐỒ ÁN TỐT NGHIỆP

Trang 39/40



client.print(body.length());

client.print("\n\n");

client.print(body);

client.print("\n\n");

}

client.stop();

}

void uart(void) {



if (Serial.available() > 0) {

c = Serial.readString();

for (int i = 0; i < c.length(); i++) { //Node1,0789,85.0,30.0

if (c.substring(i, i + 1) == ",") //Node1,0789,85.0,30.0 "NODE2,noise:%u,dust:

%u" node1,noise:41.33,dust:32.84

{

if (c.substring(0, 5) =="node1") {



pass1 = c.substring(0, 5);

noise = c.substring(12, 14);

dust = c.substring(23, 26);



//String body = "field1=" + String(temp) + "&field2=" + String(humi) +

"&field3=" + String(co2) + "&field4=" + String(dust)+ "&field5=" + String(ph);

Serial.print("noise: "); Serial.println(noise);



Hệ thống giám sát và cảnh báo mức độ ồn và ô nhiễm khơng khí



ĐỒ ÁN TỐT NGHIỆP

Trang 40/40



Serial.print("dust: "); Serial.println(dust);

lcd.clear();

}

if (c.substring(0, 5) == "node2") {

pass2 = c.substring(0, 5);

noise2 = c.substring(12, 14);

dust2 = c.substring(23, 26);



Serial.print("noise2: "); Serial.println(noise2);

Serial.print("dust2: "); Serial.println(dust2);

lcd.clear();

}

}

}

}

lcd.setCursor(0, 0);

lcd.print("khoi 1");

lcd.setCursor(0, 1);

lcd.print("noise:"); lcd.print(noise);

lcd.setCursor(20, 0);

lcd.print("dust:"); lcd.print(dust);

tempint = noise.toInt();

humiint = dust.toInt();



Hệ thống giám sát và cảnh báo mức độ ồn và ơ nhiễm khơng khí



ĐỒ ÁN TỐT NGHIỆP

Trang 41/40



if (noiseint > 30)

{

lcd.clear();

lcd.setCursor(0, 1);

lcd.print("DO ON QUA NGUONG");

digitalWrite(buzze, 1);

delay(4000);

digitalWrite(buzze, 0);

lcd.clear();

}

if (dustint > 300)

{

lcd.clear();

lcd.setCursor(2, 1);

lcd.print("DO BUI QUA NGUONG");

digitalWrite(buzze, 1);

delay(4000);

digitalWrite(buzze, 0);

lcd.clear();



}

}

void truyen(void) {



if ( (unsigned long) (millis() - tx) > 7000 )

{



Hệ thống giám sát và cảnh báo mức độ ồn và ơ nhiễm khơng khí



ĐỒ ÁN TỐT NGHIỆP

Trang 42/40



Serial.print("node");

Serial.print(n);

n = n + 1;

if (n > 2)

{

n = 1;

}

tx = millis();

}



}



Hệ thống giám sát và cảnh báo mức độ ồn và ơ nhiễm khơng khí



Xem Thêm
Tải bản đầy đủ (.docx) (42 trang)

×