我需要帮助我正在做关于使用SIM900a打开和关闭门的项目..它说没有错误但它不起作用!!我使用AT命令,它假设当用户敲门,在家里运动,高温时发送通知给用户,当他们吸烟时请帮助请
#include <SoftwareSerial.h>
#include "pins_arduino.h"
#include <String.h>
SoftwareSerial SIM900(7, 8); //tx & rx pins
String msg = String("");
char inchar;
int x = 0;
int y = 0;
float z =0;
int PIR_sensor = 12;
int door_lock = 4 ; //close the door
int door_lock1 = 5 ;
int led = 11;
int led1 = 10; //red led
int mic= 6;
int Gas_sensor = A0;
float Tem_sensor = A1;
float temp =0.0;
String textForGAS ;
String textForPIR ;
String textForTAM ;
void setup()
{
Serial.begin(19200);
pinMode(PIR_sensor, INPUT);
pinMode(door_lock, OUTPUT);
pinMode(door_lock1, OUTPUT);
pinMode(led, OUTPUT);
pinMode(led1, OUTPUT);
digitalWrite(door_lock, LOW);
digitalWrite(door_lock1, LOW);
digitalWrite(led, LOW);
digitalWrite(led1, LOW);
// wake up the GSM shield
SIM900.begin(19200);
delay(20000); // give time to log on to network.
SIM900.print("AT+CMGF=1r"); // set SMS mode to text
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0r");
// blurt out contents of new SMS upon receipt to the GSM shield’s serial out
delay(100);
Serial.println("Ready…");
}
void sendSMS(String message)
{
SIM900.print("AT+CMGF=1\r");
delay(100);
SIM900.println("AT + CMGS = \"+96896089681\"");
delay(100);
SIM900.println(message);
delay(100);
SIM900.println((char)26);
delay(100);
SIM900.println();
delay(5000);
}
void loop()
{
//If a character comes in from the cellular module…
if (SIM900.available())
{
inchar = SIM900.read();
Serial.println(inchar);
if (inchar == '#')
{
delay(10);
inchar = SIM900.read();
if (inchar == 'a')
{
delay(10);
inchar = SIM900.read();
if (inchar == '0')
{
digitalWrite(door_lock, HIGH);
digitalWrite(led1, HIGH);
digitalWrite(led, LOW);
}
else if (inchar == '1')
{
digitalWrite(door_lock1, HIGH);
digitalWrite(led, HIGH);
digitalWrite(led1, LOW);
}
delay(10);
inchar = SIM900.read();
if (inchar == 'b')
{
inchar = SIM900.read();
if (inchar == '0')
{
digitalWrite(PIR_sensor, LOW);
}
else if (inchar == '1')
{
digitalWrite(PIR_sensor, HIGH);
}
}
SIM900.println("AT+CMGD=1,4"); // delete all SMS
}
}
}
Gas_sensor = (analogRead(A0));
PIR_sensor = (digitalRead(12));
Tem_sensor = (analogRead(A1));
temp = Tem_sensor * 0.48828125;
//program for GAS sensor
if (temp > 70.0)
{
textForTAM = "Alarm ! The degree of Tamperture is :n ";
textForTAM.concat(temp);
textForTAM = textForTAM +"C";
Serial.println(textForTAM);
sendSMS(textForGAS);
delay(1000);
do {
z = (analogRead(A0));
}
while (z >= 141.312);
}
//program for GAS sensor
if (Gas_sensor > 500)
{
textForGAS = "Alarm ! there is Gas by rate :n ";
textForGAS.concat(Gas_sensor);
Serial.println(textForGAS);
sendSMS(textForGAS);
delay(1000);
}
//program for PIR sensor
if (digitalRead(12) == HIGH)
{
textForPIR = "Warnning ! n theres's a motion ";
textForPIR.concat(PIR_sensor);
Serial.println(textForPIR);
sendSMS(textForPIR);
delay(1000);
}
}
谢谢