//////////////////////////////////////////////
////////////// My Libraries //////////////
//////////////////////////////////////////////
///////// DHT LIBRARY &CONSTRACTION///////////
#include <dht11.h>
#define DHT11PIN 32
dht11 DHT11;
//////////////////LIQUID CRYSTAL DISPLAY LCD//////////////
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display
///////////////////////////////////////////////////////////
#define REMOTEXY_MODE__HARDSERIAL
#include <RemoteXY.h>
// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 9600
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 362 bytes
{ 255,3,0,46,0,99,1,17,0,0,0,172,1,126,200,3,1,1,0,2,
0,131,8,2,48,14,2,170,161,31,67,111,110,116,114,111,108,0,37,131,
64,1,60,14,2,44,34,31,78,111,116,105,102,105,99,97,116,105,111,110,
0,25,9,0,70,70,49,52,30,18,26,37,0,70,70,136,52,30,18,26,
37,0,2,74,140,44,22,1,50,27,31,31,79,78,0,79,70,70,0,70,
71,92,51,30,18,26,37,0,2,74,53,44,22,1,50,27,31,31,79,78,
0,79,70,70,0,129,6,58,62,10,31,76,105,118,105,110,103,32,82,111,
111,109,0,129,8,103,34,10,31,75,105,116,99,104,101,110,0,129,6,145,
50,10,31,66,101,100,32,82,111,111,109,0,2,75,96,44,22,1,50,27,
31,31,79,78,0,79,70,70,0,15,0,66,8,74,110,10,129,35,26,129,
8,62,84,10,31,84,101,109,112,101,114,97,116,117,114,101,32,40,194,176,
67,41,58,0,129,8,96,64,10,31,72,117,109,105,100,105,116,121,32,40,
37,41,58,0,66,8,108,110,10,129,177,26,67,96,60,22,12,5,35,26,
4,67,96,94,22,12,5,177,26,4,129,8,132,40,10,31,71,97,122,32,
40,37,41,58,0,66,8,144,110,10,129,94,26,67,96,130,22,12,5,94,
26,4,69,14,170,20,20,0,1,69,52,170,20,20,0,177,69,90,168,20,
20,0,94,70,96,28,24,24,16,26,37,0,67,8,34,84,12,5,31,26,
21,129,8,26,54,8,31,77,111,116,105,111,110,32,83,116,97,116,117,115,
58,0 };
// this structure defines all the variables and events of your control interface
struct {
uint8_t bed; // =1 if switch ON and =0 if OFF
uint8_t living; // =1 if switch ON and =0 if OFF
uint8_t kitchen; // =1 if switch ON and =0 if OFF
// output variables
uint8_t led_lvng; // led state
uint8_t led_bed; // led state
uint8_t led_ktchn; // led state
int8_t level_temp; // =0..100 level position
int8_t level_humidity; // =0..100 level position
char text_temp[4]; // string UTF8 end zero
char text_humidity[4]; // string UTF8 end zero
int8_t level_gaz; // =0..100 level position
char text_gaz[4]; // string UTF8 end zero
int16_t sound_temp; // =0 no sound, else ID of sound, =1001 for example, look sound list in app
int16_t sound_hmdt; // =0 no sound, else ID of sound, =1001 for example, look sound list in app
int16_t sound_gaz; // =0 no sound, else ID of sound, =1001 for example, look sound list in app
uint8_t led_motion; // led state
char text_motion[21]; // string UTF8 end zero
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_LIVING 36
#define PIN_KITCHEN 38
#define PIN_BED 40
///////////////////MY VARIABLES//////////////////
byte pir_pin = 26;
byte pir_output = 42;
byte buzzer = 22;
byte temp_led = 23;
////////////////////////////////////////////
void setup()
{
RemoteXY_Init ();
pinMode (PIN_LIVING, OUTPUT);
pinMode (PIN_KITCHEN, OUTPUT);
pinMode (PIN_BED, OUTPUT);
// TODO you setup code
//////////////////LCD related command//////////////////
lcd.init();
lcd.backlight();
//////////////////////////////////////////////////////
/////////////////////temperature led command/////////
pinMode (temp_led, OUTPUT);
/////////////////////temperature led command END////
//////////////PIR Sensor related command//////////////
pinMode (pir_pin, INPUT_PULLUP);
pinMode (pir_output, OUTPUT);
//////////////PIR Sensor related command END/////////////
/////////////////////////////////////////////////////
//Serial.begin(9600);
}
void loop()
{
RemoteXY_Handler ();
digitalWrite(PIN_LIVING, (RemoteXY.living == 0) ? LOW : HIGH);
digitalWrite(PIN_KITCHEN, (RemoteXY.kitchen == 0) ? LOW : HIGH);
digitalWrite(PIN_BED, (RemoteXY.bed == 0) ? LOW : HIGH);
// TODO you loop code
// use the RemoteXY structure for data transfer
// do not call delay()
//////////////////DHT Related commands//////////////
int chk = DHT11.read(DHT11PIN);
int t = DHT11.temperature;
int h = DHT11.humidity;
//////////////////////////////////////////////////////////
///////////////////////PIR Sensor////////////////////////
bool pir_status = digitalRead(pir_pin);
////////////////////////////////////////////////////////
////////////////////////indications////////////////////
RemoteXY.level_temp = t;
RemoteXY.level_humidity = h;
itoa(t, RemoteXY.text_temp, 10);
itoa (h, RemoteXY.text_humidity, 10);
int gaz = analogRead(A14);
gaz = map(gaz , 0, 1023, 0, 100);
RemoteXY.level_gaz = gaz;
itoa (gaz, RemoteXY.text_gaz, 10);
if (h > 70) {
RemoteXY.sound_hmdt = 2002;
} else {
RemoteXY.sound_hmdt = 0;
}
if (t > 30) {
RemoteXY.sound_temp = 2004;
digitalWrite(temp_led, HIGH);
} else {
RemoteXY.sound_temp = 0;
digitalWrite(temp_led, LOW);
}
if (gaz > 30) {
RemoteXY.sound_gaz = 2011;
tone(buzzer, 900);
} else {
RemoteXY.sound_gaz = 0;
noTone(buzzer);
}
if ((pir_status) == 0)
{
strcpy(RemoteXY.text_motion, "object Detected");
digitalWrite(pir_output, HIGH);
RemoteXY.led_motion = HIGH;
} else
{
strcpy(RemoteXY.text_motion, " object is Away");
digitalWrite(pir_output, LOW);
RemoteXY.led_motion = LOW;
}
if (digitalRead(PIN_KITCHEN) == 0) {
RemoteXY.led_ktchn = HIGH;
} else {
RemoteXY.led_ktchn = LOW;
}
if (digitalRead(PIN_BED) == 0) {
RemoteXY.led_bed = HIGH;
} else {
RemoteXY.led_bed = LOW;
}
if (digitalRead(PIN_LIVING) == 0) {
RemoteXY.led_lvng = HIGH;
} else {
RemoteXY.led_lvng = LOW;
}
//if (digitalRead(pir_pin)==0) {RemoteXY.led_motion = LOW;} else {RemoteXY.led_motion = HIGH;}
///////////////////////////LCD related command/////////////////////
lcd.backlight();
lcd.setCursor(0, 0);
lcd.noAutoscroll();
lcd.print("TEMPERATURE=");
lcd.print(t);
lcd.setCursor(15, 0);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("HUMIDITY= ");
lcd.print(h);
lcd.setCursor(14, 1);
lcd.print("%");
/////////////////////////////////////////////////////
//Serial.println(gaz);
///////////////// GATE SERVO///////////////////////
}