throughbeam ir sensor with sms

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/ }
}
}

int SENSORPin = 4;
int val = HIGH;

#define SENSORPIN 4

Two names that differ only in case are NOT a good idea. Make up your mind which ONE you want to use and get rid of the other one.

With pullup resistors, HIGH means not pressed, so getting a message when the beam is not broken is not surprising.

Hmm, i have changed it

It is the same

Rapsbagge:
Hmm, i have changed it

It is the same

Then it is a hardware issue. We need to see a schematic.

Rapsbagge:
Hmm, i have changed it

It is the same

Did you deal with the last paragraph of Reply #1 ?

Post your latest code - we have no idea what changes you made.
And please use the code button </>

so your code looks like this

and is easy to copy to a text editor

…R

it`s working now :) :) :) :)

Rapsbagge: it`s working now :) :) :) :)

As an aid to other newcomers who may read your Thread please describe how you solved the problem.

...R