GSM BASED PROJECT - PHASE 1
#include <SoftwareSerial.h> SoftwareSerial mySerial(2,3); long microsecondsToInches(); long microsecondsToCentimeters(); void StatusCheck(); const int trigPin =12; const int echoPin =13; const int trigPin1= 6; const int echoPin1= 7; const int Buzzer = 10; // Buzzer pin int xpin = A0; int pin1 =9; float n,a,b; int m; int sms_count=1, sms_count_wet=1; long duration,inches,cm; void setup() { mySerial.begin(9600); // Setting the baud rate of GSM Module Serial.begin(9600); // Setting the baud rate of Serial Monitor (Arduino) delay(100); pinMode(Buzzer, OUTPUT); pinMode(pin1,OUTPUT); } void loop() { StatusCheck(); CheckSurrounding(); CheckType(); } void CheckSurrounding() { a=CheckENV(); if(a<20) { delay(2000); b=CheckENV(); if(b<20) { digitalWrite(Buzzer, HIGH); // turn on buzzer delay(3000); // wait for 3 seconds digitalWrite(Buzzer, LOW); // buzzer off } } } void StatusCheck() { n=CheckLevel(); if(n > 45 && n < 60) { delay(3000); if(n > 45 && n < 60) { Serial.print(" \n DUSTBIN IS EMPTY \n"); sms_count=1; sms_count_wet=1; } } if(n < 10) { Serial.print("SECOND CHECK!!\n"); delay(3000); m=CheckLevelTrue(); if (m == 1) { Serial.print("ALERT!!\n"); Alert(); } else Serial.print("NO ALERT!!\n"); } } void CheckType() { int var = analogRead(xpin); if (var < 900) { Serial.print("WASTE IS WET\n"); if (sms_count_wet==1) { Serial.print("sms_count_wet=1\n"); SendMessageWet(); sms_count_wet=0; } } else Serial.print("WASTE IS DRY \n"); Serial.print("\n"); delay(1000); } float CheckENV() { pinMode(trigPin1,OUTPUT); digitalWrite(trigPin1,LOW); delayMicroseconds(2); digitalWrite(trigPin1,HIGH); delayMicroseconds(10); digitalWrite(trigPin1,LOW); pinMode(echoPin1,INPUT); duration=pulseIn(echoPin1,HIGH); inches= microsecondsToInches(duration); cm= microsecondsToCentimeters(duration); //Serial.print(inches); //Serial.print("in, Surroundings "); //Serial.print(cm); //Serial.print("cm , Surroundings"); //Serial.println(); delay(100); return cm; } float CheckLevel() { pinMode(trigPin,OUTPUT); digitalWrite(trigPin,LOW); delayMicroseconds(2); digitalWrite(trigPin,HIGH); delayMicroseconds(10); digitalWrite(trigPin,LOW); pinMode(echoPin,INPUT); duration=pulseIn(echoPin,HIGH); inches= microsecondsToInches(duration); cm= microsecondsToCentimeters(duration); Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(100); return cm; } int CheckLevelTrue() { pinMode(trigPin,OUTPUT); digitalWrite(trigPin,LOW); delayMicroseconds(2); digitalWrite(trigPin,HIGH); delayMicroseconds(10); digitalWrite(trigPin,LOW); pinMode(echoPin,INPUT); duration=pulseIn(echoPin,HIGH); inches= microsecondsToInches(duration); cm= microsecondsToCentimeters(duration); Serial.print(inches); Serial.print("check in, "); Serial.print(cm); Serial.print("check cm"); Serial.println(); delay(100); if(cm < 10) { return 1; } else return 0; } void Alert() { Serial.print("\n SMS COUNT \n"); Serial.print(sms_count); if(sms_count==1) { delay(100); SendMessage(); sms_count=0; } } void SendMessage() { mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode delay(2000); // Delay of 1000 milli seconds or 1 second mySerial.println("AT+CMGS=\"+917259592096\"\r"); // Replace x with mobile number delay(2000); mySerial.println("ECE LAB DUSTBIN FULL , PLEASE ADDRESS ME !!!");// The SMS text you want to send delay(200); mySerial.println((char)26);// ASCII code of CTRL+Z delay(5000); mySerial.println("ECE LAB DUSTBIN FULL , PLEASE ADDRESS ME !!!"); } void SendMessageWet() { mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode delay(2000); // Delay of 1000 milli seconds or 1 second mySerial.println("AT+CMGS=\"+917259592096\"\r"); // Replace x with mobile number delay(2000); mySerial.println("WET WASTE FOUND IN ECE LAB DUSTBIN !!!");// The SMS text you want to send delay(200); mySerial.println((char)26);// ASCII code of CTRL+Z delay(5000); mySerial.println("WET WASTE FOUND IN ECE LAB DUSTBIN !!!"); } long microsecondsToInches(long microseconds) { return microseconds/74/2; } long microsecondsToCentimeters(long microseconds) { return microseconds/29/2; }
No comments:
Post a Comment