My program is not running

con st int motor = 10;

#include <LiquidCrystal.h>
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

#include <SoftwareSerial.h>
SoftwareSerial SIM900(9,8);
String textMessage;
String message, motorState;

void setup() {
pinMode(motor ,OUTPUT);

Serial.begin(19200);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("system is on");
delay(1500);

SIM900.begin(19200);
delay(3000);
Serial.print("SIM900 is ready to send receive sms");
SIM900.print("AT+CMGF=1\r"); // AT command to set SIM900 to SMS mode
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r"); // Set module to send SMS data to serial out upon receipt
delay(100);

SIM900.println("AT+CMGF=1"); // Replace x with mobile number
delay(1000);
SIM900.println("AT+CMGS= "+9183*******7"\r"); // Replace * with mobile number
delay(1000);
SIM900.println("System is On");// The SMS text you want to send
delay(100);
SIM900.println((char)26);// ASCII code of CTRL+Z
lcd.clear();
}

void loop() {

if(SIM900.available()>0){
textMessage = SIM900.readString();
Serial.print(textMessage);
delay(10);
}
if(textMessage.indexOf("motor on")>=0){
lcd.clear();
digitalWrite(motor, HIGH);
motorState = "on";
Serial.println("motor set to ON");
textMessage = "ON";
lcd.setCursor(0, 1 );
lcd.print("motor on");
delay(1000);
}
if(textMessage.indexOf("motor off")>=0){
// Turn off relay and save current state
digitalWrite(motor, LOW);
motorState = "off";
Serial.println("motor set to OFF");
textMessage = "OFF";
}
if(textMessage.indexOf("state motor")>=0){
String message = "motor1 is " + motorState;
sendSMS(message);
Serial.println("motor1 state resquest");
textMessage = "";
}

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

What exactly do you mean by "not running" ? If you don't get an error message when uploading it then the sketch is running

What should it do ?
What does it do ?
Which Arduino board are you using ?

Hello sandip_patil

Welcome to the worldbest Arduino forum ever.

I assume that you have written the programme by yourself, then it is quite easy to find the error.

There's a trick to figuring out why something isn't working:

Use a logic analyzer to see what happens.
Put Serial.print statements at various places in the code as diagnostic prints to see the values of variablesand determine whether they meet your expectations.

Have a nice day and enjoy coding in C++.

Hi @sandip_patil

welcome to the arduino-forum.
I'm pretty sure that you agree and will follow the way how to solve your problem mimimum 200 minutes faster.

This requires to invest 20 minutes of your precious time to read how to speedup solving your problems.

Directly after registering you got presented informations how to speed up solving your problem.
You should really read it.

please RE-edit your posting to present your code as a code-section

click on the pencil-icon below your posting and then re-edit your posting following this short tutorial

best regards Stefan

const int motor = 10;

There are more errors. Have you found any?

SIM900.println("AT+CMGS= "+918600787981"\r"); // Replace * with mobile number
C:\Users\lenovo\AppData\Local\Temp.arduinoIDE-unsaved2023104-6560-1ydkg9r.02zo\sketch_nov4a\sketch_nov4a.ino: In function 'void setup()':
C:\Users\lenovo\AppData\Local\Temp.arduinoIDE-unsaved2023104-6560-1ydkg9r.02zo\sketch_nov4a\sketch_nov4a.ino:30:40: error: expected ')' before string constant
SIM900.println("AT+CMGS= "+918600787981"\r"); // Replace * with mobile number
^~~~
C:\Users\lenovo\AppData\Local\Temp.arduinoIDE-unsaved2023104-6560-1ydkg9r.02zo\sketch_nov4a\sketch_nov4a.ino: In function 'void loop()':
C:\Users\lenovo\AppData\Local\Temp.arduinoIDE-unsaved2023104-6560-1ydkg9r.02zo\sketch_nov4a\sketch_nov4a.ino:64:1: error: 'sendSMS' was not declared in this scope
sendSMS(message);
^~~~~~~
C:\Users\lenovo\AppData\Local\Temp.arduinoIDE-unsaved2023104-6560-1ydkg9r.02zo\sketch_nov4a\sketch_nov4a.ino:67:15: error: a function-definition is not allowed here before '{' token
}void setup() {
^
C:\Users\lenovo\AppData\Local\Temp.arduinoIDE-unsaved2023104-6560-1ydkg9r.02zo\sketch_nov4a\sketch_nov4a.ino:72:13: error: a function-definition is not allowed here before '{' token
void loop() {
^
C:\Users\lenovo\AppData\Local\Temp.arduinoIDE-unsaved2023104-6560-1ydkg9r.02zo\sketch_nov4a\sketch_nov4a.ino:75:1: error: expected '}' at end of input
}
^

exit status 1

Compilation error: expected ')' before string constant
please help me to resolve.

balcony garden water system using dc motor

yes i found more error
SIM900.println("AT+CMGF=1"); // Replace x with mobile number

delay(1000);

SIM900.println("AT+CMGS="+918600787981"\r"); // Replace * with mobile number

delay(1000);

SIM900.println("System is On");// The SMS text you want to send

delay(100);

SIM900.println((char)26);// ASCII code of CTRL+Z

lcd.clear();

}

