:: مهندس متميز ::
تاريخ التسجيل: Oct 2015
المشاركات: 620
|
|
نشاط [ مشتاق الله ]
قوة السمعة:0
|
|
12-05-2016, 04:02 PM
المشاركة 5
|
|
بسم الله الرحمن الرحيم
السلام عليكم و رحمة الله و بركاته
اخى العزيز بفضل الله قمت ببعض التعديلات , باضافة حساس او مفتاح
للباب , فعندما تضئ led1= high ان شاء الله سينتظر البرنامج حتى
تضغط على مفتاح موصل بالدخل 1 , ثم يرسل رسالة جرب و عرفنا
ملاحظة مهمة : الدخل 1 لازم يوصل بمقاومة 10 ك للارضى , و المفتاح يدخل 5 فولت عليه .
اذا نجحت قم بتكرار الكود الخاص بالسطر "a1" السطر الازرق فى الكود
كود:
#include <SoftwareSerial.h>
#include <string.h>
SoftwareSerial SIM900(7, 8);
char inchar; // Will hold the incoming character from the GSM shield
char* orderIsdone;
int led1 = 10;
int led2 = 11;
int led3 = 12;
int led4 = 13;
int doorSensor = 1;
void setup()
{
// set up the digital pins to control
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(doorSensor, INPUT);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
SIM900.begin(19200);
SIM900power();
delay(2000); // give time to log on to network.
}
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(5000);
}
void sendSMS(char* orderIsdone)
{
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(100);
SIM900.println("AT + CMGS = \"+12128675309\""); // recipient's mobile number, in international format
delay(100);
SIM900.println("Hello, world. This is a text message from an Arduino Uno."); // message to send
delay(100);
SIM900.println(*orderIsdone);
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(5000); // give module time to send SMS
// SIM900power(); // turn off module
}
void receiveControl(){
SIM900.print("AT+CMGF=1\r"); // set SMS mode to text
delay(100);
SIM900.print("AT+CNMI=2,2,0,0,0\r");
// blurt out contents of new SMS upon receipt to the GSM shield's serial out
delay(100);
Serial.println("Ready...");
}
void loop()
{ //char* orderIsdone;
orderIsdone ="hellow";
sendSMS(orderIsdone);
receiveControl();
do {
//If a character comes in from the cellular module...
if(SIM900.available() >0)
{
inchar=SIM900.read();
if (inchar=='#')
{
delay(10);
inchar=SIM900.read();
if (inchar=='a')
{
delay(10);
inchar=SIM900.read();
if (inchar=='0')
{
digitalWrite(led1, LOW);
}
else if (inchar=='1')
{
digitalWrite(led1, HIGH); // next code is to be dublicate as you like
while(doorSensor == 0){} // waiting for swich read hi
orderIsdone = "door opened"; // send sms
sendSMS(orderIsdone);
}
delay(10);
inchar=SIM900.read();
if (inchar=='b')
{
inchar=SIM900.read();
if (inchar=='0')
{
digitalWrite(led2, LOW);
}
else if (inchar=='1')
{
digitalWrite(led2, HIGH);
}
delay(10);
inchar=SIM900.read();
if (inchar=='c')
{
inchar=SIM900.read();
if (inchar=='0')
{
digitalWrite(led3, LOW);
}
else if (inchar=='1')
{
digitalWrite(led3, HIGH);
}
delay(10);
inchar=SIM900.read();
if (inchar=='d')
{
delay(10);
inchar=SIM900.read();
if (inchar=='0')
{
digitalWrite(led4, LOW);
}
else if (inchar=='1')
{
digitalWrite(led4, HIGH);
}
delay(10);
}
}
SIM900.println("AT+CMGD=1,4"); // delete all SMS
}
}
}
}
} while (1);
}
الحمد الذى بنعمته تتم الصالحات
الله مولانا ولا مولى لهم
انى عذت بربى و ربكم ان ترجمون
الله ينصرك سوريا و . و . - كلنا حلب و غزة
|