Sunday, 25 June 2017

Rain Detected then GSM Module Send Email using Arduino

Rain Detected then GSM Module Send Email using Arduino:


#include<SoftwareSerial.h>
SoftwareSerial mySerial(9,10); //RX,TX
int Analog_Out=A0;            //ANALOG INPUT
int Analog_In=0;
void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(Analog_Out,INPUT);    //DECLARE A0 AS INPUT
  delay(50);
}

void loop() {
  Analog_In=analogRead(Analog_Out); // SENSOR VALUE
  if(Analog_In<500)                 //when raindrop sensor detect analog value then value
                                          // will be reduce
  {
 
    Serial.println("It's Rainging Outside");
    SendEmail();                    //Send Mail to Gsm module GSM MODULE
    while(analogRead(Analog_Out)<800);//HOLDING STATE UNTIL RAIN STOP
  }
  else if(Analog_In>500 && Analog_In<800)   // this is for rain Warning
  {
    Serial.println("About To Rain");
  }
  else if(Analog_In>800)     //when not raining
  {
    Serial.println("It's Sunny Outside");
  }
delay(1000);
}


void SendEmail()        //SENDING EMAIL
{
  mySerial.println("AT");
  delay(100);
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"\r");  //CONFIGUREING BEARER PROFILE
  delay(10000);

  mySerial.println("AT+SAPBR=1,1");       //OPEN A GPRS CONTEXT
  delay(15000);
  mySerial.println("AT+SAPBR=2,1");      //QUERY THE GPRS CONTEXT
  delay(3000);
  mySerial.println("AT+EMAILCID=1");     //SET PARAMETERS OF EMAIL
  delay(4000);
  mySerial.println("AT+EMAILTO=30");    //REFRESHING IN EVERY 30 SEC IF NO WORKIS HAPPING  mySerial.println("AT+SMTPSRV=\"OUTGOING SERVER ID \",PORT_NO \r"); //SET SMTP SERVER ADDRESS AND PORT
  delay(5000);
    mySerial.println("AT+SMTPSRV=\"OUTGOING SERVER ID \",PORT_NO \r"); //SET SMTP SERVER ADDRESS AND PORT
    delay(3000);
  mySerial.println("AT+SMTPAUTH=1,\"USER_ID\",\"PASSWORD\"\r");   //SET SMTP ID & PASSWORD
  delay(8000);
  mySerial.println("AT+SMTPFROM=\"SENDER_EMAIL_ID\",\"SENDER_NAME\"\r");    //SET SENDER Email ID
  delay(6000);
  mySerial.println("AT+SMTPRCPT=0,0,\"TO_EMAIL_ADDRESS\",\"TO_NAME\"\r");         //SET RECIPIENT (TO:)
  delay(5000);
  mySerial.println("AT+SMTPRCPT=1,0,\"CC_TO_EMAIL_ADDRESS\",\"CC NAME\"\r");      //SET RECIPIENT(Cc:)
  delay(5000);
 mySerial.println("AT+SMTPRCPT=2,0,\"BCc_TO_MAIL_ADDRESS\",\"BCc NAME\"\r");    //SET RECIPIENT (BCc)
  delay(5000);
  mySerial.println("AT+SMTPSUB=\"FROM YOUR RAIN DROP DETACTOR\"\r");          //ENTER YOUR EMAIL SUBJECCT
  delay(5000);
  mySerial.println("AT+SMTPBODY");                                            // FOR EMAIL BODY
  delay(5000);
  mySerial.println("IT'S RAINING OUTSIDE.\n \n *Regards,*\n*Your GSM Module*");   //YOUR EMAIL BODY
  delay(1000);
  mySerial.println((char)26);                                             //FOR CTRL+Z
  delay(5000);
  mySerial.println("AT+SMTPSEND");                                        //EMAIL SEND
  delay(100000);
 }

Circuit Diagram:




0 comments:

Post a Comment

if you have any doubt please let me know