String apaAja = "";
String msg = "";
String textMode = "AT+CMGF=1\r\n";
bool smsFlagOff;
bool smsFlag1;
bool smsFlag2;
bool smsFlag3;
bool feedBack1;
bool feedBack2;
bool feedBack3;
bool sukses = 0;
bool siap = 0;
unsigned int errorCounter;
int r1 = 2;
int r2 = 3;
int r3 = 4;
int ledIndikator = 7;
int reSet = 8;
int inv1 = 10;
int inv2 = 11;
int inv3 = 12;
void setup()
{
digitalWrite(reSet, HIGH);
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
pinMode(inv1, INPUT_PULLUP);
pinMode(inv2, INPUT_PULLUP);
pinMode(inv3, INPUT_PULLUP);
pinMode(r1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(r3, OUTPUT);
pinMode(reSet, OUTPUT);
pinMode(ledIndikator, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (Serial.available())
{
apaAja += (char)Serial.read();
}
else
{
feedBack1 = digitalRead(inv1);
feedBack2 = digitalRead(inv2);
feedBack3 = digitalRead(inv3);
if (apaAja.indexOf("OK") >= 0)
{
digitalWrite(ledIndikator, HIGH);
siap = 1;
errorCounter = 0;
apaAja.remove(0);
}
if (apaAja.indexOf("ERROR") >= 0)
{
siap = 0;
errorCounter = 0;
apaAja.remove(0);
}
if (siap == 0)
{
Serial.print(textMode);
digitalWrite(ledIndikator, HIGH);
delay(10);
digitalWrite(ledIndikator, LOW);
delay(290);
errorCounter++;
if (errorCounter == 40)
{
digitalWrite(reSet, LOW);
}
}
if (feedBack1 == 0 && smsFlag1 == 0 && siap == 1)
{
delay (3000);
feedBack1 = digitalRead(inv1);
if (feedBack1 == 0)
{
msg = "Speed 1, 50Hz";
sms();
smsFlag1 = 1;
}
}
if (feedBack2 == 0 && smsFlag2 == 0 && siap == 1)
{
delay (3000);
feedBack2 = digitalRead(inv2);
if (feedBack2 == 0)
{
msg = "Speed 2, 40Hz";
sms();
smsFlag2 = 1;
}
}
if (feedBack3 == 0 && smsFlag3 == 0 && siap == 1)
{
delay (3000);
feedBack3 = digitalRead(inv3);
if (feedBack3 == 0)
{
msg = "Speed 3, 35Hz";
sms();
smsFlag3 = 1;
}
}
if (feedBack1 == 1 && feedBack2 == 1 && feedBack3 == 1 && smsFlagOff == 0 && siap == 1)
{
delay (3000);
feedBack1 = digitalRead(inv1);
feedBack2 = digitalRead(inv2);
feedBack3 = digitalRead(inv3);
if (feedBack1 == 1 && feedBack2 == 1 && feedBack3 == 1)
{
smsFlagOff = 1;
msg = "Speed 0, OFF";
sms();
}
}
if (apaAja.indexOf("Speed 1") >= 0)
{
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
errorCounter = 0;
smsFlagOff = 0;
smsFlag1 = 0;
smsFlag2 = 0;
smsFlag3 = 0;
apaAja.remove(0);
}
if (apaAja.indexOf("Speed 2") >= 0)
{
digitalWrite(r1, LOW);
digitalWrite(r2, LOW);
digitalWrite(r3, HIGH);
errorCounter = 0;
smsFlagOff = 0;
smsFlag1 = 0;
smsFlag2 = 0;
smsFlag3 = 0;
apaAja.remove(0);
}
if (apaAja.indexOf("Speed 3") >= 0)
{
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(r3, LOW);
errorCounter = 0;
smsFlagOff = 0;
smsFlag1 = 0;
smsFlag2 = 0;
smsFlag3 = 0;
apaAja.remove(0);
}
if (apaAja.indexOf("Off") >= 0)
{
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
errorCounter = 0;
smsFlagOff = 0;
smsFlag1 = 0;
smsFlag2 = 0;
smsFlag3 = 0;
apaAja.remove(0);
}
}
}
void sms()
{
Serial.print("AT+CMGS=");
Serial.print("\"");
Serial.print("082210028004");
Serial.print("\"");
Serial.print("\r");
delay (250);
Serial.print(msg);
Serial.print((char)26);
apaAja.remove(0);
indikatorProsesSms();
}
void indikatorProsesSms()
{
for (int kedip = 0; kedip < 50; kedip++)
{
digitalWrite(ledIndikator, LOW);
delay(75);
digitalWrite(ledIndikator, HIGH);
delay(10);
}
}
READMORE
String msg = "";
String textMode = "AT+CMGF=1\r\n";
bool smsFlagOff;
bool smsFlag1;
bool smsFlag2;
bool smsFlag3;
bool feedBack1;
bool feedBack2;
bool feedBack3;
bool sukses = 0;
bool siap = 0;
unsigned int errorCounter;
int r1 = 2;
int r2 = 3;
int r3 = 4;
int ledIndikator = 7;
int reSet = 8;
int inv1 = 10;
int inv2 = 11;
int inv3 = 12;
void setup()
{
digitalWrite(reSet, HIGH);
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
pinMode(inv1, INPUT_PULLUP);
pinMode(inv2, INPUT_PULLUP);
pinMode(inv3, INPUT_PULLUP);
pinMode(r1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(r3, OUTPUT);
pinMode(reSet, OUTPUT);
pinMode(ledIndikator, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (Serial.available())
{
apaAja += (char)Serial.read();
}
else
{
feedBack1 = digitalRead(inv1);
feedBack2 = digitalRead(inv2);
feedBack3 = digitalRead(inv3);
if (apaAja.indexOf("OK") >= 0)
{
digitalWrite(ledIndikator, HIGH);
siap = 1;
errorCounter = 0;
apaAja.remove(0);
}
if (apaAja.indexOf("ERROR") >= 0)
{
siap = 0;
errorCounter = 0;
apaAja.remove(0);
}
if (siap == 0)
{
Serial.print(textMode);
digitalWrite(ledIndikator, HIGH);
delay(10);
digitalWrite(ledIndikator, LOW);
delay(290);
errorCounter++;
if (errorCounter == 40)
{
digitalWrite(reSet, LOW);
}
}
if (feedBack1 == 0 && smsFlag1 == 0 && siap == 1)
{
delay (3000);
feedBack1 = digitalRead(inv1);
if (feedBack1 == 0)
{
msg = "Speed 1, 50Hz";
sms();
smsFlag1 = 1;
}
}
if (feedBack2 == 0 && smsFlag2 == 0 && siap == 1)
{
delay (3000);
feedBack2 = digitalRead(inv2);
if (feedBack2 == 0)
{
msg = "Speed 2, 40Hz";
sms();
smsFlag2 = 1;
}
}
if (feedBack3 == 0 && smsFlag3 == 0 && siap == 1)
{
delay (3000);
feedBack3 = digitalRead(inv3);
if (feedBack3 == 0)
{
msg = "Speed 3, 35Hz";
sms();
smsFlag3 = 1;
}
}
if (feedBack1 == 1 && feedBack2 == 1 && feedBack3 == 1 && smsFlagOff == 0 && siap == 1)
{
delay (3000);
feedBack1 = digitalRead(inv1);
feedBack2 = digitalRead(inv2);
feedBack3 = digitalRead(inv3);
if (feedBack1 == 1 && feedBack2 == 1 && feedBack3 == 1)
{
smsFlagOff = 1;
msg = "Speed 0, OFF";
sms();
}
}
if (apaAja.indexOf("Speed 1") >= 0)
{
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
errorCounter = 0;
smsFlagOff = 0;
smsFlag1 = 0;
smsFlag2 = 0;
smsFlag3 = 0;
apaAja.remove(0);
}
if (apaAja.indexOf("Speed 2") >= 0)
{
digitalWrite(r1, LOW);
digitalWrite(r2, LOW);
digitalWrite(r3, HIGH);
errorCounter = 0;
smsFlagOff = 0;
smsFlag1 = 0;
smsFlag2 = 0;
smsFlag3 = 0;
apaAja.remove(0);
}
if (apaAja.indexOf("Speed 3") >= 0)
{
digitalWrite(r1, LOW);
digitalWrite(r2, HIGH);
digitalWrite(r3, LOW);
errorCounter = 0;
smsFlagOff = 0;
smsFlag1 = 0;
smsFlag2 = 0;
smsFlag3 = 0;
apaAja.remove(0);
}
if (apaAja.indexOf("Off") >= 0)
{
digitalWrite(r1, HIGH);
digitalWrite(r2, HIGH);
digitalWrite(r3, HIGH);
errorCounter = 0;
smsFlagOff = 0;
smsFlag1 = 0;
smsFlag2 = 0;
smsFlag3 = 0;
apaAja.remove(0);
}
}
}
void sms()
{
Serial.print("AT+CMGS=");
Serial.print("\"");
Serial.print("082210028004");
Serial.print("\"");
Serial.print("\r");
delay (250);
Serial.print(msg);
Serial.print((char)26);
apaAja.remove(0);
indikatorProsesSms();
}
void indikatorProsesSms()
{
for (int kedip = 0; kedip < 50; kedip++)
{
digitalWrite(ledIndikator, LOW);
delay(75);
digitalWrite(ledIndikator, HIGH);
delay(10);
}
}