element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs Please help in checking ir, pir sensors and gps and accordingly sending data via gsm module
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Former Member
  • Date Created: 11 Apr 2016 6:15 PM Date Created
  • Views 432 views
  • Likes 0 likes
  • Comments 0 comments
Related
Recommended

Please help in checking ir, pir sensors and gps and accordingly sending data via gsm module

Former Member
Former Member
11 Apr 2016

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

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube