Checking ir, pir sensors and gps and accordingly sending data via gsm module

hi
i am working on a project theft intimation of vehicles using gsm and tracking it by gps.
here i am getting stuck with the infinite loop used in gps as it is continuously sending the lattitude and longitude. i also have to check 4 ir sensors and a pir sensor continuously.
please help me urgently for how am i going to use two loops in a program, out of which one is infinite loop.
the codes i am using are
#include<SoftwareSerial.h>
#include<TinyGPS.h>

long lat, lon;
int ir1 = 4;
int ir2 = 5;
int ir3 = 6;
int ir4 = 7;
int pir = 8;
int out = 9;

SoftwareSerial gpsSerial(2,3);
TinyGPS gps;

void setup()
{
pinMode(ir1, INPUT);
pinMode(ir2, INPUT);
pinMode(ir3, INPUT);
pinMode(ir4, INPUT);
pinMode(pir, INPUT);
pinMode(out, OUTPUT);

Serial.begin(9600);
delay(100);

gpsSerial.begin(9600);
send_sms (“ANUPAM YOUR CAR IS BEING ACCESSED BY SOMEONE”);
send_sms (“AND THE POSITION OF YOUR CAR IS :”);
}

//void loop() {}

void send_sms (char msg)
{
Serial.println(“AT”);
delay(2000);
Serial.println(“ATE0”);
Serial.println(’\r’);
delay(1000);
Serial.println(“AT+CMGF=1”);
Serial.println(’\r’);
delay(1000);
Serial.println(“AT+CMGS=“9453894151"”);
Serial.println(’\r’);
delay(1000);
Serial.println(msg);
Serial.println(”\x1A");
delay(1000);
}

void send_sms2 (long x, long y)
{
Serial.println(“AT”);
delay(2000);
Serial.println(“ATE0”);
Serial.println(’\r’);
delay(1000);
Serial.println(“AT+CMGF=1”);
Serial.println(’\r’);
delay(1000);
Serial.println("AT+CMGS=“9453894151"”);
Serial.println(’\r’);
delay(1000);
Serial.print("Position: ");
Serial.print("lat: “);Serial.print(x);Serial.print(” ");
Serial.print(“lon: “);Serial.println(y);
Serial.println(”\x1A”);

delay(1000);
}

void loop()
{
while(gpsSerial.available())
{
if(gps.encode(gpsSerial.read()))
{
gps.get_position(&lat,&lon);
send_sms2(lat,lon);
}
}
}

and the code for sensors is

#define ir1 4
#define ir2 5
#define ir3 6
#define ir4 7
#define pir 8
#define out 9

boolean flag_1 = LOW;

void setup()
{
pinMode(ir1, INPUT);
pinMode(ir2, INPUT);
pinMode(ir3, INPUT);
pinMode(ir4, INPUT);
pinMode(pir, INPUT);
pinMode(out, OUTPUT);
}

void loop()
{

/* if((digitalRead(ir1) == HIGH) || (digitalRead(ir2) == HIGH) || (digitalRead(ir3) == HIGH) || (digitalRead(ir4) == HIGH) || (digitalRead(pir) == HIGH))
{
digitalWrite(out,HIGH);
flag_1 = HIGH;
}
else
{
digitalWrite(out,LOW);
}*/
if (digitalRead(ir1) == HIGH)
{
digitalWrite(out,HIGH);
}
else
{
digitalWrite(out,LOW);
}

if (digitalRead(ir2) == HIGH)
{
digitalWrite(out,HIGH);
}
else
{
digitalWrite(out,LOW);
}

if (digitalRead(ir3) == HIGH)
{
digitalWrite(out,HIGH);
}
else
{
digitalWrite(out,LOW);
}

if (digitalRead(ir4) == HIGH)
{
digitalWrite(out,HIGH);
}
else
{
digitalWrite(out,LOW);
}

if (digitalRead(pir) == HIGH)
{
digitalWrite(out,HIGH);
}
else
{
digitalWrite(out,LOW);
}

}

please help to merge these two codes in one

project3sensors.ino (1.03 KB)

project4.ino (1.54 KB)

Hi Anipam,

How often do you want to make your sensor readings and how often do you want to log the data to your GSM link?

Pat.

sir,
THANK YOU FOR YOUR RESPONSE
the basic idea of my project is to check the sensors reading continuously and whenever a high output comes from it i have to send a message to the owner of the vehicle, that his or her vehicle is being accessed by someone unknown and at the same time i have to switch on a solenoidal valve which will stop the flow of fuel to the vehicle and finally it will stop due to lack of fuel.
after this part i have to continuously send the latitude and longitude position of my vehicle from gps module with the help of my gsm to the vehicle owner.

Thanks for the clarification. I would break your loops apart and perform the steps in the following order:

In loop:

Check sensor

If sensor triggered, then energize the solenoid and then start reading and sending the GPS coordinates.

It doesn't sound like you need to read the GPS until the vehicle is stolen.