có cảm biến gas
unknown
plain_text
2 years ago
3.2 kB
3
Indexable
#include<LiquidCrystal.h> LiquidCrystal lcd(7, 6, 5, 4, 3, 2); int motorPin = 12; //connection pins of DC motor int temp = 0; //value variable temp int r =0; float voltage = 0; //value variable voltage float sensor = 0; //value variable sensor float celsius = 0; //value variable celsius(C) float fahrenheit = 0; //value variable fahrenheit(F) int couter = 0; //couter variable int sensor_In = 0; //smoke sensor #define SENSOR_PIN A1 //sensor connector void setup() { Serial.begin(9600); //Open the Serial port at baudrate 9600 to communicate with the computer pinMode(2, INPUT); //Cài đặt chân D2 ở trạng thái đọc dữ liệu pinMode(2,OUTPUT); //lcd.setCursor(3,0); //lcd.print("NHIET DO"); pinMode(A1, INPUT); lcd.begin(16, 2); //LCD screen with size 16x2. pinMode(13, OUTPUT); //13 is the output (OUTPUT) to drive the LED and the DC motor. pinMode(12, OUTPUT); //12 is the output (OUTPUT) to drive the LED //Setup DC motor //pinMode(motorPin, OUTPUT); while (!Serial); //The program will execute this print command line and then execute other commands Serial.println("Speed 0 to 255"); } void loop() { sensor_In = analogRead(A0); //read smoke sensor using analogRead(A0) temp = analogRead(A1); //read temperature sensor using analogRead(A1) Serial.println(analogRead(A0)); //Write the value you just read to Serial and print it on the computer Serial.println(analogRead(A1)); //Write the value you just read to Serial and print it on the computer lcd.setCursor(5,1); //cursor is displayed in column 5 and row 1 for (int i = 12; i <= 13; i++) //turn off output on two ports 12 and 13 digitalWrite(i, LOW); if (temp >= 207 ||sensor_In >=30) //Check temperature value and smoke sensor. { digitalWrite(13, HIGH); //Turn on the LED on pin 13 digitalWrite(12, LOW); //Turn off the LED on pin 12. tone(13, 720); //play tone 60 (C5 = 523 Hz) sensor = analogRead(SENSOR_PIN); //Read the value from the sensor and calculate the Celsius temperature value. voltage = (sensor*5000)/1024; //mV (mili Volt). voltage = voltage-495; celsius = voltage/10; //convert voltage value to Celsius . temperature unit lcd.setCursor(6,0); lcd.print(celsius); lcd.setCursor(2,4); lcd.print("Co 1 dam chay"); delay(1000); lcd.clear(); } else if(temp <207 || sensor_In < 30){ digitalWrite(13, LOW); digitalWrite(12, HIGH); lcd.clear(); noTone(13); sensor = analogRead(SENSOR_PIN); voltage = (sensor*5000)/1024; //5000mv chia cho giá trị analog voltage = voltage-495; // trừ điện áp bù trừ celsius = voltage/10; // chuyển từ mV sang độ C lcd.setCursor(6,0); lcd.print(celsius); // giá trị C hiển thị ở dòng thứ 3 lcd.setCursor(3,4); lcd.print("Binh Thuong"); delay(1000); lcd.clear(); delay(1000); } }
Editor is loading...