Try fixing these errors:

This is line 30. It is written wrong:

SIM900.println("AT+CMGS= "+9183*******7"\r"); // Replace * with mobile number

This is line 64... you do not have a function written, or a library included with this function:

sendSMS(message);

This means you are missing a close brace (to close void loop() function)

plz reply with solution

The corrections to the three errors (above) should be the solution. Let's fix the last one... Here is the last error:

72:13: error: a function-definition is not allowed here before '{' token

This says, on line 72, character 13, something "is not allowed" before an open brace '{'
In the code you posted, there is no "line 72", your code stops at 68, but if you look at the top line of your code, you can see the remains of what was a line:

con st int Motor = 10;

Which should probably be:

const int Motor = 10;

On closer reading, Motor pin 10 is OUTPUT, and is HIGH oR LOW (enable/disable?). I will guess that the first three lines were the author's identifying information.

Well, to put that as the first line of your code is not standard; why define a motor pin if no motor object was declared? I suspect the first three lines to be something like:

#include <Stepper.h>
Stepper motor; // create an object/instance of Stepper
// empty line number 3 + 68 = 72.

So, back down to line 68... Here is what the formatted code looks like:

  if (textMessage.indexOf("state motor") >= 0) {
    String message = "motor1 is " + motorState;
    sendSMS(message);
    Serial.println("motor1 state resquest");
    textMessage = "";
  } // there are two spaces before this close brace...

The last line (above) has an extra tab at the beginning... combine that with the error wanting a close brace '}' before the next open brace '{'... you should insert a close brace...

  if (textMessage.indexOf("state motor") >= 0) {
    String message = "motor1 is " + motorState;
    sendSMS(message);
    Serial.println("motor1 state resquest");
    textMessage = "";
  } // there are two spaces before this close brace...
} // added this close brace to complete loop()... no spaces before this close brace.

Now, at line #72, there should be a function named sendSMS()... but there is not... that error still remains to be fixed.

Your turn to fix errors 1 and 2.

The second error...

Says... line 30, character 40 is missing a close parenthesis... but... this is the line of code:

  SIM900.println("AT+CMGS= " + 9183 8008135"\r"); // Replace * with mobile number

The formatting is not correct, probably from a copy/paste into a forum that considers the "backwards diagonal" slash "\" to be an "escape" character... the formatting of this line should have been:

   SIM900.println("AT+CMGS = \"+91838008135\"");

You can see the previously missing backward slash \ before second double quote. The backslash tells the code to use the next character as part of the string (telephone number) to be used as the argument for AT+CMGS. Next you see the removal of the incorrect "\r". Then the "escaped" third double quote finishes the CMGS string, then the last double quote to finish the println(); string.

Your turn to fix the last one. Give it a try.

Okay, you are a shy one. Let me help. This might be close to what the original author wrote, maybe not, in the missing sendSMS() function...

void sendSMS(String messageData) {
// remove comment marks if ATH command was used
//  SIM900.println("AT + CMGS = \"+91838008135\""); // mobile number
//  delay(100);
  SIM900.print(messageData);
  delay(100);
  SIM900.println((char)26);  // End AT command with a ^Z, ASCII code 26
  delay(100);
  SIM900.println();
  delay(5000);  // delay for sending SMS
}

First step of solution:

Use <code> for your code.

Questions?

Hi, @ledsyn

To add code please click this link;

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.