مشروع إرسال درجة الحرارة عبر الرسائل النصية SMS اكتب تعليقُا

تم نشر هذا المشروع لجميع الأشخاص المهتمين في مجال تصنيع وابتكار المشاريع الإلكترونية والبرمجية، و نود التنويه أن موقع انا الكتروني يخلي مسؤوليته التامة في حال لم يعمل المشروع لدى العميل أو في حال الاستخدام الخاطئ للمكونات الإلكترونية والكهربائية التي قد تؤدي لحدوث أي مشكلة لا سمح الله.

شرح فكرة المشروع

  • وحدة SIM800 هي وحدة اتصالات ونقل البيانات تعمل بتقنية GSM/GPRS.
  • تمكّن وحدة SIM800 من التواصل عبر الشبكات الخلوية لإرسال واستقبال المكالمات الصوتية والرسائل النصية ونقل البيانات عبر GPRS.
  • تعد وحدة SIM800 شائعة الاستخدام في مجموعة متنوعة من التطبيقات، مثل أنظمة الأمان والمراقبة عن بُعد، أنظمة التحكم الصناعي، أجهزة التتبع الجغرافي، أجهزة الاستشعار الذكية، والعديد من المشاريع الإلكترونية التفاعلية الأخرى التي تتطلب التواصل عبر الشبكات الخلوية.
  • حساس DHT22 هو نوع من حساسات استشعار درجة الحرارة والرطوبة.
  • يتميز DHT22 بقدرته على قياس درجة الحرارة والرطوبة بدقة عالية، ويمكن استخدامه في العديد من التطبيقات المختلفة.
  • في هذا المشروع، سيتم إرسال رسالة نصية إلى الأردوينو لطلب درجة الحرارة المحيطة، ثم الحصول على الرد في شكل SMS كذلك.
  • الرابط

ادوات المشروع

تنويه: استخدم لوحة Bread board لتوصيل الوحدات بمنفذ 5V و GND

مخطط المشروع

الكود البرمجي

تنبيه : في حال لم تكن متأكد من قدرتك على تنفيذ خطوات المشروع يرجى استشارة شخص متخصص في هذا المجال.
  • للتعرف على تجهيز لوحة أردوينو للبرمجة قم بزيارة الرابط التالي.
  • للإطلاع على كيفية تحميل وتنصيب المكتبات قم بزيارة الرابط التالي.
  • قبل تحميل الكود البرمجي، عليك تحميل المكتبات التالية:
  • gprs.h من هنا
  • DHT.h من هنا
  • في حال لم يعمل هذا الكود البرمجي، قم بتحميل ملف الكود بالضغط على زر التحميل الموجود في الأسفل.

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain

#include “DHT.h”

#define DHTPIN 2 // what digital pin we’re connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
DHT dht(DHTPIN, DHTTYPE);

#include <gprs.h>
#include <softwareserial.h>
#define TIMEOUT 5000
GPRS gprs;
bool ITemp = false;
float temp;
String MyString;
#define LED_PIN 13
bool ledStatus;
//Variable to hold last line of serial output from SIM800
char currentLine[500] = “”;
int currentLineIndex = 0;
//Boolean to be set to true if message notificaion was found and next
//line of serial output is the actual SMS message content
bool nextLineIsMessage = false;

void Reply ()// Function starts here
{
Serial.println(“GPRS – Send SMS Test …”);
gprs.preInit();
delay(1000);
while(0 != gprs.init()) {
delay(1000);
Serial.print(“init error\\”);
}
Serial.println(“Init success, start to send SMS message…”);
if (ITemp == true){
float t = dht.readTemperature();
temp=t;
ITemp = false; }

MyString = String(temp,0); //Convert float to String
MyString = (MyString + ” Degrees C”);

// convert string to char starts here
// Length (with one extra character for the null terminator)
int str_len = MyString.length() + 1;
// Prepare the character array (the buffer)
char char_array[str_len];
// Copy it over
MyString.toCharArray(char_array, str_len);
// convert string to char ends here

gprs.sendSMS(“04++++++++”,char_array); //define phone number and text
// Function ends here
}
void setup() {
Serial.begin(9600);
Serial.println(“DHTxx test!”);

dht.begin();
gprs.preInit();
delay(1000);

while(0 != gprs.init()) {
delay(1000);
Serial.print(“init error\\”);
//later display SIM ERROR on Nextion HMI Home Page
}

//Set SMS mode to ASCII
if(0 != gprs.sendCmdAndWaitForResp(“AT+CMGF=1\\”,”OK”, TIMEOUT)) {
ERROR(“ERROR:CNMI”);
return;
}

//Start listening to New SMS Message Indications
if(0 != gprs.sendCmdAndWaitForResp(“AT+CNMI=1,2,0,0,0\\”,”OK”, TIMEOUT)) {
ERROR(“ERROR:CNMI”);
return;
}

Serial.println(“Init success”);
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds ‘old’ (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();

Serial.print(“Humidity: “);
Serial.print(h);
Serial.println(” %\ “);
Serial.print(“Temperature: “);
Serial.print(t);
Serial.println(” *C “);
SIM();
}

void SIM()
{
//Write current status to LED pin
digitalWrite(LED_PIN, ledStatus);
Serial.println(“Looking for SMS”);
//If there is serial output from SIM800
if(gprs.serialSIM800.available()){
char lastCharRead = gprs.serialSIM800.read();
//Read each character from serial output until \or \is reached (which denotes end of line)
if(lastCharRead == ‘\’ || lastCharRead == ‘\’){
String lastLine = String(currentLine);

//If last line read +CMT, New SMS Message Indications was received.
//Hence, next line is the message content.
if(lastLine.startsWith(“+CMT:”)){
Serial.println(lastLine);
nextLineIsMessage = true;
} else if (lastLine.length() > 0) {

if(nextLineIsMessage) {
Serial.println(lastLine);

//Read message content and set status according to SMS content
if(lastLine.indexOf(“InTemp”) >= 0){
Serial.println(“InTemp”);
ITemp = true;
Reply ();
// ledStatus = 1;
// Serial.println(“Turn ON the Light”);
//} else if(lastLine.indexOf(“LED OFF”) >= 0) {
// ledStatus = 0;
// Serial.println(“Turn OFF the Light”);
}

nextLineIsMessage = false;
}

}

//Clear char array for next line of read
for( int i = 0; i < sizeof(currentLine); ++i ) {
currentLine[i] = (char)0;
}
currentLineIndex = 0;
} else {
currentLine[currentLineIndex++] = lastCharRead;
}
}
}

اترك تعليقاً

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *