Hi,
We are new to Arduino and are trying to enable communication between a SIMCOM SIM900 GPRS Shield (mounted on a Arduino Uno) and an LDR sensor. When the sensor drops below a value I would like it to send a SMS. I can get both bits of code for the separate units to work (i.e message sent from SIM900 independently and output from LDR displayed in serial monitor) but when I try to put them together, many many error messages appear and I’m not sure what they mean.
Here is the code (that works) for the SIM900 Shield:
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
void setup()
{
SIM900.begin(19200);
SIM900power();
delay(20000); // give time to log on to network.
}
void SIM900power()
// software equivalent of pressing the GSM shield “power” button
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(5000);
}
void sendSMS()
{
SIM900.print(“AT+CMGF=1\r”); // AT command to send SMS message
delay(100);
SIM900.println(“AT + CMGS = “+44xxxxxxxxxx””); // recipient’s mobile number, in international format
delay(100);
SIM900.println(“Testing 123.”); // message to send
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(5000); // give module time to send SMS
SIM900power(); // turn off module
}
void loop()
{
sendSMS();
do {} while (1);
}
Here is the code for the LDR sensor circuit (without the “if” statement):
void setup()
{
Serial.begin(9600);
}
void loop()
{
int ldr = analogRead(A0);
Serial.println(ldr);
delay (500);
}
Here is the code that I have attempted to stitch together:
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);
void setup()
{
SIM900.begin(19200);
SIM900power();
delay(20000);
Serial.begin (9600);
}
void loop()
{
int ldr = analogRead(A0);
Serial.println(ldr);
delay (500);
if (ldr <500)
{
void SIM900power()
// software equivalent of pressing the GSM shield “power” button
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(5000);
}
void sendSMS()
{
SIM900.print(“AT+CMGF=1\r”); // AT command to send SMS message
delay(100);
SIM900.println(“AT + CMGS = “+44xxxxxxxxxx””); // recipient’s mobile number, in international format
delay(100);
SIM900.println(“Testing 123.”); // message to send
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(5000); // give module time to send SMS
SIM900power(); // turn off module
}
void loop()
{
sendSMS();
do {} while (1);
}
Every time the following error messages are displayed on compiling:
text_shield.ino: In function ‘void loop()’:
text_shield:23: error: a function-definition is not allowed here before ‘{’ token
text_shield:31: error: a function-definition is not allowed here before ‘{’ token
text_shield:46: error: a function-definition is not allowed here before ‘{’ token
text_shield:49: error: expected `}’ at end of input
I’m not sure what all the errors mean or even if we are going to right way about putting the two bits of code together.
Any help will be much appreciated. Thanks.