ILOVA A - Energiya va elektrika texnika instituti

ILOVA A
//LCD displey ulanishlari #include
#include
LiquidCrystal_I2C lcd(0x27,16,2);
//RFID ACSni ulash #include
#include
#define
SS_PIN 53 #define
RST_PIN 5
MFRC522 mfrc522(SS_PIN, RST_PIN);
unsigned long uidDec, uidDecTemp; //Teg raqamini kasr formatida saqlash uchun
int countRFID = 0; //
RFID karta o'qishlar sonining hisoblagichi int relayDoor = 11; //
Elektr klapanni (keyingi o'rinlarda qulf deb yuritiladi) boshqarish uchun o'rni
bool d = noto'g'ri; //Bloklash holatini o'zgartirishni amalga
oshirish uchun int countUNKNOWN; //Ro'yxatdan o'tmagan RFID kartasini o'qishlar sonining hisoblagichi
//Int relay signalizatsiyasi
uchunAlarm = 9; //Sirenni ulash uchun rele
//Bluetooth orqali boshqarish uchun
int val = 0; //Portdan ma'lumotlarni yozish uchun o'zgaruvchi
//Gaz qochqinlarini himoya qilish tizimi
uchun int gasPin = A9; //Gaz sensori uchun
pin int gasValue = 0; //Gaz sensori ma'lumotlarini saqlash uchun o'zgaruvchi int
relayGas = 4; //Fan yoki elektr klapanni (bu holda fan) ulash uchun rele bool a = true; //
Budilnikni bitta signal bilan ham
yoqing
gaz sensori
int countGas = 0; //Gaz sensori signallari soni
//Suv oqishini himoya qilish tizimi uchun int
waterPin = A4; //suv sensori uchun PIN int
waterValue = 0; //Suv sensori ma'lumotlarini saqlash uchun o'zgaruvchi int
relayWater = 12; //Elektr klapanni ulash uchun rele bool b = true; //
Budilnikni bitta signal bilan ham yoqing
suv sensori
int countWater = 0; //Suv sensori faollashtirilgan soni
50
Machine Translated by Google
//Yong'in sensori
uchun int firePin = A7; //Yong'in sensori
uchun pin int fireValue = 0; //Yong'in sensori ma'lumotlarini saqlash uchun o'zgaruvchi bool c = true; //Budilnikni bitta signal bilan ham yoqing yong'in sensori
int countFire = 0; //Yong'in sensori faollashtirilgan soni
//Eshikni qo'riqlash uchun int
gerkon = 7; //Ochiq datchik pin int
gerkonState = 0; //Ochish sensori ma'lumotlarini saqlash uchun o'zgaruvchi int countDoor = 0; //Tizimni qurollantirish uchun o'zgaruvchi
void setup()
{ //Eslatma: signal darajasi YUQOR bo'lganda har qanday rele o'chiriladi Serial.begin(9600); //com port pinMode (relayAlarm, OUTPUT) orqali ma'lumotlar almashinuv kursi; // digitalWrite sirenasini ulash (relayAlarm, HIGH); //Dastlab sirena o'chirilgan pinMode(gerkon, INPUT); //Ochish sensori ulanishi
//Displeyni ulash
lcd.begin(); //Initializatsiya
lcd.noBacklight(); // Orqa yorug'likni o'chirish
//Gaz qochqinlarini himoya qilish tizimini ulash pinMode(relayGas, OUTPUT);
digitalWrite(relayGas, HIGH);
//suv oqishini himoya qilish tizimini ulash pinMode(relayWater, OUTPUT);
digitalWrite(relayWater, HIGH);
//ACS ulanishi
SPI.begin(); //Initializatsiya
mfrc522.PCD_Init();
pinMode (relayEshik, OUTPUT);
digitalWrite(relayDoor, HIGH); //Dastlab qulf yopiladi }
void loop()
{ //BLUETOOTH CONTROL if
(Serial.available() > 0) //Agar com portiga biror narsa kelgan
bo'lsa { val = Serial.read(); //Val o'zgaruvchiga yozish, portdan ma'lumotlarni o'qish
51
Machine Translated by Google
//Gaz qochqinlarini himoya qilish tizimi uchun agar (val == '1') //Agar “1”
kelgan bo'lsa { lcd.clear(); //Displeydagi
yozuvni
chiqarish
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("FAN");
lcd.setCursor(0,1); lcd.print("ISLAYDI");
digitalWrite(relayGas, LOW); //
Shamollatishni yoqing } if(val == '2') //Agar “2” kelgan bo'lsa { digitalWrite(relayGas, HIGH); //DigitalWrite
ventilyatsiyasini
o'chiring(relayAlarm, HIGH); // Signalni o'chirish lcd.clear(); lcd.noBacklight(); countGas = 0
//Suv oqishini himoya qilish tizimi uchun agar (val == '3') //Agar “3” kelgan
bo'lsa { lcd.clear(); //Displeydagi yozuvni
chiqarish
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("SUV
VANA"); lcd.setCursor(0,1);
lcd.print("ISLAYDI"); digitalWrite(relayWater, LOW); //
Elektr
klapanni yoqish } if(val == '4') { digitalWrite(relayWater,
HIGH); //digitalWrite elektr klapanini o'chiring(relayAlarm,
HIGH); //
Signalni o'chirish
lcd.clear();
lcd.noBacklight(); countWater = 0; }
//Yong'in sensori uchun if (val
== '5') { digitalWrite(relayAlarm, HIGH); // Signalni o'chirish
lcd.clear();
52
Machine Translated by Google
lcd.noBacklight();
countFire =
0; }
//Qurollash uchun (old eshikni boshqarish) if (val == '6')
{ lcd.clear(); //
lcd.backlight(); yorlig'ini
chiqarish.
lcd.setCursor(0,0);
lcd.print("XAVFSIZLIK REJIMI");
countDoor++; //tizimni qurollantirish uchun o'zgaruvchi }
//Agar qurolsizlantirish
uchun (val
== '7') { countDoor = 0; //O'zgaruvchini
nolga qaytarish lcd.clear(); //Agar yoqilgan bo'lsa signalni
o'chiring
lcd.noBacklight();
digitalWrite(relayAlarm, HIGH); } }
agar (countDoor > 0 && a == rost) //Tizim xavfsizlik rejimida bo'lsa
{ a =
noto'g'ri; gerkonState = digitalRead(gerkon); //Ochish sensori ma'lumotlarini
o'qish if(gerkonState == HIGH) //Agar eshik ochiq
bo'lsa { lcd.clear(); //
lcd.backlight();
yorlig'ini chiqarish.
lcd.setCursor(0,0);
lcd.print("XAVFSIZLIK
REJIMI"); lcd.setCursor(0,1);
lcd.print("ESHIK OCHIQ!"); digitalWrite(relayAlarm, LOW); //
Signalni yoqish } }
//SUV OCHISHIDAN HIMOYA QILISh TIZIMI
waterValue = analogRead(waterPin); //Suv sensori ma'lumotlarini o'qing, agar (waterValue <= 500 && b == rost) //Agar sizib chiqish aniqlansa { b =
noto'g'ri;
53
Machine Translated by Google
countWater = 1; //Datchik javob hisoblagichini oshiring } if (waterValue
> 500 && b == false) //Agar u ishlamasa { countWater = 0; //
Qayta tiklash b = rost; } if
(countWater == 1) //Datchik ishga tushirilganda quyidagilar bajariladi:
{ lcd.backlight(); //lcd.clear() yorlig'ini
chiqaring;
lcd.setCursor(0,0);
lcd.print("Signal! SUV");
lcd.setCursor(0,1);
lcd.print(" ");
digitalWrite(relayWater, LOW); // digitalWrite elektr klapanini yoqish(relayAlarm, LOW); // Signalni yoqish }
//GAZ CHIQISHINI HIMOYA QILISh TIZIMI
gazValue = analogRead(gasPin); //Gaz datchigidan ma'lumotlarni o'qing, agar (gasValue > 400 && a == rost) //Agar sizib chiqish aniqlansa
{ a =
noto'g'ri; countGas = 1; //Datchik javob hisoblagichini oshiring } if
(gasValue < 400 && a == false) //Agar u ishlamasa
{ countGas = 0; // Qayta tiklash a
= rost; } if (countGas == 1) //Datchik ishga tushirilganda
quyidagilar bajariladi: { lcd.backlight(); //
lcd.clear()
yorlig'ini chiqaring;
lcd.setCursor(0,0);
lcd.print("ALARM!
GAS"); ");
lcd.setCursor(0,1); lcd.print(" digitalWrite(relayGas, LOW); //
digitalWrite elektr klapanini yoqing(relayAlarm, LOW); // Signalni yoqing }
//YONG'IN SENSORI
yong'in qiymati = analogRead(firePin); //Yong'in sensori ma'lumotlarini o'qing
54
Machine Translated by Google
agar (fireValue < 30 && c == rost) //Agar yong'in aniqlansa
{ c = noto'g'ri; //Datchik javob hisoblagichini oshiring countFire =
1; } if (fireValue > 100 && c == false) //Agar u ishlamasa
{ countFire = 0; //Qayta
tiklash
c = rost; } if (countFire == 1) //Datchik ishga tushirilganda
quyidagilar bajariladi:
{ lcd.backlight(); //
lcd.clear() yorlig'ini chiqaring;
lcd.setCursor(0,0);
");
lcd.print("ALARM! YONGIN"); lcd.setCursor(0,1); lcd.print(" digitalWrite(relayAlarm, LOW); // Signalni yoqish }
//ACS if
(!mfrc522.PICC_IsNewCardPresent()) { //Yangi yorliqni qaytarishni
qidiring; } if (!mfrc522.PICC_ReadCardSerial()) { //Yorliq
qaytarilishini
tanlang; } uidDec = 0; uchun (bayt i = 0; i < mfrc522.uid.size; i++) { //uidDecTemp
tegining seriya raqamini berish = mfrc522.uid.uidByte[i]; //O'nlik
formatda uidDec = uidDec * 256 +
uidDecTemp; } if (uidDec == 16909060) { //Yorliq raqamini berilgan bilan solishtirish, agar raqamlar
teng bo'lsa, d = !d; //Bloklash
kechikish
holatini
o'zgartirish (1000); } if (d) { digitalWrite(relayDoor,
LOW); //"eshik ochiq" } else { digitalWrite(relayDoor, HIGH); //"eshik yopiq"}
55
Machine Translated by Google
if (uidDec != 16909060) { //Agar raqamlar teng
bo'lmasa
kechikish(1000);
countUNKNOWN++; if(countUNKNOWN = 1) { //Ro'yxatdan o'tmagan kartani
o'qishlar soni lcd.clear(); //
lcd.backlight();
yorlig'ini chiqarish.
lcd.setCursor(0,0);
lcd.print("ALARM!");
lcd.setCursor(0,1);
lcd.print("Noma'lum KARTA"); digitalWrite(relayAlarm,
LOW); // Signalni yoqish } } }
56
|