Advertisement
shadow7777

Wiktor Bień - system przeciwpożarowy

May 31st, 2022
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1. #define Pomp 12
  2. #define left 2
  3. #define velocity 3
  4. #define right 4
  5. #define Buzzer 7
  6.  
  7.  
  8.  
  9. #include <Wire.h>
  10. #include <LiquidCrystal_I2C.h>
  11.  
  12. LiquidCrystal_I2C lcd(0x27,16,2);
  13. const int analogInPin = A0;
  14. const int analogPin2 = A1;
  15. int sensorValue = 0;
  16. int outputValue = 0;
  17. int sensorValue2 = 0;
  18. int outputValue2 = 0;
  19.  
  20.  
  21.  
  22.  
  23.  
  24. void setup() {
  25.   pinMode(Pomp, OUTPUT);
  26.   pinMode(left, OUTPUT);
  27.   pinMode(velocity, OUTPUT);
  28.   pinMode(right, OUTPUT);
  29.   pinMode(Buzzer, OUTPUT);
  30.   Serial.begin(9600);
  31.   lcd.init();
  32.   lcd.backlight();
  33.   lcd.print("Pomiesczenie");
  34.   lcd.setCursor(0,1);
  35.   lcd.print("bezpieczne");
  36. }
  37.  
  38. void loop() {
  39.   motor_control();
  40.   sensors_control();
  41.   pomp_control();
  42.  
  43. }
  44.  
  45. void pomp_control()
  46. {
  47.  
  48.  
  49.   if(sensorValue>130)
  50.   {
  51.   digitalWrite(Pomp, LOW);
  52.   digitalWrite(Buzzer, HIGH);
  53.   lcd.clear();
  54.   lcd.print("Zagrozenie");
  55.   lcd.setCursor(0,1);
  56.   lcd.print("pozarowe");
  57.    delay(300);
  58.   }
  59.  
  60.   if(sensorValue < 130)
  61.   {
  62.   digitalWrite(Pomp, HIGH);
  63.   digitalWrite(Buzzer, LOW);
  64.   lcd.clear();
  65.   lcd.print("Pomiesczenie");
  66.   lcd.setCursor(0,1);
  67.   lcd.print("bezpieczne");
  68.   delay(300);
  69.  
  70.   }
  71.  
  72.  
  73. }
  74.  
  75.  
  76. void sensors_control()
  77.  
  78. {
  79. sensorValue = analogRead(A0);
  80. outputValue = map(sensorValue, 0, 1023, 0, 255);
  81. sensorValue2 = analogRead(A1);
  82. outputValue2 = map(sensorValue2, 0, 1023, 0, 255);
  83.  
  84.  
  85.  
  86.   Serial.println("sensor1: ");
  87.   Serial.println(sensorValue);
  88.  
  89.   Serial.println("sensor2: ");
  90.   Serial.println(sensorValue2);
  91.  
  92.   delay(100);
  93. }
  94.  
  95.  
  96. void motor_control()
  97.  
  98.  
  99. {
  100.   if(sensorValue2 > 150 && sensorValue2 < 250)
  101.   {
  102.   analogWrite(velocity, 170);
  103.   digitalWrite(right, HIGH);
  104.   digitalWrite(Buzzer, HIGH);
  105.   delay(250);
  106.   lcd.clear();
  107.   lcd.print("Zagrozenie");
  108.   lcd.setCursor(0,1);
  109.   lcd.print("gazowe");
  110.   Serial.println("speed1");
  111.   }
  112.  
  113.   else if(sensorValue2 > 250 && sensorValue2 < 300)
  114.   {
  115.   analogWrite(velocity, 210);
  116.   digitalWrite(right, HIGH);
  117.   digitalWrite(Buzzer, HIGH);
  118.   delay(250);
  119.   lcd.clear();
  120.   lcd.print("Zagrozenie");
  121.   lcd.setCursor(0,1);
  122.   lcd.print("gazowe");
  123.   delay(300);
  124.   Serial.println("speed2");
  125.   }
  126.  
  127.   else if(sensorValue2 > 300)
  128.   {
  129.   analogWrite(velocity, 255);
  130.   digitalWrite(right, HIGH);
  131.   digitalWrite(Buzzer, HIGH);
  132.   delay(250);
  133.   lcd.clear();
  134.   lcd.print("Zagrozenie");
  135.   lcd.setCursor(0,1);
  136.   lcd.print("gazowe");
  137.   delay(300);
  138.   Serial.println("speed3");
  139.   }
  140.   else if(sensorValue2 < 125)
  141.   {
  142.   digitalWrite(velocity, LOW);
  143.   digitalWrite(right, LOW);
  144.   digitalWrite(Buzzer, LOW);
  145.   lcd.clear();
  146.   lcd.print("Pomiesczenie");
  147.   lcd.setCursor(0,1);
  148.   lcd.print("bezpieczne");
  149.   delay(300);
  150.   }
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement