我不能增加或减少否。循环运行时的人员 [英] I cant increment or decrement no. Of persons when the loop is running

查看:83
本文介绍了我不能增加或减少否。循环运行时的人员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目是自动室内灯光控制器,带有使用arduino的访客计数器。我的项目运行正确,但是当我们将gsm模块连接到我们的项目时问题是因为我们已经限制了这个房间,所以当使用gsm超出限制后,必须向管理员发送一个msg。实际问题是当超出限制时,代码不会出现循环,以及当我们尝试增加或减少否时。使用红外传感器的人但没有发生。帮助我sholud使用哪个循环自动发送消息



我尝试过:



< 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(房间里的人:);
lcd.setCursor(0,1);
lcd.print(count);
延迟(1000);
}
无效OUT()
{
count--;
lcd.clear();
lcd.print(房间里的人:);
lcd.setCursor(0,1);
lcd.print(count);
延迟(1000);
}
void setup()
{
lcd.begin(16,2);
lcd.print(访客柜台);
delay(2000);
pinMode(in,INPUT);
pinMode(out,INPUT);
pinMode(relay,OUTPUT);
lcd.clear();
lcd.print(房间里的人:);
lcd.setCursor(0,1);
lcd.print(count);

mySerial.begin(9600); //设置GSM模块的波特率
Serial.begin(9600); //设置串口监视器(Arduino)的波特率
Serial.println(GSM SIM900A BEGIN);
Serial.println(输入控制选项的字符:);
Serial.println(s:发送消息);
Serial.println();
延迟(100);
}


void loop()
{

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

if(count< = 0)
{
lcd.clear();
digitalWrite(relay,LOW);
lcd.clear();
lcd.print(无人房间);
lcd.setCursor(0,1);
lcd.print(光已关);
延迟(200);
}

其他
digitalWrite(relay,HIGH);

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

digitalWrite(relay,HIGH);
延迟(100);
lcd.clear();
lcd.print(超出限额);
lcd.setCursor(0,1);
lcd.print(count);
返回;
}
//其他
// digitalWrite(relay,LOW);


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

void SendMessage()
{
mySerial.println(AT + CMGF = 1); //在文本模式下设置GSM模块
delay(1000); //延迟1000毫秒或1秒
mySerial.println(AT + CMGS = \+ 918419906897 \\ r); //用手机号码替换x
delay(1000);
mySerial.println(GSM测试:超出房间限制); //要发送的短信
delay(100);
mySerial.println((char)26); // CTRL的ASCII码+ Z
delay(1000);
//Serial.end();
}

void ReceiveMessage()
{
mySerial.println(AT + CNMI = 2,2,0,0,0); // AT命令接收实时短信
延迟(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 ++;
延迟(10);
if(count == 1000){Serial.println(GSM not Found); break;}

}
}

解决方案

我认为你有两个问题: IR 传感器(或处理它的代码)无法正常工作和缺失的通知。

您可以先模拟 IR 传感器(一种简单的方法是从更改if(digitalRead(in)) if(1)以测试代码的通知部分。然后你可能会遇到人员检测问题。有很多资源可用在这个主题的网络上,请参阅概述| PIR运动传感器| Adafruit学习系统 [ ^ ]。

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

}
}

解决方案

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[^].


这篇关于我不能增加或减少否。循环运行时的人员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