const int analogPin1 = PIN_A0; // pin that the eb L1 sense
const int analogPin2 = PIN_A1; // pin that the eb L2 sense
const int analogPin3 = PIN_A2; // pin that the eb L3 sense
const int analogPin3 = PIN_A3; // pin that the dry run sense
const int threshold = 1023; // an arbitrary threshold level that's in the range of the analog input
int repeat = 0;
int LED = 8;
int motor = 9;
int buttonpushcounter =0;
int buttonstate =0;
int lastbuttonstate =0;
int temp=0;
int i=0;
char str[15];
void setup()
{
Serial.begin(9600);
pinMode(threshold , INPUT);
pinMode(motor,OUTPUT);
pinMode(LED,OUTPUT);
digitalWrite(motor,LOW);
digitalWrite(LED,LOW);
delay(5000);
delay(5000);
delay(5000);
Serial.println("AT+CNMI=2,2,0,0,0");
delay(1000);
Serial.println("AT+CMGF=1");
delay(1000);
// read the value of the potentiometer:
int analog1Value = analogRead(analogPin1);
int analog2Value = analogRead(analogPin2);
int analog3Value = analogRead(analogPin3);
Serial.println("Analog pin A0: " +String(analog1Value));
Serial.println( "Analog pin A1: " +String(analog2Value));
Serial.println("Analog pin A2: " +String(analog3Value));
delay(1000);
}
void loop()
{
buttonstate = analogRead (threshold);
if (buttonstate != lastbuttonstate)
{
if (buttonstate == threshold){
buttonpushcounter ++;
Serial.println("3 PHASE OK");
delay(1000);
//Serial.println("number of button pushes:");
//Serial.println(buttonpushcounter);
Serial.println("AT+CMGS=\"+919705422218\"\r"); // Replace x with mobile number
delay(1000);
Serial.println("system ready three phase available");// The SMS text you want to send
delay(1000);
Serial.println((char)26); // ASCII code of CTRL+Z
delay(1000);
} else {
if (buttonstate != lastbuttonstate)
Serial.println("3 PHASE NOT OK");
delay(1000);
//Serial.println("number of button pushes:");
//Serial.println(buttonpushcounter);
digitalWrite(motor,LOW);
digitalWrite(LED,LOW);
delay(1000);
Serial.println("AT+CMGS=\"+919705422218\"\r"); // Replace x with mobile number
delay(1000);
Serial.println("system ready but three phase not available");// The SMS text you want to send
delay(1000);
Serial.println((char)26); // ASCII code of CTRL+Z
delay(1000);
}
lastbuttonstate = buttonstate;
if (buttonpushcounter % 1 ==0){
}
}
if(temp==1)
{
check();
temp=0;
i=0;
delay(1000);
}
}
void serialEvent()
{
while(Serial.available())
{
if(Serial.find("/"))
{
delay(1000);
while (Serial.available())
{
char inChar=Serial.read();
str[i++]=inChar;
if(inChar=='/')
{
temp=1;
return;
}
}
}
}
}
void check()
{
if(!(strncmp(str,"motor on",8)))
{delay(1000); // delay in between reads for stability
// read the value of the potentiometer:
int analog1Value = analogRead(analogPin1);
int analog2Value = analogRead(analogPin2);
int analog3Value = analogRead(analogPin3);
Serial.println("Analog pin A0: " +String(analog1Value));
Serial.println( "Analog pin A1: " +String(analog2Value));
Serial.println("Analog pin A2: " +String(analog3Value));
if("analog1Value threshold", "analog2Value threshold", "analog3Value threshold"){
delay(100); // delay in between reads for stability
digitalWrite(motor,HIGH);
digitalWrite(LED,HIGH);
delay(1000);
Serial.println("AT+CMGS=\"+919705422218\"\r"); // Replace x with mobile number
delay(1000);
Serial.println("Motor Activated");// The SMS text you want to send
delay(100);
Serial.println((char)26); // ASCII code of CTRL+Z
delay(1000);
} else {
digitalWrite(motor,LOW);
digitalWrite(LED,LOW);
delay(1000);
Serial.println("AT+CMGS=\"+919705422218\"\r"); // Replace x with mobile number
delay(1000);
Serial.println("Motor deactivated due to three phase not available");// The SMS text you want to send
delay(100);
Serial.println((char)26); // ASCII code of CTRL+Z
delay(1000);
}
}
else if(!(strncmp(str,"motor off",9)))
{
digitalWrite(motor,LOW);
digitalWrite(LED,LOW);
delay(1000);
Serial.println("AT+CMGS=\"+919705422218\"\r"); // Replace x with mobile number
delay(1000);
Serial.println("Motor deactivated");// The SMS text you want to send
delay(100);
Serial.println((char)26); // ASCII code of CTRL+Z
delay(1000);
}
else if(!(strncmp(str,"test",4)))
{
Serial.println("AT+CMGS=\"+919705422218\"\r"); // Replace x with mobile number
delay(1000);
Serial.println("The System is Working Fine.");// The SMS text you want to send
delay(100);
Serial.println((char)26); // ASCII code of CTRL+Z
delay(1000);
}
}