I am doing project using light dependent sensor (LDR), arduino UNO and GSM SIM900A.
The project is when LDR value below than 300, it will send multiple SMS on different phone no.
The problem the LDR show the value in serial monitor but no SMS was sent.
Below is the code:
#include <SoftwareSerial.h>
SoftwareSerial SIM900(2,3); //(Rx, Tx) Arduino
int toggle=0;
int sensor = 0;
void setup() {
Serial.begin(9600);
SIM900.begin(19200);
pinMode(A0,INPUT);//ldr input reading
}
void loop() {
sensor=analogRead(A0);
Serial.print("Sensor: ");
Serial.println(sensor);
if(sensor<300 && toggle==0)//ldr dark
{
Serial.println("LDR light value is less than 300");
sendSMS1();
Serial.println("Send SMS 1");
delay(1000);
sendSMS2();
Serial.println("Send SMS 2");
toggle=1;
}
if(sensor>300)
{
toggle=0;
}
}
void sendSMS1()
{
SIM900.print("AT+CMGF=1\r"); // AT command send SMS
delay(100);
SIM900.println("AT + CMGS = "+6*""); // * phone no
delay(100);
SIM900.println("WARNING! PLEASE TAKES AN ACTION IMMEDIATELY."); // Message to send delay(100);
SIM900.println((char)26); // End ATCommand a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(1000); // Delay 1 sec to send sms
SIM900.println("AT+CLTS=1");
SIM900.println("AT+CCLK?");
}
void sendSMS2()
{
SIM900.print("AT+CMGF=1\r"); // AT command send SMS
delay(100);
SIM900.println("AT + CMGS = "+6*""); // * phone no
delay(100);
SIM900.println("WARNING! PLEASE TAKES AN ACTION IMMEDIATELY."); // Message to send
delay(100);
SIM900.println((char)26); // End ATCommand a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(1000); // Delay 1 sec to send sms
SIM900.println("AT+CLTS=1");
SIM900.println("AT+CCLK?");
}
Can anybody tell what mistake I have or what should I do?
I am beginner to arduinos. Please help me if you know what is going on.