Hello everybody .
I`m building burglar alarm with sms alert with ir throughbeam sensors
I have a problem with the code
gsm modem sending sms even when the throughbeam is not broken
Can please anyone help me with this code:
#include "SIM900.h"
#include <SoftwareSerial.h>
#include "sms.h"
#include <Wire.h>
SMSGSM sms;
String smsText = "INTRUDER ";
boolean started = true;
char sms_text[160];
int ledPin = 13;
int SENSORPin = 4;
int val = HIGH;
#define SENSORPIN 4
// variables will change:
int sensorState = 0, lastState=0;
void setup()
{
pinMode (ledPin, OUTPUT);
pinMode(SENSORPIN, INPUT);
digitalWrite(SENSORPIN, HIGH); // turn on the pullup
Serial.begin(9600);
if (gsm.begin(9600))
{
Serial.println("\nstatus=READY");
started = true;
}
else
Serial.println("\nstatus=IDLE");
}
void loop ()
{
val = digitalRead(SENSORPin);
digitalWrite(ledPin, val);
if (val == 1)
{
Serial.println();
smsText = smsText;
smsText.toCharArray(sms_text, 160);
sms.SendSMS("0701548869", sms_text);
String smsText = "intruder ";
for(;;){ /*empty*/ }
}
}
Hmm. Are you sure the sensor pin is connected properly? It looks like you have it set to pull up when disconnected. When will it be pulled down?
for(;;){ /*empty*/ }
When will this loop exit? Unless the arduino will interrupt the loop() function somehow, it will never exit.
That may be because when the beam is broken the digital output will be zero. And so your if condition is wrong. Try this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
void loop ()
{
val = digitalRead(SENSORPin);
if (val == 0)
{
digitalWrite(ledpin, HIGH);
Serial.println();
smsText = smsText;
smsText.toCharArray(sms_text, 160);
sms.SendSMS("0701548869", sms_text);
String smsText = "intruder ";
for(;;){ /*empty*/ }
}
}
|
Edit: And yeah the for loop is an infinte loop so you should change it.
Last edited on