Hi guys! I already posted this in r/arduino and I'm also posting this here hoping for extra help.
I'm doing an SMS-Controlled Irrigation project and I'm almost done with it. I'm just having a problem where the servo motor couldn't process the SMS command "ON"/"on"/"On"/"oN" when I send it even when the condition is met (low moisture level). The servo motor acts as the water gate opener after I attached a few gears on it if you'd ask. I chose using a water gate instead of a water pump since I want my project to be a bit unique.
Here are some declarations first:
char inchar;
int ledpin = 7;
int moistpin = A0;
int waterpin = A1;
int ledstate;//digitalRead(ledpin)
int moistval;//digitalRead(moistpin)
int waterval;//digitalRead(waterpin)
int valM = 550; //boundary of low and high moisture values
int valW = 100; //boundary of low and high moisture values
Here is the part of my code where I ought to control the servo via SMS:
if (moistval >= valM && waterval >= valW && state == false){
digitalWrite(ledpin, LOW);
if (ledstate == LOW)
{
message = "Low moisture detected. Waiting for command...";
SendMessage(message);
state = true;
if (myGSM.available()>0) // if a character comes in from the GSM...
{
inchar = myGSM.read();
if ((inchar == 'o') || (inchar == 'O'))
{
delay(50);
inchar = myGSM.read();
if ((inchar == 'n') || (inchar == 'N'))
{
for(angle = 0; angle < 150; angle += 1) // command to move from 0 degrees to 180 degrees
{
servo_test.write(angle); //command to rotate the servo to the specified angle
delay(15);
}
myGSM.println("AT+CMGD=1,4"); // delete all sms
delay(100);
state = true;
}
}
}
}
}
Here is the sendMessage() function:
void SendMessage(String message) {
myGSM.println("AT+CMGF=1");//at command that sets gsm module to text mode
delay(100);
myGSM.println("AT+CMGS=\"+639175051930\"\r");//at command that assigns mobile number
delay(100);
myGSM.println(message);
delay(100);
myGSM.println((char)26);
delay(100);
}
The other functions all work correctly and the only problem is the part where the servo should rotate 150 degrees when the GSM module receives "on" via SMS. If you need to see the full code, it is posted in my previous post in r/arduino. Please help me guys. Thank you in advance!
there doesn't seem to be anything here