Click here to Skip to main content
14,691,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my project is automatic room light controller with visitor counter using arduino. my project was running correct upto this but the problem when we connected gsm module to our project because we have given a limit to thye room so when after limit exceeded using gsm a msg must be sent to the admin. Actual problem is when a limit exceeds,code is not coming out of loop and when we are trying to increment or decrement no. of persons using IR sensor but its not happening. Help me which loop i sholud use to send msg automatically

What I have tried:

<pre>#include<LiquidCrystal.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(3, 5);
char msg;
LiquidCrystal lcd(13,12,11,10,9,8);
#define in 14
#define out 19
#define relay 2
int count=0;
void IN()
{
    count++;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
}
void OUT()
{
  count--;
    lcd.clear();
    lcd.print("Person In Room:");
    lcd.setCursor(0,1);
    lcd.print(count);
    delay(1000);
}
void setup()
{
  lcd.begin(16,2);
  lcd.print("Visitor Counter");
  delay(2000);
  pinMode(in, INPUT);
  pinMode(out, INPUT);
  pinMode(relay, OUTPUT);
  lcd.clear();
  lcd.print("Person In Room:");
  lcd.setCursor(0,1);
  lcd.print(count);

 mySerial.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  Serial.println("GSM SIM900A BEGIN");
  Serial.println("Enter character for control option:");
  Serial.println("s : to send message");
  Serial.println();
  delay(100);
}


void loop()
{  

  if(digitalRead(in))
  IN();
  if(digitalRead(out))
  OUT();

  if(count<=0)
  {
    lcd.clear();
    digitalWrite(relay, LOW);
    lcd.clear();
    lcd.print("Nobody In Room");
    lcd.setCursor(0,1);
    lcd.print("Light Is Off");
    delay(200);
  }

  else
    digitalWrite(relay, HIGH);

        if(count>=3)
        {
          SendMessage();

        digitalWrite(relay, HIGH);
    delay(100);
    lcd.clear();
    lcd.print("Limit exceeded");
    lcd.setCursor(0,1);
    lcd.print(count);
   return;
      }
    //else
  //  digitalWrite(relay, LOW);


if (Serial.available()>0)
   switch(Serial.read())
  {
    case 's':
      SendMessage();
      break;
    case 'r':
      ReceiveMessage();
      break;
  }
 if (mySerial.available()>0)
 Serial.write(mySerial.read());
}

void SendMessage()
{
  mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);  // Delay of 1000 milli seconds or 1 second
  mySerial.println("AT+CMGS=\"+918419906897\"\r"); // Replace x with mobile number
  delay(1000);
  mySerial.println("GSM TEST:Limit of the room exceeded");// The SMS text you want to send
  delay(100);
   mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
   //Serial.end();
}

void ReceiveMessage()
{
  mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to recieve a live SMS
  delay(1000);
  if (mySerial.available()>0)
  {
    msg=mySerial.read();
    Serial.print(msg);
  }
}

void Response()
{
int count = 0;
Serial.println();
while(1)
{
if(Serial.available())
{
char data =Serial.read();
if(data == 'K'){Serial.println("OK");break;}
if(data == 'R'){Serial.println("GSM Not Working");break;}
}
count++;
delay(10);
if(count == 1000){Serial.println("GSM not Found");break;}

}
}
Posted
Updated 27-Jan-18 8:33am
v2

1 solution

I looks you have two issues: the IR sensor (or the code handling it) not working and the missing notification.
You could first mock the IR sensor (a simple way would be changing from if (digitalRead(in)) to if (1) in order to test the notification part of the code. Then you could face the people detection problem. There are many resources available on the web on this very topic, see, for instance Overview | PIR Motion Sensor | Adafruit Learning System[^].
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900