//مكتبة الشاشة
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Servo.h>
//Arduinoتعريف المتغيرات لاطراف ال
#define Bulb 2
#define Motion 4
#define Tempreture A0
#define Garage_door 3
#define Garage_button 5
Servo motor; // Object for the garage motor
//(عدد الاعمدة , عدد الصفوف ,عنوان الشاشة)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Variables
int pir_val = 0;
float temperature = 0.0;
unsigned long lastLightOn = 0;
unsigned long lastButtonPress = 0;
void setup()
{ //تهيئة الاطراف للادخال او الاخراج
pinMode(Bulb,OUTPUT);
pinMode(Motion,INPUT);
pinMode(Garage_door,OUTPUT);
pinMode(Garage_button,INPUT_PULLUP);
// تعريفات موتور الجاراش
motor.attach(Garage_door); //arduinoتعريف طرف الموتور في ال
//ابتداء تشغيل الشاشة
lcd.init();
lcd.backlight();
lcd.print("Outdoor");
lcd.setCursor(0,1); //(الصف,العمود)
lcd.print("Tempreture");
delay(1000);
lcd.clear();
}
void loop() {
PIR();
Garage_servo();
DisplayTemperature();
}
// Function to display temperature on the LCD
void DisplayTemperature() {
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
lcd.setCursor(0, 0); // Set the cursor to the first column, first row
lcd.print("Temp: ");
lcd.print(celsius);
lcd.print(" C");
}
// لحساس الحركه Function تعريف
void PIR(){
pir_val = digitalRead(Motion); // قرائة قيمه حساس الحركة
if (pir_val == HIGH && millis()-lastLightOn > 1000 && millis()-lastLightOn < 3000) { // التاكد من طرف الحساس مرفوع ام لا
digitalWrite(Bulb, HIGH); // اطفاء الاضاءة
lastLightOn = millis();
}
else if (millis()-lastLightOn > 3000)
digitalWrite(Bulb, LOW); // اغلاق الاضائة
}
// لموتور الجاراش Function تعريف
void Garage_servo() {
if(digitalRead(Garage_button) == LOW && millis()-lastButtonPress > 500)
{ lastButtonPress = millis();
if(motor.read()== 90)
{motor.write(0);}
else
{motor.write(90);}
}
}