#include "mbed.h" #include "TextLCD.h" #include int nsum=10; DigitalOut myled(LED1); DigitalOut led_pin1(P10_12); DigitalIn moisture_sensor(P4_7); DigitalIn IR_sensor(P4_6); DigitalOut led_pin3(P8_15); DigitalOut led_pin2(P10_14) ; DigitalIn PIR_pin(P10_15) ; DigitalIn Flame_sensor(P4_5); DigitalOut Buzzer(P10_13); AnalogIn LDR_pin(P1_8) ; AnalogIn temp(P1_9); AnalogIn LM35(P1_10); AnalogIn MQ6_Sensor(P1_11); AnalogIn humidity(P1_13); AnalogIn LDR_pin2(P1_15) ; // for connecting to Fan DigitalOut Exchaust_Fan_pin(P8_14) ; Serial pc(USBTX, USBRX); // tx, rx // pc comunication Serial SIM900(P8_13, P8_11); //tx =P8_13, rx = P8_11 of Renesas GR Peach SIM 900 to be connected to Serial 5 string result; char x; float sensorValue2 = 0.0; float sensorValue3 = 0.0; TextLCD lcd(P2_0, P2_1, P2_2, P2_3, P2_4, P2_5 ); // rs, e, d4-d7 , connect to GR Peach /* The circuit: * LCD RS pin to digital pin GR Peach P2_0 * LCD Enable pin to digital GR Peach P2_1 * LCD D0 pin to digital GR Peach P2_2 * LCD D1 pin to digital GR Peach P2_3 * LCD D2 pin to digital GR Peach P2_4 * LCD D3 pin to digital GR Peach P2_5 * LCD R/W pin to ground * LCD VSS pin to ground * LCD VCC pin to 5V * ends to +5V and ground * Using 10K resistor (pot):wiper to LCD VO pin (pin 3) */ void clearString() { result.clear(); } void callback_rx() { while (SIM900.readable()) { x = SIM900.getc(); result += x; pc.putc(x); // print the answer from SIM900 } } void sendSMS() { clearString(); SIM900.printf("AT\r"); //at Command wait_ms(1000); clearString(); SIM900.printf("AT+CMGF=1\r"); //at command for send sms wait_ms(1000); clearString(); wait_ms(1000); SIM900.printf("AT+CMGS="); SIM900.putc('"'); SIM900.printf("+918553472606"); SIM900.putc('"'); SIM900.printf("\r"); wait_ms(1000); SIM900.printf("Hi, Welcome to GR Peach Design Contest Project Demo: GR Peach based Smart Home Food storage Maintenance and Monitoring Safety Alert System"); wait_ms(1000); SIM900.putc(0x1A); wait_ms(5000); } void sendSMS1() { clearString(); SIM900.printf("AT\r"); //at Command wait_ms(1000); clearString(); SIM900.printf("AT+CMGF=1\r"); //at command for send sms wait_ms(1000); clearString(); wait_ms(1000); SIM900.printf("AT+CMGS="); SIM900.putc('"'); SIM900.printf("+918553472606"); SIM900.putc('"'); SIM900.printf("\r"); wait_ms(1000); SIM900.printf("Hi Saleem: GR Peach based Smart Home Food storage Maintenance and Monitoring Safety Alert System is Ready for the demonstration."); wait_ms(1000); SIM900.putc(0x1A); wait_ms(5000); } void sendSMS_Fire_Alert() { clearString(); SIM900.printf("AT\r"); //at Command wait_ms(1000); clearString(); SIM900.printf("AT+CMGF=1\r"); //at command for send sms wait_ms(1000); clearString(); wait_ms(1000); SIM900.printf("AT+CMGS="); SIM900.putc('"'); SIM900.printf("+918553472606"); SIM900.putc('"'); SIM900.printf("\r"); wait_ms(1000); SIM900.printf("Hi Saleem: Alert: Fire has been detected in the Kitchen, take neccessary Action."); wait_ms(1000); SIM900.putc(0x1A); wait_ms(5000); } void sendSMS_Smoke_LPG_Alert() { clearString(); SIM900.printf("AT\r"); //at Command wait_ms(1000); clearString(); SIM900.printf("AT+CMGF=1\r"); //at command for send sms wait_ms(1000); clearString(); wait_ms(1000); SIM900.printf("AT+CMGS="); SIM900.putc('"'); SIM900.printf("+918553472606"); SIM900.putc('"'); SIM900.printf("\r"); wait_ms(1000); SIM900.printf("Hi Saleem: Alert, LPG Gas leakage and Smoke has been Detected, Alert. Buzzer is on, Exchaust Fan turned on."); wait_ms(1000); SIM900.putc(0x1A); wait_ms(5000); } void sendSMS_Alert_utensil1() { clearString(); SIM900.printf("AT\r"); //at Command wait_ms(1000); clearString(); SIM900.printf("AT+CMGF=1\r"); //at command for send sms wait_ms(1000); clearString(); wait_ms(1000); SIM900.printf("AT+CMGS="); SIM900.putc('"'); SIM900.printf("+918553472606"); SIM900.putc('"'); SIM900.printf("\r"); wait_ms(1000); SIM900.printf("Hi Saleem, Food Storage in Utensil 1 : Ragi is below the threshold Level, Kindly Check"); wait_ms(1000); SIM900.putc(0x1A); wait_ms(5000); } void sendSMS_Alert_utensil2() { clearString(); SIM900.printf("AT\r"); //at Command wait_ms(1000); clearString(); SIM900.printf("AT+CMGF=1\r"); //at command for send sms wait_ms(1000); clearString(); wait_ms(1000); SIM900.printf("AT+CMGS="); SIM900.putc('"'); SIM900.printf("+918553472606"); SIM900.putc('"'); SIM900.printf("\r"); wait_ms(1000); SIM900.printf("Hi Saleem, Food Storage in Utensil 2 : Rice is below the threshold Level, Kindly Check"); wait_ms(1000); SIM900.putc(0x1A); wait_ms(5000); } void sendSMS_Alert_utensil3() { clearString(); SIM900.printf("AT\r"); //at Command wait_ms(1000); clearString(); SIM900.printf("AT+CMGF=1\r"); //at command for send sms wait_ms(1000); clearString(); wait_ms(1000); SIM900.printf("AT+CMGS="); SIM900.putc('"'); SIM900.printf("+918553472606"); SIM900.putc('"'); SIM900.printf("\r"); wait_ms(1000); SIM900.printf("Hi Saleem, Food Storage in Utensil 3 : Liquid(Oil) Level is below the threshold Level, Kindly Check"); wait_ms(1000); SIM900.putc(0x1A); wait_ms(5000); } int main() { float tempC,tempF,a[10],avg; int i ; Buzzer = 0 ; led_pin1 = 0; led_pin2 = 0; led_pin3 = 0; Exchaust_Fan_pin = 0 ; // Messages on Terminal Appication pc.printf( "Hi, Welcome to Project Demo of Renesas GR Peach India Design Contest: \n"); wait(2.2); pc.printf( "GR Peach based Smart Home Food storage Maintenance and Monitoring Safety Alert System : \n"); pc.printf( " \n"); // pc.printf("\r\n Hi Saleem, Welcome to GSM 900 SMS Sending TEST using GR Peach \n"); // Messages on LCD 16x2 lcd.printf("Renesas GR Peach"); lcd.printf("Design Contest !\n"); pc.printf("Hello Saleem, 16x2 LCD is working \n") ; wait(5.0) ; SIM900.attach(&callback_rx); SIM900.baud(9600); // wait_ms(100); sendSMS(); // SEND Welcome SMS pc.printf("Hi Saleem, Welcome Message is Sent to your Mobile No : \n") ; while(1) { // Messages on LCD 16x2 lcd.printf("*GR Peach SMART*\n"); lcd.printf("HomeFood Monitor\n"); wait_ms(10); sendSMS1(); // SEND SMS wait_ms(100); pc.printf( " Project Demo of : GR Peach based Smart Home Food storage Maintenance and Monitoring Safety Alert System : \n"); myled = 1; wait(0.2); myled = 0; wait(0.2); pc.printf(" Success: LEDs On-Off Test is Successful: \n"); // Automatic Room Light -Using LDR pc.printf( " Smart Kitchen: Automatic Kitchen Room Light Monitoring using LDR \n"); wait(6.0) ; for (int j=0 ; j<2 ; j++) { if(LDR_pin < 0.1) { pc.printf(" Light intensity is low So turning on LED (%f) \n", LDR_pin.read()); led_pin1 = 1; wait (32.0) ; } else { pc.printf(" Light intensity is High So turning off the LED (%f) \n", LDR_pin.read()); led_pin1 = 0; wait (17.0) ; } } // end of for loop // Human Motion Detecion Program pc.printf( " Automatic Human Motion Detection using PIR Sensor \n"); wait(2.2) ; for (int j=0 ; j<2 ; j++) { if(PIR_pin == 1 ) { pc.printf("Human Motion is Detected So turning on LED bulb(%f) \n", PIR_pin.read()); led_pin2 = 1; wait (24.0) ; } else { pc.printf(" Human Motion is Not Detected So turning off the LED bulb (%f) \n", PIR_pin.read()); led_pin2 = 0; wait (12.0) ; } } // end of for loop // Flame Sensor Program to detect Fire pc.printf("Flame Sensor is Active now...\n"); wait(2.2) ; for (int j=0 ; j<2 ; j++) { if(Flame_sensor == 1) { Buzzer = 1; // turn on Buzzer pc.printf("Flame Sensor has Detected Fire, Buzzer is on...\n"); wait(15.2) ; Buzzer = 1; led_pin3=1 ; lcd.printf("*Alert: Fire *\n"); lcd.printf("Fire is Detected\n"); wait_ms(10); sendSMS_Fire_Alert(); // SEND SMS for Fire Alert pc.printf("Hi Saleem, Alert SMS is Sent to your Mobile No regarding Fire Detection: \n") ; wait(12.0) ; } else { Buzzer = 0 ; pc.printf("Flame Sensor Didnot Detect the Fire..\n"); led_pin3=0 ; wait(9.2); } } // end of for loop // MQ6 Smoke GAS Sensor Program for (int j=0 ; j<2 ; j++) { pc.printf("MQ6 Sensors started reading...\n"); pc.printf("Sensor value= 0x%4x, percentage= %3.3f%%\n\r",MQ6_Sensor.read(), MQ6_Sensor.read()*100.0f); wait(2.2) ; if(MQ6_Sensor > 0.08) { Buzzer = 1; // > 0.08 * Vcc wil turn on Buzzer ie, 0.08*5=0.4 will turn on Buzzer pc.printf("MQ6 Sensors Detected Smoke or GAS leakage, Buzzer is on...\n"); wait(16.2) ; Buzzer = 1; Exchaust_Fan_pin = 1 ; led_pin3=0; lcd.printf("*Alert: LPG GAS*\n"); lcd.printf("SMOKEis Detected\n"); wait (9.2); sendSMS_Smoke_LPG_Alert(); // SMS for Alert on Smoke and LPG Gas leakage wait(3.2) ; pc.printf("Hi Saleem, Alert SMS is Sent to your Mobile No regarding LPG Gas leakage and Smoke Detection: \n") ; } else { Buzzer = 0 ; led_pin3 = 0 ; pc.printf("MQ6 Sensors Didnot Detected Smoke or GAS leakage.\n"); wait(13.2); } } // end of for loop // Temparature LM35 Sensor Program avg=0; for(i=0;i<10;i++) { a[i]=LM35.read(); wait(.02); } for(i=0;i<10;i++) { avg=avg+(a[i]/10); } tempC=(avg*3.685503686*100); tempF=(9.0*tempC)/5.0 + 32.0; lcd.locate(0,0); lcd.printf(" Temperature "); lcd.locate(0,1); lcd.printf("%.2f C %.2f F",tempC,tempF); pc.printf( "The Temperature Recorded using LM35 Sensor is :%.2f C and %.2f F \n",tempC,tempF); wait(15.5); // Humidity Sensor Program for (int i=0;i