Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <DHT.h>
- #include <LiquidCrystal.h>
- #include <SoftwareSerial.h>
- #include <Adafruit_Sensor.h>
- LiquidCrystal lcd(3, 4, 5, 6, 7, 8);
- int RX=45;
- int TX=47;
- SoftwareSerial BTmodule(RX,TX);
- DHT dht(51,DHT11);
- #include <Servo.h>
- #define TEMT A0
- #define FOTO A1
- #define VAPORE A3
- #define VIBRA A4
- int FIAMMA=53;
- int luce=12;
- int bz=49;
- Servo myservo;
- Servo myservo2;
- int pos = 0;
- //int i=0;
- int j=0;
- //int k=0;
- int rbin=11;
- int val=0; //valore fotoresistenza binari
- int val2=0; //valore TEMT
- int val4=0; //valore FIAMMA
- int val5=0; //valore VIBRAZIONE
- int val6=0; //valore VAPORE
- int val7=0; //valore TEMPERATURA
- int val8=0; //valore UMIDITA'
- int allarme=0;
- int ledin=0;
- int ledvi=0;
- int ledgas=0;
- int prima=0;
- void setup()
- {
- pinMode(rbin,OUTPUT);
- pinMode(luce,OUTPUT);
- pinMode(FOTO,INPUT);
- lcd.begin(16, 2);
- myservo.attach(10);
- myservo2.attach(9);
- Serial.begin(115200);
- BTmodule.begin(115200);
- Serial1.begin(1152000);
- dht.begin();
- pinMode(TEMT,INPUT);
- pinMode(bz, OUTPUT);
- }
- void loop()
- {
- val=analogRead(FOTO);
- if(val<100)
- {digitalWrite(rbin,HIGH);
- for (pos = 0; pos <= 90; pos += 1)
- {
- myservo.write(90-pos);
- myservo2.write(pos+90);
- luminosita();
- gas();
- tone(bz,900,100);
- delay(100);
- }
- for(j=0;j<160;j++)
- {
- luminosita();
- gas();
- delay(60);
- }
- for (pos = 0; pos <= 90; pos += 1)
- {
- myservo.write(pos);
- myservo2.write(180-pos);
- luminosita();
- gas();
- delay(50);
- }
- digitalWrite(rbin,LOW);
- }
- else if(val>100)
- {
- luminosita();
- gas();
- digitalWrite(rbin,LOW);
- myservo.write(90);
- myservo2.write(90);
- }
- }
- void luminosita()
- {
- val2=analogRead(TEMT);
- if(val2<200)
- {
- digitalWrite(luce, HIGH);
- }
- else
- {
- digitalWrite(luce, LOW);
- }
- }
- void gas()
- {
- allarme=0;
- delay(50);
- val4=digitalRead(FIAMMA);
- Serial.print(val4);
- Serial.print(" ");
- if(val4==0)
- {
- allarme++;
- BTmodule.println("PERICOLO INCENDI");
- }
- //1 no fiamme 0 si fiamme
- val5=analogRead(VIBRA);
- Serial.print(val5);
- Serial.println(" ");
- if(val5>500)
- {
- allarme++;
- BTmodule.println("PERICOLO TERREMOTO");
- }
- //<500 no vibra >500 vibra
- val6=analogRead(VAPORE);
- lcd.setCursor(0,0);
- lcd.print("vap:");
- lcd.print(val6);
- BTmodule.print("livello vapore: ");
- BTmodule.println(val6);
- val7=dht.readTemperature();
- lcd.setCursor(8,0);
- lcd.print("temp:");
- lcd.print(val7);
- BTmodule.print("temperatura: ");
- BTmodule.print(val7);
- BTmodule.println("°");
- val8=dht.readHumidity();
- lcd.setCursor(0,1);
- lcd.print("umidita':");
- lcd.print(val8);
- lcd.print("%");
- BTmodule.print("umidità: ");
- BTmodule.print(val8);
- BTmodule.println("%");
- int l=BTmodule.read();
- Serial.print(l);
- if(allarme>0)
- {
- int a = 10;
- Serial1.write(a);
- Serial.println("ok");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement