Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. #include <DHT.h>
  2. #include <LiquidCrystal.h>
  3. #include <SoftwareSerial.h>
  4. #include <Adafruit_Sensor.h>
  5. LiquidCrystal lcd(3, 4, 5, 6, 7, 8);
  6. int RX=45;
  7. int TX=47;
  8. SoftwareSerial BTmodule(RX,TX);
  9. DHT dht(51,DHT11);
  10. #include <Servo.h>
  11. #define TEMT A0
  12. #define FOTO A1
  13. #define VAPORE A3
  14. #define VIBRA A4
  15. int FIAMMA=53;
  16. int luce=12;
  17. int bz=49;
  18. Servo myservo;
  19. Servo myservo2;
  20. int pos = 0;
  21. //int i=0;
  22. int j=0;
  23. //int k=0;
  24. int rbin=11;
  25. int val=0; //valore fotoresistenza binari
  26. int val2=0; //valore TEMT
  27. int val4=0; //valore FIAMMA
  28. int val5=0; //valore VIBRAZIONE
  29. int val6=0; //valore VAPORE
  30. int val7=0; //valore TEMPERATURA
  31. int val8=0; //valore UMIDITA'
  32. int allarme=0;
  33. int ledin=0;
  34. int ledvi=0;
  35. int ledgas=0;
  36. int prima=0;
  37. void setup()
  38. {
  39. pinMode(rbin,OUTPUT);
  40. pinMode(luce,OUTPUT);
  41. pinMode(FOTO,INPUT);
  42. lcd.begin(16, 2);
  43. myservo.attach(10);
  44. myservo2.attach(9);
  45. Serial.begin(115200);
  46. BTmodule.begin(115200);
  47. Serial1.begin(1152000);
  48. dht.begin();
  49. pinMode(TEMT,INPUT);
  50. pinMode(bz, OUTPUT);
  51. }
  52.  
  53. void loop()
  54. {
  55. val=analogRead(FOTO);
  56. if(val<100)
  57. {digitalWrite(rbin,HIGH);
  58. for (pos = 0; pos <= 90; pos += 1)
  59. {
  60. myservo.write(90-pos);
  61. myservo2.write(pos+90);
  62. luminosita();
  63. gas();
  64. tone(bz,900,100);
  65. delay(100);
  66. }
  67.  
  68. for(j=0;j<160;j++)
  69. {
  70. luminosita();
  71. gas();
  72. delay(60);
  73. }
  74.  
  75. for (pos = 0; pos <= 90; pos += 1)
  76. {
  77. myservo.write(pos);
  78. myservo2.write(180-pos);
  79. luminosita();
  80. gas();
  81. delay(50);
  82. }
  83. digitalWrite(rbin,LOW);
  84. }
  85. else if(val>100)
  86. {
  87. luminosita();
  88. gas();
  89. digitalWrite(rbin,LOW);
  90. myservo.write(90);
  91. myservo2.write(90);
  92. }
  93. }
  94. void luminosita()
  95. {
  96. val2=analogRead(TEMT);
  97. if(val2<200)
  98. {
  99. digitalWrite(luce, HIGH);
  100. }
  101. else
  102. {
  103. digitalWrite(luce, LOW);
  104. }
  105. }
  106. void gas()
  107. {
  108. allarme=0;
  109. delay(50);
  110.  
  111.  
  112. val4=digitalRead(FIAMMA);
  113. Serial.print(val4);
  114. Serial.print(" ");
  115. if(val4==0)
  116. {
  117. allarme++;
  118. BTmodule.println("PERICOLO INCENDI");
  119. }
  120. //1 no fiamme 0 si fiamme
  121. val5=analogRead(VIBRA);
  122. Serial.print(val5);
  123. Serial.println(" ");
  124. if(val5>500)
  125. {
  126. allarme++;
  127. BTmodule.println("PERICOLO TERREMOTO");
  128. }
  129. //<500 no vibra >500 vibra
  130. val6=analogRead(VAPORE);
  131. lcd.setCursor(0,0);
  132. lcd.print("vap:");
  133. lcd.print(val6);
  134. BTmodule.print("livello vapore: ");
  135. BTmodule.println(val6);
  136.  
  137. val7=dht.readTemperature();
  138. lcd.setCursor(8,0);
  139. lcd.print("temp:");
  140. lcd.print(val7);
  141. BTmodule.print("temperatura: ");
  142. BTmodule.print(val7);
  143. BTmodule.println("°");
  144.  
  145. val8=dht.readHumidity();
  146. lcd.setCursor(0,1);
  147. lcd.print("umidita':");
  148. lcd.print(val8);
  149. lcd.print("%");
  150. BTmodule.print("umidità: ");
  151. BTmodule.print(val8);
  152. BTmodule.println("%");
  153.  
  154. int l=BTmodule.read();
  155. Serial.print(l);
  156.  
  157. if(allarme>0)
  158. {
  159. int a = 10;
  160. Serial1.write(a);
  161. Serial.println("ok");
  162. }
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement