// ArduiHome Test code // #include #include #include #include #include #include #include #define ONE_WIRE_BUS 4 // DS18S20 wired to digital pin 4, same bus for all sensors LiquidCrystal_I2C lcd(0x20,20,4); // Liquide crystal is a 4x20 LCD with I2C support OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); DeviceAddress bathroom = { 0x10, 0x5E, 0xE8, 0x33, 0x02, 0x08, 0x00, 0xDB }; //Sensor 1 DeviceAddress room = { 0x10, 0xBE, 0xCA, 0x33, 0x02, 0x08, 0x00, 0x89 }; //Sensor 2 DeviceAddress ext = { 0x28, 0x75, 0x73, 0xBC, 0x05, 0x00, 0x00, 0xF8 }; //Sensor 3 unsigned int swt = 0; // flip for alternate the display btw temp and humidity #include "DHT.h" #define DHTPIN0 A0 // sensor DHT room 1 connected to A0 #define DHTPIN1 A1 // sensor DHT room 2 connected to A1 #define DHTTYPE DHT11 // DHT 11 type DHT dht_0(DHTPIN0, DHTTYPE); DHT dht_1(DHTPIN1, DHTTYPE); SMSGSM sms; char number[]="XXXXXXXXXX"; // Destination number char message[180]; char pos; char *p; ///////////////Var and Int for GAS detection function///////////////////// int value=0; int value_old=0; char gasmessage[45]; char value_str[4]; int pin=A3; void setup() { lcd.init(); // initialize the lcd lcd.backlight(); // Backlight ON lcd.setCursor(0, 1); lcd.print(" Ardui'Home "); lcd.setCursor(0, 2); lcd.print(" Loading... "); sensors.begin(); sensors.setResolution(bathroom, 10); sensors.setResolution(room, 10); sensors.setResolution(ext, 10); value=analogRead(pin); value_old=analogRead(pin); dht_0.begin(); // Sensor DHT for room 1 dht_1.begin(); // Sensor DHT for room 2 Serial.begin(9600); if (gsm.begin(2400)) Serial.println("\nstatus=READY"); else Serial.println("\nstatus=IDLE"); (sms.SendSMS(number, "Starting ok !")); //sending sms when he starting up pinMode(7, OUTPUT); // Pin 7 for bliking running led } void loop() { temps(); // calculate and displaying temps from DS18 and DHT sensor's gas(); // For Gas sensing runingled(); //loop to displaying a running LED } void gas() { value=analogRead(pin); Serial.println(value); // For debug if(value<50) //Gas value need to be defined { message[0]='\0'; while(3) // Try to send the SMS 3x in case of GSM network failure { sms.SendSMS(number,"!Alert! - !Gas level reached dangerous limit!"); // Dont forget to set - char gasmessage[XX]; - if you change the message ! } } } void temps() { sensors.requestTemperatures(); float tbathroom = sensors.getTempC(bathroom); // Bathroom sensor float troom = sensors.getTempC(room); // Sitting room temp sensor float text = sensors.getTempC(ext); // Outside sensor swt++; // Alternate displaying betwen DS18 and DHT sensors if ((swt % 15) > 5 ) { //////////////DS18B20 Sensors///////////////// lcd.setCursor(0, 0); lcd.print("Sdb "); lcd.print(tbathroom); lcd.print(" C"); lcd.setCursor(0, 1); lcd.print("Salon "); lcd.print(troom); lcd.print(" C"); lcd.setCursor(0, 2); lcd.print("Exterieur "); lcd.print(text); lcd.print(" C"); lcd.setCursor(0, 3); lcd.print(" "); } else { ////////////////DHT Sensors////////////////// float h0 = dht_0.readHumidity(); float t0 = dht_0.readTemperature(); float h1 = dht_1.readHumidity(); float t1 = dht_1.readTemperature(); lcd.clear(); lcd.setCursor(0, 0); lcd.clear(); lcd.print("Room 1 T: "); // Temperature lcd.print(t0); lcd.print(" C"); //////////////////////////////////////// lcd.setCursor(0, 1); lcd.print(" H: "); // Humidity lcd.print(h0); lcd.print(" %"); //////////////////////////////////////// lcd.setCursor(0, 2); lcd.print("Room 2 T: "); // Temperature lcd.print(t1); lcd.print(" C"); //////////////////////////////////////// lcd.setCursor(0, 3); lcd.print(" H: "); // Humidity lcd.print(h1); lcd.print(" %"); } } /////////// Blink a Led to check if the code run correctly /////////// void runingled() { digitalWrite(7, HIGH); delay(80); digitalWrite(7, LOW); delay(1000); }