Send SMS to two different number when any fault is detected
fig1:GSM Module
PROGRAM
/* Send SMS to two different number when any fault is detected
pin 5 used to detect fault commenly any sensor
pin 7 to turn ON the whole system
pin12 turn OFF the power to the machine usually a relay
created 2017
by Alwin Thomas
modified 9 Apr 2017
by Arun Prabhakaran P
*/
const int SENSORPIN = 5;
const int RELAY = 12;
const int KEY = 7;
int s = 0;
void SendSMS()
{
Serial.print("AT+CMGF=1");
Serial.write(0x0D);
delay(2000);
Serial.print("AT+CMGS=");
Serial.write(0x22);
Serial.print("9048316362");
Serial.write(0x22);
Serial.write(0x0D);
delay(2000);
Serial.print(" WARNING! ");
Serial.print("POLLUTION DETECTED");
Serial.write(0x1A);
delay(3000);
/* Sending Message 2 */
Serial.print("AT+CMGF=1");
Serial.write(0x0D);
delay(2000);
Serial.print("AT+CMGS=");
Serial.write(0x22);
Serial.print("9746683166");
Serial.write(0x22);
Serial.write(0x0D);
delay(2000);
Serial.print(" POLLUTION DETECTED ");
Serial.write(0x1A);
delay(3000);
}
int SENSORSTATE = 0;
int RELAYSTATE = 0;
int KEYSTATE = 0;
void setup() {
Serial.begin(9600);
delay(100);
Serial.println("System Ready....");
pinMode(SENSORSTATE, INPUT);
pinMode(RELAY, OUTPUT);
pinMode(KEY, INPUT);
}
void loop() {
SENSORSTATE = digitalRead(SENSORPIN);
RELAYSTATE = digitalRead(RELAY);
KEYSTATE = digitalRead(KEY);
if ((digitalRead(KEY) == HIGH) && (digitalRead(SENSORPIN) == LOW)) {
Serial.println("Starting Vehicle");
digitalWrite(RELAY, HIGH);
s = 0;
}
else if ( (digitalRead(KEY) == HIGH) && (digitalRead(SENSORPIN) == 1) ) {
Serial.println("Sensor Error....");
digitalWrite(RELAY, LOW);
if (s == 0) {
Serial.println("Sending Message");
SendSMS();
s = 1;
}
}
else {
digitalWrite(RELAY, LOW);
}
}
fig :2
Arun Prabhakaran P,
+91 8907735577
(B.E ECE)
Comments
Post a Comment