const String PHONE = "+9876543210";
#define rxPin 4
#define txPin 2
#define BAUD_RATE 9600
HardwareSerial sim800(1);
#define LED_PIN 23
#define PIR_SENSOR_PIN 14
String smsStatus,senderNumber,receivedDate,msg;
//
//
//bool led = false;
bool pirSensor = false;
//
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(PIR_SENSOR_PIN, INPUT);
}
//
void loop() {
//////////////////////////////////////////////////
while(sim800.available()){
parseData(sim800.readString());
}
//////////////////////////////////////////////////
while(Serial.available()) {
sim800.println(Serial.readString());
}
//////////////////////////////////////////////////
}
//***************************************************
void parseData(String buff){
Serial.println(buff);
unsigned int len, index;
//////////////////////////////////////////////////
index = buff.indexOf("\r");
buff.remove(0, index+2);
buff.trim();
//////////////////////////////////////////////////
if(buff != "OK"){
index = buff.indexOf(":");
String cmd = buff.substring(0, index);
cmd.trim();
buff.remove(0, index+2);
if(cmd == "+CMTI"){
index = buff.indexOf(",");
String temp = buff.substring(index+1, buff.length());
temp = "AT+CMGR=" + temp + "\r";
sim800.println(temp);
}
else if(cmd == "+CMGR"){
extractSms(buff);
if(senderNumber == PHONE){
doAction();
}
}
//////////////////////////////////////////////////
}
else{
}
}
//************************************************************
void extractSms(String buff){
unsigned int index;
index = buff.indexOf(",");
smsStatus = buff.substring(1, index-1);
buff.remove(0, index+2);
senderNumber = buff.substring(0, 11);
buff.remove(0,19);
receivedDate = buff.substring(0, 20);
buff.remove(0,buff.indexOf("\r"));
buff.trim();
index =buff.indexOf("\n\r");
buff = buff.substring(0, index);
buff.trim();
msg = buff;
buff = "";
msg.toLowerCase();
}
if (digitalRead(PIR_SENSOR_PIN) = HIGH)&& false) {
Reply ("indbrud")
// pirSensor = true;
}
}
void doAction(){
if (msg == "ARM") {
pirSensor = false;
Led = HIGH
Reply("PIR sensor armed");
} else if (message == "DISARM") {
pirSensor = true;
Led = LOW
Reply("PIR sensor disarmed");
}
smsStatus = "";
senderNumber="";
receivedDate="";
msg="";
}
void Reply(String text)
{
sim800.print("AT+CMGF=1\r");
delay(1000);
sim800.print("AT+CMGS=\""+PHONE+"\"\r");
delay(1000);
sim800.print(text);
delay(100);
sim800.write(0x1A);
delay(1000);
Serial.println("SMS Sent Successfully.");
delay(1000);
sim800.println("AT+CMGD=1,4");
delay(1000);
sim800.println("AT+CMGDA= \"DEL ALL\"");
delay(1000);
}
What am I missing here? ... you need to post your code properly (in code tags (</>), and tell us what the actual problem is?
are you missing the country code?
The problem is the output when the pir is trigged and the alarm is armed. I get a error when i try to compile it.
For which board? What errors?
Compilation error: 'doAction' was not declared in this scope.
Its a esp32 board and i think a arduino can run the code. I use the most of the code in a relay setup and the only change in code is in the end
This code(around line 101)
if (digitalRead(PIR_SENSOR_PIN) = HIGH) && false) {
Reply ("indbrud")
// pirSensor = true;
}
}
Is outside of any function, and is therefore illegal. You closed the previous function above this line.
Learn to auto-format your code in the IDE, then learn to observe what the formatter is showing you.
First fix the issue shown by @camsysca.
Then, In File>Preferences turn on "Show verbose output during compile" and work through all the warnings which are being treated as errors. There are many errors which need correcting.
I am struckling... my english is bad and i cant change the code to run in danish so to now i am learning the hard way. mostly using google translate and it givs me some time more problems then i came with.
This compiles for me
const String PHONE = "+9876543210";
#define rxPin 4
#define txPin 2
#define BAUD_RATE 9600
HardwareSerial sim800(1);
#define LED_PIN 23
#define PIR_SENSOR_PIN 14
String smsStatus, senderNumber, receivedDate, msg;
//
//
bool Led = false;
bool pirSensor = false;
//
void setup()
{
pinMode(LED_PIN, OUTPUT);
pinMode(PIR_SENSOR_PIN, INPUT);
}
//
void loop()
{
//////////////////////////////////////////////////
while (sim800.available())
{
parseData(sim800.readString());
}
//////////////////////////////////////////////////
while (Serial.available())
{
sim800.println(Serial.readString());
}
//////////////////////////////////////////////////
}
//***************************************************
void parseData(String buff)
{
Serial.println(buff);
//unsigned int len, index;
unsigned int index;
//////////////////////////////////////////////////
index = buff.indexOf("\r");
buff.remove(0, index + 2);
buff.trim();
//////////////////////////////////////////////////
if (buff != "OK")
{
index = buff.indexOf(":");
String cmd = buff.substring(0, index);
cmd.trim();
buff.remove(0, index + 2);
if (cmd == "+CMTI")
{
index = buff.indexOf(",");
String temp = buff.substring(index + 1, buff.length());
temp = "AT+CMGR=" + temp + "\r";
sim800.println(temp);
}
else if (cmd == "+CMGR")
{
extractSms(buff);
if (senderNumber == PHONE)
{
doAction();
}
}
//////////////////////////////////////////////////
}
else
{
}
}
//************************************************************
void extractSms(String buff)
{
unsigned int index;
index = buff.indexOf(",");
smsStatus = buff.substring(1, index - 1);
buff.remove(0, index + 2);
senderNumber = buff.substring(0, 11);
buff.remove(0, 19);
receivedDate = buff.substring(0, 20);
buff.remove(0, buff.indexOf("\r"));
buff.trim();
index = buff.indexOf("\n\r");
buff = buff.substring(0, index);
buff.trim();
msg = buff;
buff = "";
msg.toLowerCase();
}
/*
if (digitalRead(PIR_SENSOR_PIN) = HIGH)&& false)
{
Reply("indbrud")
// pirSensor = true;
}
}
*/
void doAction()
{
if (msg == "ARM")
{
pirSensor = false;
Led = HIGH;
Reply("PIR sensor armed");
}
//else if (message == "DISARM")
else if (msg == "DISARM")
{
pirSensor = true;
Led = LOW;
Reply("PIR sensor disarmed");
}
smsStatus = "";
senderNumber = "";
receivedDate = "";
msg = "";
}
void Reply(String text)
{
sim800.print("AT+CMGF=1\r");
delay(1000);
sim800.print("AT+CMGS=\"" + PHONE + "\"\r");
delay(1000);
sim800.print(text);
delay(100);
sim800.write(0x1A);
delay(1000);
Serial.println("SMS Sent Successfully.");
delay(1000);
sim800.println("AT+CMGD=1,4");
delay(1000);
sim800.println("AT+CMGDA= \"DEL ALL\"");
delay(1000);
}
thanks what do i do to get reply when the pir sensor gets trigged
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.