المنزل الذكى
الهدف من هذا المشروع هوا التحكم في المنزل عن طريق الهاتف الذكي.
الإنجاز
الأداوات
أردوينو من نواع mega
wifi esp8266
5 مصابيح
هاتف ذكي
- Servo moteur
- afficheur LCD i2c
- phototransistor
- ventilateur
- capteur gaz MQ - 8
- capteur température dht11
- buzzer
الدوائر
المصابيح
servo- metteur
منفذ signal هوا المنفذ رقم 5
الغاز
bizzeur
wifi
photorésistance
الكود
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP8266_HARDSERIAL_POINT
#include <dht.h>
dht DHT;
int Sensor=51;
int Temp;
int Humidity;
int buzzer = 33;
int smokeA0 = A5;
const int sensorPin = A0; // Pin connected to sensor
int ledPin1=22;
//Variables
int sensorVal; // Analog value from the sensor
// Your threshold value
int sensorThres = 250 ;
#include <RemoteXY.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 115200
#define REMOTEXY_WIFI_SSID "RemoteXY"
#define REMOTEXY_WIFI_PASSWORD "12345678"
#define REMOTEXY_SERVER_PORT 6377
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] =
{ 255,6,0,1,0,213,0,10,13,0,
2,0,4,20,11,5,2,26,31,31,
79,78,0,79,70,70,0,2,0,63,
8,11,5,2,26,31,31,79,78,0,
79,70,70,0,2,0,84,20,11,5,
2,26,31,31,79,78,0,79,70,70,
0,2,0,42,20,11,5,2,26,31,
31,79,78,0,79,70,70,0,2,0,
24,8,11,5,2,26,31,31,79,78,
0,79,70,70,0,4,128,31,32,60,
5,2,26,66,0,40,38,7,23,2,
26,129,0,1,16,20,4,17,99,104,
97,109,98,114,101,32,49,0,129,0,
20,4,20,4,17,99,104,97,109,98,
114,101,32,50,0,129,0,59,4,20,
4,17,99,104,97,109,98,114,101,32,
52,0,129,0,38,16,20,4,17,99,
104,97,109,98,114,101,32,51,0,129,
0,80,16,20,4,17,99,104,97,109,
98,114,101,32,53,0,129,0,7,32,
20,4,17,112,111,114,116,101,0,129,
0,51,48,20,4,17,103,97,122,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
uint8_t LAMP1; // =1 if switch ON and =0 if OFF
uint8_t LAMP4; // =1 if switch ON and =0 if OFF
uint8_t LAMP5; // =1 if switch ON and =0 if OFF
uint8_t LAMP3; // =1 if switch ON and =0 if OFF
uint8_t LAMP2; // =1 if switch ON and =0 if OFF
int8_t slider_1; // =0..100 slider position
// output variables
int8_t level_1; // =0..100 level position
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
#include <Servo.h>
Servo myservo;
/////////////////////////////////////////////
// END RemoteXY include //
////////////////////////////////////////////
#define PIN_LAMP1 9
#define PIN_LAMP4 12
#define PIN_LAMP5 13
#define PIN_LAMP3 11
#define PIN_LAMP2 10
LiquidCrystal_I2C lcd(0x27,16,2);
void setup()
{
RemoteXY_Init ();
pinMode (PIN_LAMP1, OUTPUT);
pinMode (PIN_LAMP4, OUTPUT);
pinMode (PIN_LAMP5, OUTPUT);
pinMode (PIN_LAMP3, OUTPUT);
pinMode (PIN_LAMP2, OUTPUT);
pinMode (31, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
pinMode(ledPin1, OUTPUT);
myservo.attach(5);
RemoteXY.slider_1 = 50+500;
// TODO you setup code
}
void loop()
{
RemoteXY_Handler ();
digitalWrite(PIN_LAMP1, (RemoteXY.LAMP1==0)?LOW:HIGH);
digitalWrite(PIN_LAMP4, (RemoteXY.LAMP4==0)?LOW:HIGH);
digitalWrite(PIN_LAMP5, (RemoteXY.LAMP5==0)?LOW:HIGH);
digitalWrite(PIN_LAMP3, (RemoteXY.LAMP3==0)?LOW:HIGH);
digitalWrite(PIN_LAMP2, (RemoteXY.LAMP2==0)?LOW:HIGH);
int ms = RemoteXY.slider_1*20+500;
myservo.writeMicroseconds(ms);
{{
}
// TODO you loop code
// use the RemoteXY structure for data transfer
// do not call delay()
int chk=DHT.read11(Sensor);
Temp=DHT.temperature;
Humidity=DHT.humidity;
lcd.backlight();
lcd.init();
lcd.setCursor(1,0);
lcd.print("Smart Home" );
lcd.init();
lcd.setCursor(9,0);
lcd.print(Temp);
lcd.setCursor(1,0);
lcd.print("Temp");
lcd.setCursor(13,0);
lcd.print("c");
lcd.setCursor(9,1);
lcd.print(Humidity);
lcd.setCursor(1,1);
lcd.print("Humid");
lcd.setCursor(13,1);
lcd.print("%");
if(Temp>31)
{
// turn ventelo on:
digitalWrite(31, HIGH);
} else {
// turn ventelo off:
digitalWrite(31, LOW);
}}
int analogSensor = analogRead(smokeA0);
if (analogSensor > sensorThres)
{
tone(buzzer, 1000, 2000);
}
else
{
noTone(buzzer);
}
sensorVal = analogRead(sensorPin);
if(sensorVal<130 ){
// turn LED on:
digitalWrite(ledPin1, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin1, LOW);
}
}
فيديو الإنجاز
تعليقات
إرسال تعليق