i want to control led throught sms when i send sms pompeon led should turn on and when i send sms pompeoff led should turn off and when led turn off PIR sensor should start work
sometime sms part working fine and sometime no i dont know why but PIR sensor is not working i have attached code down there
sketch_may04a.ino (3.56 KB)
//#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
#include "gsm.h"
//#include "string.h"
#define DEBUG_CODE_ON
#define DEBUG_ACTION_ON
SMSGSM sms;
boolean started=false;
boolean startSMS=false;
char smsbuffer[160];
char n_in[16];
char n_ref[12] = "60172543861";
char msg[1];
char pompe_on[160] = "Pompeon";
char pompe_off[160] = "Pompeoff";
char vanne_on[160] = "Vanneon";
char vanne_off[160] = "Vanneoff";
int swtch=13;
int PIRSensor=2;
void setup()
{
// digit
pinMode(swtch, OUTPUT);
pinMode(PIRSensor, INPUT);
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
// GSM START
if (gsm.begin(9600))
{
Serial.println("\nstatus=READY");
started=true;
}
else Serial.println("\nstatus=IDLE");
if(started){
#ifdef DEBUG_CODE_ON
Serial.println("mise en ligne");
#endif
gsm.SimpleWriteln("AT+CMEE=2");
delay(5000);
#ifdef DEBUG_CODE_ON
Serial.print("AT+CMEE=2");
gsm.WhileSimpleRead();
#endif
//
// PIN CODE
//
#ifdef DEBUG_CODE_ON
Serial.println("PIN CODE");
#endif
//if (gsm.SendATCmdWaitResp("AT+CPIN ?", 1000, 100, "READY", 5) != 1 )
// {
gsm.SimpleWriteln("AT+CPIN=2343");
delay(5000);
#ifdef DEBUG_CODE_ON
Serial.print("AT+CPIN=####");
gsm.WhileSimpleRead();
#endif
// }
//
// INIT FOR SEND SMS
//
gsm.SimpleWriteln("AT+CLIP=1");
delay(500);
#ifdef DEBUG_CODE_ON
Serial.print("AT+CLIP=1");
gsm.WhileSimpleRead();
#endif
gsm.SimpleWriteln("AT+CSCA ?");
delay(5000);
#ifdef DEBUG_CODE_ON
Serial.print("AT+CSCA ?");
gsm.WhileSimpleRead();
#endif
gsm.SimpleWriteln("AT+CMGF=1");
delay(5000);
#ifdef DEBUG_CODE_ON
Serial.print("AT+CMGF=1");
gsm.WhileSimpleRead();
#endif
//
// CMD LOW
//
#ifdef DEBUG_ACTION_ON
Serial.println("INIT PUMP");
#endif
digitalWrite(swtch, LOW);
}
};
void PIRON(){
if(digitalRead(PIRSensor)==HIGH){ // read the input pin
digitalWrite(swtch, HIGH); // sets the LED to the button's value
delay(1000);
digitalWrite(swtch, LOW); // delay in milisecond. 3000 = 3 second
}
}
void loop()
{
if(started)
{
//
// READ SMS
//
#ifdef DEBUG_ACTION_ON
Serial.println("Wait Read sms");
#endif
if(gsm.readSMS(smsbuffer, 16, n_in, 12))
{
#ifdef DEBUG_ACTION_ON
Serial.println(n_in);
Serial.println(smsbuffer);
#endif
//
// filter num gsm
//
if (memcmp(n_in,n_ref,11)==0)
{
#ifdef DEBUG_ACTION_ON
Serial.println("Sender ok");
#endif
// ok
startSMS=true;
}
}
//
// Action
//
if (startSMS){
//
// pump
//
if (memcmp(smsbuffer,pompe_on,7)==0)
{
digitalWrite(swtch, HIGH);
#ifdef DEBUG_ACTION_ON
Serial.println("Pump On");
#endif
}
if (memcmp(smsbuffer,pompe_off,7)==0)
{
digitalWrite(swtch, LOW);
PIRON();
#ifdef DEBUG_ACTION_ON
Serial.println("Pump Off");
#endif
}
//
// valve
//
/*
if (memcmp(smsbuffer,vanne_on,7)==0)
{
digitalWrite(12, LOW);
#ifdef DEBUG_CODE_ON
Serial.println("Valve On");
#endif
}
if (memcmp(smsbuffer,vanne_off,7)==0)
{
digitalWrite(12, LOW);
#ifdef DEBUG_CODE_ON
Serial.println("Valve Off");
#endif
}
*/
startSMS=false;
// clear SMS
gsm.SimpleWriteln("AT+CMGL=\"REC UNREAD\",0");
}
}
delay(500);
};
Does the LED ever come on?
What happens if you control the PIR input pin by connecting it to 5V or gnd?
Do you get the debug output you expect?
yes sometime its working fine with sms but some time no and PIR never work with sms part i dont know why but if i juts put code for PIR only it workd fine
i just want that when i send sms to turn off led PIR sensor should start work