Abstract:
In today’s world, the Automatic system is being preferred over the manual system. With a rapid increase in the number of users of the internet over the past decade has made the internet a part of life, and IOT is the latest and emerging technology. Home automation using IOT is a system that uses a computer or mobile device to control basic home function and features automatically through the internet from anywhere around the world. Also using IOT can control energy meter. With the help of Arduino that can count the units of and that unit and bill in terms of rupees, that message will send to consumer and service provider.
Working principle of Smart Home Automation Module:
As the home automation system is a model which consist of different sensors like Gas, smoke, motion, IR, keypad lock, Peltier. Initially, the Arduino connects to the internet through Wi-Fi when the connection is established it will start reading the parameter of sensors.
As the threshold level for the required sensors is set. The sensor data are sent to a web server and stored in cloud computing. The data can be analyzed anywhere anytime if the sensor parameter is greater than the threshold level then respective actuation is done.
Working principle of Energy Management Module:
As the Energy meter is for measuring the electrical energy used by the consumers. Through which signal conditioner is connected to increase the voltage level. To give 5v output as this output voltage is given to Arduino as the entire functioning of the system on this board.
Arduino reacts to 5v supply and keep on counting the supply and calculate the power consumed and also the cost. As using MAX232 for serial communication with GSM module and Wi-Fi module as max232 is used to provide TTL to components as per requirement.
Application of model and advantages over an existing version of model:-
- Reduces installation costs as no more cabling is necessary.
- System scalability and easy extension as the wireless network is especially advantages.
- Aesthetical benefits that attribute to covering the large area.
- Integration of mobile devices with an automation system becomes possible everywhere and at any time.
- Reduce energy conservation.
- To provide better security.
- To save human energy.
Important design aspects:
The sensors are used in our project this is the analog sensors. To read the signals we are using an Arduino board. The Arduino board has 6 analog pins and 13 digital pins to read signals. Also, the appliances are connected to the Arduino board to digital pins. The IOT is connected to Arduino board to on/off the appliances. Also to energy meter is connected to Arduino board and IOT module, GSM module to read the units and that message is sent to consumer and services provider.The solar panels are used in our project to provide renewable energy with the help of charging batteries. The system can be accessed from the web server of any local or mobile device. Wi-Fi is used to connect servers and sensors to improve security. By typing the IP address of web server to communicate with the system. It can be monitored from anywhere around the world.
Schematic Diagram for Smart Home Automation:
Smart Home Automation Schematic Diagram :
Required Components:
Sr. No. | Components | Specification | Quantity | ||
1 | Capacitor | 22pf | 2 | ||
0.47uf | 2 | ||||
33pf | 2 | ||||
2. | Resistors | Pull up resistor | 2 | ||
100Ω | 6 | ||||
2.2k | 6 | ||||
100k | 2 | ||||
10k | 6 | ||||
3. | Diodes | 1n4007 | 4 | ||
4. | Relays | 12v dc | 6 | ||
5. | IC sockets | 40 pin | 1 | ||
16 pin | 1 | ||||
6. | ICs | Arduino mega | 2 | ||
MAX232 | 1 | ||||
7. | Transistors | BC547 | 6 | ||
8. | Connectors | 2 pin connector | 7 | ||
3 pin connector | 1 | ||||
LCD connector | 1 | ||||
9. | PCB | Glass epoxy | 2 | ||
10. | Transformer | 230-15v | 2 | ||
11. | WiFi receiver | WiFi receiver | 1 | ||
12. | LCD | 16*2 char | 2 |
Specify area of applications:-
- The control and automation of lighting, heating, smart thermostats.
- Home appliances ovens, refrigerator, washer, air conditioning.
- Get real-time electricity usage data on your smartphones on a weekly/monthly basis.
- Allows you to remotely lock and unlock your doors.
- Allows you to schedule electrical devices.
- Automatically sets the ambient lighting the way you prefer it.
- It reduces the energy wastage and brings awareness among all.
Parameter on which performance of the project is tested:-
The response time of IOT, GSM Modem.
The output voltage of Solar panel, Arduino.
Power dissipation
Initial cost is high but as production quantity increases cost decreases.
Here we use solar power hence it is pollution free.
Please comment on the commercial viability of the project:-
This system is designed to be low cost and expandable allowing a variety of devices to be controlled.
Get real-time electricity usage data on your smartphone on a weekly/monthly basis.
The control and automation of lighting, heating, smart thermostats.
It can be monitored from anywhere around the world.
Eliminate the third party between consumer and service provider.
Source Code For Smart Home Automation Module:
* First Make Account in iotgecko.com and get your String Id and Add into source code just like i Did | Add Your WiFi Name and Password into source code | Must Add Your Cellphone Number inside source code.
String id = "[email protected]"; // iotgecko login id String pass = "2263"; // iotgecko login password String ssid = "IOTPROJECTSB"; // SSID/name of your wifi router or wifi hotspot String pass_key = "one1two2"; //Wifi Password // Download this library at IOTGecko.com -> Code Examples: #include <LiquidCrystal.h> // include the library code: //########### HARDWARE PIN CONNECTIONS ####################### LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // RS, EN, D0,D1,D2,D3 initialize the library with the numbers of the interface pins // declaration at the begining of code const int Keypad_Col1 = 23; const int Keypad_Col2 = 25; const int Keypad_Col3 = 27; const int Keypad_Col4 = 29; const int Keypad_Row1 = 31; const int Keypad_Row2 = 33; const int Keypad_Row3 = 35; const int Keypad_Row4 = 37; char keypad_output = 'X'; void Password_Detection(); const int Buzzer = 46; const int Motor_1 = 48; const int Motor_2 = 49; const int sensorPin1 = A0; // select the input pin for the Sensor 1 const int sensorPin2 = A1; // select the input pin for the Sensor 2 const int sensorPin3 = A2; // select the input pin for the Sensor 3 char sensorNumber = '0'; int bytesSent; int Gsm_Type = 800; char SMS_Welocme[] = {"Smart Home automation system."}; char SMS_Sensor[] = {" Sensor crossed threhold level. Please take immediate action. S = "}; void func_Send_SMS(char *, int); char LCDmsgwelcome[] = {"IOT & GSM BASED@HOME AUTOMATION$"}; char LCDmsgcorrectpwd[] = {"CORRECT PASSWORD.@$"}; char LCDmsgwrongpwd[] = {"WRONG PASSWORD.$"}; char LCDmsgwificantconnect[] = {"CAN NOT CONNECT@TO WIFI$"}; char LCDmsgenterpwd[] = {"ENTER PASSWORD:$"}; char LCDmsglockingdoor[] = {"LOCKING DOOR$"}; char LCDmsgSensorCrossed[] = {"SENSOR VALUE@CROSSED LIMIT$"}; char LCDmsgSendingSms[] = {"SENDING@SMS$"}; char LCDmsgSmsSent[] = {"SMS SENT@SUCCESSFULLY$"}; #include <iotgecko.h> #define esp_baudrate 115200 // enter baud rate of your wifi module // initialize the library with the esp8266(wifi module) iotgecko gecko = iotgecko(esp_baudrate); bool notConected = true; bool login = false; const int number_of_loads = 4; // number of loads/devices to control int load_status[number_of_loads]; //Assign pins for loads const int load1 = 9; const int load2 = 10; const int load3 = 11; const int load4 = 12; char keypad_function(); void Check_IOT_Device_Status(); void disp_lcd_msg(const char * LCD_Line); void setup() { // code in setup part for setting output/input pin mode pinMode(Keypad_Row1, OUTPUT); pinMode(Keypad_Row2, OUTPUT); pinMode(Keypad_Row3, OUTPUT); pinMode(Keypad_Row4, OUTPUT); pinMode(Keypad_Col1, INPUT); pinMode(Keypad_Col2, INPUT); pinMode(Keypad_Col3, INPUT); pinMode(Keypad_Col4, INPUT); digitalWrite(Keypad_Col1, HIGH); digitalWrite(Keypad_Col2, HIGH); digitalWrite(Keypad_Col3, HIGH); digitalWrite(Keypad_Col4, HIGH); digitalWrite(Keypad_Row1, HIGH); digitalWrite(Keypad_Row2, HIGH); digitalWrite(Keypad_Row3, HIGH); digitalWrite(Keypad_Row4, HIGH); pinMode(Motor_1, OUTPUT); pinMode(Motor_2, OUTPUT); pinMode(Buzzer, OUTPUT); digitalWrite(Motor_1, LOW); lcd.begin(16, 2); // set up the LCD's number of columns and rows: disp_lcd_msg(LCDmsgwelcome); delay(2000); Serial.begin(115200); pinMode(load1,OUTPUT); pinMode(load2,OUTPUT); pinMode(load3,OUTPUT); pinMode(load4,OUTPUT); Serial1.begin(9600); // Start serial port 9600 bps func_Send_SMS(SMS_Welocme, sizeof(SMS_Welocme)); delay(2000); } void loop() { int counter1, counter2; for(counter1 = 0 ; counter1 < 10 ; counter1++) { for(counter2 = 0 ; counter2 < 10 ; counter2++) { Password_Detection(); Door_Lock(); delay(100); } Read_Sensor_Values(); } for(counter1 = 0 ; counter1 < 1 ; counter1++) { Check_IOT_Device_Status(); delay(1000); } } void Read_Sensor_Values(void) { int sensorAllValues[]={0,0,0}; sensorAllValues[0] = (analogRead(sensorPin1)); sensorAllValues[1] = (analogRead(sensorPin2)); sensorAllValues[2] = (analogRead(sensorPin3)); lcd.clear(); lcd.print("S1="); lcd.print(sensorAllValues[0]); lcd.setCursor(8,0); lcd.print("S2="); lcd.print(sensorAllValues[1]); lcd.setCursor(0,1); lcd.print("S3="); lcd.print(sensorAllValues[2]); delay(1000); if(sensorAllValues[0] > 500 || sensorAllValues[1] < 500 || sensorAllValues[2] < 500) { if(sensorAllValues[0] > 500) sensorNumber = '1'; if(sensorAllValues[1] < 500) sensorNumber = '2'; if(sensorAllValues[2] < 500) sensorNumber = '3'; disp_lcd_msg(LCDmsgSensorCrossed); lcd.setCursor(7,0); lcd.print(sensorNumber); digitalWrite(Buzzer, HIGH); delay(4000); digitalWrite(Buzzer, LOW); func_Send_SMS(SMS_Sensor, sizeof(SMS_Sensor)); delay(2000); } } void func_Send_SMS(char * Array_msg, int length_value) { // char strATCMGS[] = {"AT+CMGS=\""}; // char strATCMGSend[] = {"\""}; // strcat(strATCMGS, MobileNumber); // strcat(strATCMGS, strATCMGSend); int i; i = length_value - 2; disp_lcd_msg(LCDmsgSendingSms); bytesSent = Serial1.write("AT"); Serial1.write(13); delay(2000); delay(2000); bytesSent = Serial1.write("AT+CMGF=1"); Serial1.write(13); delay(2000); delay(2000); if(Gsm_Type == 800) { bytesSent = Serial1.write("AT+CSMP=17,167,0,0"); //"AT+CSMP=17,167,0,0",13,10,'$' Serial1.write(13); delay(2000); delay(2000); } // bytesSent = Serial1.write(strATCMGS, sizeof(strATCMGS)); bytesSent = Serial1.write("AT+CMGS=\"+918600448130\""); Serial1.write(13); delay(2000); delay(2000); if(sensorNumber != '0') { Array_msg[i] = sensorNumber; length_value++; } if(sensorNumber == '1') { Array_msg[0] = 'G'; Array_msg[1] = 'a'; Array_msg[2] = 's'; } if(sensorNumber == '2') { Array_msg[0] = 'I'; Array_msg[1] = 'R'; Array_msg[2] = ' '; } if(sensorNumber == '3') { Array_msg[0] = 'P'; Array_msg[1] = 'I'; Array_msg[2] = 'R'; } bytesSent = Serial1.write(Array_msg, length_value); // bytesSent = Serial1.write("GSM based LPG Leakage detection system."); disp_lcd_msg(LCDmsgSmsSent); } void disp_lcd_msg(const char * LCD_Line) { int i = 0; lcd.clear(); while(LCD_Line[i] != '$') { if(LCD_Line[i] == '@') { lcd.setCursor(0, 1); // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): } else { lcd.print(LCD_Line[i]); // Print a message to the LCD. } i++; } } char keypad_function(void) { keypad_output = 'X'; //==================================================================== digitalWrite(Keypad_Row1, LOW); digitalWrite(Keypad_Row2, HIGH); digitalWrite(Keypad_Row3, HIGH); digitalWrite(Keypad_Row4, HIGH); if(digitalRead(Keypad_Col1) == LOW) { delay(10); // debounce delay if(digitalRead(Keypad_Col1) == LOW) { keypad_output = '1'; // lcd.print('1'); } } if(digitalRead(Keypad_Col2) == LOW) { delay(10); if(digitalRead(Keypad_Col2) == LOW) { keypad_output = '2'; // lcd.print('2'); } } if(digitalRead(Keypad_Col3) == LOW) { delay(10); if(digitalRead(Keypad_Col3) == LOW) { keypad_output = '3'; // lcd.print('3'); } } if(digitalRead(Keypad_Col4) == LOW) { delay(10); if(digitalRead(Keypad_Col4) == LOW) { keypad_output = 'A'; // lcd.print('A'); } } //==================================================================== //==================================================================== digitalWrite(Keypad_Row1, HIGH); digitalWrite(Keypad_Row2, LOW); digitalWrite(Keypad_Row3, HIGH); digitalWrite(Keypad_Row4, HIGH); if(digitalRead(Keypad_Col1) == LOW) { delay(10); // debounce delay if(digitalRead(Keypad_Col1) == LOW) { keypad_output = '4'; // lcd.print('4'); } } if(digitalRead(Keypad_Col2) == LOW) { delay(10); if(digitalRead(Keypad_Col2) == LOW) { keypad_output = '5'; // lcd.print('5'); } } if(digitalRead(Keypad_Col3) == LOW) { delay(10); if(digitalRead(Keypad_Col3) == LOW) { keypad_output = '6'; // lcd.print('6'); } } if(digitalRead(Keypad_Col4) == LOW) { delay(10); if(digitalRead(Keypad_Col4) == LOW) { keypad_output = 'B'; // lcd.print('B'); } } //==================================================================== //==================================================================== digitalWrite(Keypad_Row1, HIGH); digitalWrite(Keypad_Row2, HIGH); digitalWrite(Keypad_Row3, LOW); digitalWrite(Keypad_Row4, HIGH); if(digitalRead(Keypad_Col1) == LOW) { delay(10); // debounce delay if(digitalRead(Keypad_Col1) == LOW) { keypad_output = '7'; // lcd.print('7'); } } if(digitalRead(Keypad_Col2) == LOW) { delay(10); if(digitalRead(Keypad_Col2) == LOW) { keypad_output = '8'; // lcd.print('8'); } } if(digitalRead(Keypad_Col3) == LOW) { delay(10); if(digitalRead(Keypad_Col3) == LOW) { keypad_output = '9'; // lcd.print('9'); } } if(digitalRead(Keypad_Col4) == LOW) { delay(10); if(digitalRead(Keypad_Col4) == LOW) { keypad_output = 'C'; // lcd.print('C'); } } //==================================================================== //==================================================================== digitalWrite(Keypad_Row1, HIGH); digitalWrite(Keypad_Row2, HIGH); digitalWrite(Keypad_Row3, HIGH); digitalWrite(Keypad_Row4, LOW); if(digitalRead(Keypad_Col1) == LOW) { delay(10); // debounce delay if(digitalRead(Keypad_Col1) == LOW) { keypad_output = '*'; // lcd.print('*'); } } if(digitalRead(Keypad_Col2) == LOW) { delay(10); if(digitalRead(Keypad_Col2) == LOW) { keypad_output = '0'; // lcd.print('0'); } } if(digitalRead(Keypad_Col3) == LOW) { delay(10); if(digitalRead(Keypad_Col3) == LOW) { keypad_output = '#'; // lcd.print('#'); } } if(digitalRead(Keypad_Col4) == LOW) { delay(10); if(digitalRead(Keypad_Col4) == LOW) { keypad_output = 'D'; // lcd.print('D'); } } //==================================================================== } void Door_Lock() { char customKey = 'X'; customKey = keypad_function(); if(customKey == '#') { disp_lcd_msg(LCDmsglockingdoor); digitalWrite(Motor_1, LOW); digitalWrite(Motor_2, HIGH); delay(4000); digitalWrite(Motor_1, LOW); digitalWrite(Motor_2, LOW); disp_lcd_msg(LCDmsgwelcome); } } void Password_Detection() { char UserInput[10] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}; char customKey = 'X'; char prevchar = 'X'; int i=0, j=0; customKey = keypad_function(); if(customKey == '*') { disp_lcd_msg(LCDmsgenterpwd); delay(1000); customKey = 'X'; lcd.setCursor(0, 1); // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): while(customKey != '*') { customKey = keypad_function(); if((prevchar != customKey) && (customKey != 'X')) { if(customKey != '*') { lcd.print(customKey); UserInput[i] = customKey; i++; } } prevchar = customKey; delay(1000); } lcd.clear(); lcd.print("Checking..."); delay(1000); if(UserInput[0] == '1' && UserInput[1] == '2' && UserInput[2] == '3' && UserInput[3] == '4' && UserInput[4] == '5' && UserInput[5] == '6' && UserInput[6] == ' ' ) { disp_lcd_msg(LCDmsgcorrectpwd); digitalWrite(Motor_1, HIGH); digitalWrite(Motor_2, LOW); delay(4000); digitalWrite(Motor_1, LOW); digitalWrite(Motor_2, LOW); disp_lcd_msg(LCDmsgwelcome); } else { disp_lcd_msg(LCDmsgwrongpwd); digitalWrite(Buzzer, HIGH); delay(2000); digitalWrite(Buzzer, LOW); disp_lcd_msg(LCDmsgwelcome); } } } void Check_IOT_Device_Status(void) { int iot_status; if(iot_status == InvalidUserIdOrPassword) { lcd.clear(); lcd.print("Invalid UserId or Password"); Serial.println("Invalid UserId or Password"); while(1); } else if(iot_status == InvalidData) { Serial.println("Invalid Data"); lcd.clear(); lcd.print("Invalid Data"); while(1); } else if(iot_status == VALID) { if(load_status[0]>=0 && load_status[1]>=0 && load_status[2]>=0 && load_status[3]>=0) { if(load_status[0]==1) { digitalWrite(load1,HIGH); Serial.println("Load 1 is ON"); //lcd.clear(); lcd.setCursor(0,0); lcd.print("L1=ON "); } else { digitalWrite(load1,LOW); Serial.println("Load 1 is OFF"); //lcd.clear(); lcd.setCursor(0,0); lcd.print("L1=OFF "); } if(load_status[1]==1) { digitalWrite(load2,HIGH); Serial.println("Load 2 is ON"); //lcd.clear(); lcd.setCursor(8,0); lcd.print("L2=ON "); } else { digitalWrite(load2,LOW); Serial.println("Load 2 is OFF"); //lcd.clear(); lcd.setCursor(8,0); lcd.print("L2=OFF "); } if(load_status[2]==1) { digitalWrite(load3,HIGH); Serial.println("Load 3 is ON"); //lcd.clear(); lcd.setCursor(0,1); lcd.print("L3=ON "); } else { digitalWrite(load3,LOW); Serial.println("Load 3 is OFF"); //lcd.clear(); lcd.setCursor(0,1); lcd.print("L3=OFF "); } if(load_status[3]==1) { digitalWrite(load4,HIGH); Serial.println("Load 4 is ON"); //lcd.clear(); lcd.setCursor(8,1); lcd.print("L4=ON "); } else { digitalWrite(load4,LOW); Serial.println("Load 4 is OFF"); //lcd.clear(); lcd.setCursor(8,1); lcd.print("L4=OFF "); } } else { Serial.println("connection lost"); Serial.println("reconnecting..."); lcd.clear(); lcd.print("reconnecting..."); while(!gecko.GeckoReconnect()) // reconnect to the iotgecko.com { lcd.clear(); lcd.print("conncetion failed. reconnecting"); Serial.println("conncetion failed.....reconnecting"); delay(2000); } Serial.println("connected succesfully"); lcd.clear(); lcd.print("connected succesfully"); } } Serial.println(); } void Connect_to_wifi(void) { Serial.println("conncecting to wifi"); lcd.clear(); lcd.print("WIFI CONNECTING"); Serial.print(ssid); Serial.print("\t"); Serial.println(pass_key); while(notConected) { if(gecko.GeckoConnect(ssid,pass_key)) // connect to wifi with given SSID and password { Serial.println("connceted to wifi..."); lcd.clear(); lcd.print("CONNECTING TO WIFI"); notConected = false; } else { Serial.println("can't connect to wifi"); lcd.clear(); disp_lcd_msg(LCDmsgwificantconnect); } delay(1000); } Serial.println("connecting to iotgecko.com"); lcd.clear(); lcd.print("connecting to iotgecko.com"); while(!login) { if(gecko.GeckoVerify(id,pass)) // login to iotgecko.com with given ID and password { Serial.println("connected succesfully"); lcd.clear(); lcd.print("CONNECTED SUCCESFULLY"); login = true; } else { lcd.clear(); lcd.print("FAIL TO CONNECT"); Serial.println("fail to connect"); } } }
Source Code For Smart Home Automation Module:
// CHANGE HOTSPOT DETAILS AND EMAIL ID HERE String id = "[email protected]"; // iotgecko login id String pass = "7141"; // iotgecko login password String ssid = "IOTPROJECTSB"; // SSID/name of your wifi router or wifi hotspot String pass_key = "one1two2"; //Wifi Password // Download this library at IOTGecko.com -> Code Examples: //#include "TimerOne.h" #include <LiquidCrystal.h> // include the library code: //########### HARDWARE PIN CONNECTIONS ####################### LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // RS, EN, D0,D1,D2,D3 initialize the library with the numbers of the interface pins int billingfactor = 2; boolean starttimer = false; const int Buzzer = A5; int second_counter = 0; int time_counter = 0; const int sensorPin1 = A0; // select the input pin for the Sensor 1 char sensorNumber = '0'; int bytesSent; int Gsm_Type = 800; char SMS_Welocme[] = {"Smart Energy Management system."}; char SMS_EnergyBill[] = {"Period over. Pulse = . Your Bill= Rs. ."}; void func_Send_SMS(char *, int); char LCDmsgwelcome[] = {"SMART ENERGY@MANAGEMENT$"}; char LCDmsgwificantconnect[] = {"CAN NOT CONNECT@TO WIFI$"}; //char LCDmsgSensorCrossed[] = {"SENSOR VALUE@CROSSED LIMIT$"}; char LCDmsgSendingSms[] = {"SENDING@SMS$"}; char LCDmsgSmsSent[] = {"SMS SENT@SUCCESSFULLY$"}; #include <iotgecko.h> #define esp_baudrate 115200 // enter baud rate of your wifi module // initialize the library with the esp8266(wifi module) iotgecko gecko = iotgecko(esp_baudrate); bool notConected = true; bool login = false; const int number_of_loads = 4; // number of loads/devices to control int load_status[number_of_loads]; const int no_of_doors = 1; int door_status[no_of_doors]; //Assign pins for loads const int Relay1 = 10; //const int Relay2 = 11; //const int Relay3 = 12; //const int Relay4 = 13; int Pulse_Count = 0; char keypad_function(); void Check_IOT_Device_Status(); void disp_lcd_msg(const char * LCD_Line); void setup() { pinMode(Buzzer, OUTPUT); digitalWrite(Buzzer, LOW); // Timer1.initialize(1000000); // initialize timer1, and set a 1 second period // Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt pinMode(Relay1, OUTPUT); // pinMode(Relay2,OUTPUT); // pinMode(Relay3,OUTPUT); // pinMode(Relay4,OUTPUT); digitalWrite(Relay1, HIGH); // digitalWrite(Relay2,LOW); // digitalWrite(Relay3,LOW); // digitalWrite(Relay4,LOW); lcd.begin(16, 2); // set up the LCD's number of columns and rows: disp_lcd_msg(LCDmsgwelcome); delay(2000); delay(2000); lcd.clear(); lcd.print("PLEASE WAIT..."); delay(2000); lcd.print('.'); delay(2000); lcd.print('.'); delay(2000); lcd.print('.'); Serial1.begin(115200); Serial1.begin(9600); // Start serial port 9600 bps func_Send_SMS(SMS_Welocme, sizeof(SMS_Welocme)); func_Send_SMS2nd(SMS_Welocme, sizeof(SMS_Welocme)); delay(2000); lcd.clear(); starttimer = true; } void loop() { int counter1, counter2; bool iot_checking = false; lcd.setCursor(0, 0); lcd.print("PULSE="); lcd.print(Pulse_Count); lcd.print(" "); while (time_counter < 600) { Read_Energy_Meter(); /* if(iot_checking == false && time_counter > 300) { Check_IOT_Device_Status(); delay(2000); lcd.clear(); iot_checking = true; } */ } time_counter = 0; iot_checking = false; Check_IOT_Device_Status(); delay(2000); sensorNumber = '1'; func_Send_SMS(SMS_EnergyBill, sizeof(SMS_EnergyBill)); func_Send_SMS2nd(SMS_EnergyBill, sizeof(SMS_EnergyBill)); delay(2000); Check_IOT_Device_Status(); delay(2000); lcd.clear(); for (counter1 = 0 ; counter1 < 1 ; counter1++) { // Check_IOT_Device_Status(); // delay(1000); } } void Read_Energy_Meter(void) { int LDRsensorValue; LDRsensorValue = 0; LDRsensorValue = analogRead(sensorPin1); /* lcd.setCursor(0, 1); lcd.print("S1="); lcd.print(LDRsensorValue); lcd.print(" "); */ if (LDRsensorValue > 150) { Pulse_Count++; lcd.setCursor(0, 0); lcd.print("PULSE="); lcd.print(Pulse_Count); lcd.print(" "); delay(500); time_counter = time_counter + 5; // lcd.clear(); } delay(100); time_counter++; // delay(1000); /* if(sensorAllValues[0] > 50 ) { if(sensorAllValues[0] > 50) sensorNumber = '1'; disp_lcd_msg(LCDmsgSensorCrossed); lcd.setCursor(7,0); lcd.print(sensorNumber); digitalWrite(Buzzer, HIGH); delay(4000); digitalWrite(Buzzer, LOW); // func_Send_SMS(SMS_Sensor, sizeof(SMS_Sensor)); // delay(2000); } */ } void func_Send_SMS(char * Array_msg, int length_value) { // char strATCMGS[] = {"AT+CMGS=\""}; // char strATCMGSend[] = {"\""}; // strcat(strATCMGS, MobileNumber); // strcat(strATCMGS, strATCMGSend); char str[2]; char str2[4]; int i; int BillingAmount; i = length_value - 2; disp_lcd_msg(LCDmsgSendingSms); bytesSent = Serial1.write("AT"); Serial1.write(13); delay(2000); delay(2000); bytesSent = Serial1.write("AT+CMGF=1"); Serial1.write(13); delay(2000); delay(2000); if (Gsm_Type == 800) { bytesSent = Serial1.write("AT+CSMP=17,167,0,0"); //"AT+CSMP=17,167,0,0",13,10,'$' Serial1.write(13); delay(2000); delay(2000); } // bytesSent = Serial1.write(strATCMGS, sizeof(strATCMGS)); bytesSent = Serial1.write("AT+CMGS=\"+918600448130\""); // bytesSent = Serial1.write("AT+CMGS=\"+919021443222\""); Serial1.write(13); delay(2000); delay(2000); if (sensorNumber != '0') { Array_msg[i] = sensorNumber; length_value++; } //char SMS_EnergyBill[] = {"Period over. Pulse = . Your Bill= Rs. ."}; //20 //21 //43 tostring(str, Pulse_Count); BillingAmount = Pulse_Count * billingfactor ; tostring(str2, BillingAmount); if (sensorNumber == '1') { Array_msg[22] = str[0]; if (str[1] != 'X') { Array_msg[23] = str[1]; if (str[2] != 'X') { Array_msg[24] = str[2]; } else Array_msg[24] = ' '; } else { Array_msg[23] = ' '; Array_msg[24] = ' '; } Array_msg[44] = str2[0]; if (str2[1] != 'X') { Array_msg[45] = str2[1]; if (str2[2] != 'X') { Array_msg[46] = str2[2]; if (str2[3] != 'X') { Array_msg[47] = str2[3]; } else Array_msg[47] = ' '; } else { Array_msg[46] = ' '; Array_msg[47] = ' '; } } else { Array_msg[45] = ' '; Array_msg[46] = ' '; Array_msg[47] = ' '; } } Array_msg[47] = ' '; Array_msg[48] = ' '; Array_msg[49] = ' '; bytesSent = Serial1.write(Array_msg, length_value); // bytesSent = Serial1.write("GSM based LPG Leakage detection system."); disp_lcd_msg(LCDmsgSmsSent); delay(2000); } void func_Send_SMS2nd(char * Array_msg, int length_value) { // char strATCMGS[] = {"AT+CMGS=\""}; // char strATCMGSend[] = {"\""}; // strcat(strATCMGS, MobileNumber); // strcat(strATCMGS, strATCMGSend); char str[2]; char str2[4]; int i; int BillingAmount; i = length_value - 2; disp_lcd_msg(LCDmsgSendingSms); bytesSent = Serial1.write("AT"); Serial1.write(13); delay(2000); delay(2000); bytesSent = Serial1.write("AT+CMGF=1"); Serial1.write(13); delay(2000); delay(2000); if (Gsm_Type == 800) { bytesSent = Serial1.write("AT+CSMP=17,167,0,0"); //"AT+CSMP=17,167,0,0",13,10,'$' Serial1.write(13); delay(2000); delay(2000); } // bytesSent = Serial1.write(strATCMGS, sizeof(strATCMGS)); bytesSent = Serial1.write("AT+CMGS=\"+919284705710\""); // bytesSent = Serial1.write("AT+CMGS=\"+919860119860\""); Serial1.write(13); delay(2000); delay(2000); if (sensorNumber != '0') { Array_msg[i] = sensorNumber; length_value++; } //char SMS_EnergyBill[] = {"Period over. Pulse = . Your Bill= Rs. ."}; //20 //21 //43 tostring(str, Pulse_Count); BillingAmount = Pulse_Count * billingfactor ; tostring(str2, BillingAmount); if (sensorNumber == '1') { Array_msg[22] = str[0]; if (str[1] != 'X') { Array_msg[23] = str[1]; if (str[2] != 'X') { Array_msg[24] = str[2]; } else Array_msg[24] = ' '; } else { Array_msg[23] = ' '; Array_msg[24] = ' '; } Array_msg[44] = str2[0]; if (str2[1] != 'X') { Array_msg[45] = str2[1]; if (str2[2] != 'X') { Array_msg[46] = str2[2]; if (str2[3] != 'X') { Array_msg[47] = str2[3]; } else Array_msg[47] = ' '; } else { Array_msg[46] = ' '; Array_msg[47] = ' '; } } else { Array_msg[45] = ' '; Array_msg[46] = ' '; Array_msg[47] = ' '; } } Array_msg[47] = ' '; Array_msg[48] = ' '; Array_msg[49] = ' '; bytesSent = Serial1.write(Array_msg, length_value); // bytesSent = Serial1.write("GSM based LPG Leakage detection system."); disp_lcd_msg(LCDmsgSmsSent); delay(2000); } void disp_lcd_msg(const char * LCD_Line) { int i = 0; lcd.clear(); while (LCD_Line[i] != '$') { if (LCD_Line[i] == '@') { lcd.setCursor(0, 1); // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): } else { lcd.print(LCD_Line[i]); // Print a message to the LCD. } i++; } } void Check_IOT_Device_Status(void) { int iot_status; int retrycount = 0; lcd.clear(); /* int iot_status = gecko.GetgParams(door_status, no_of_doors); //Get door status if (iot_status == InvalidUserIdOrPassword) { lcd.print("Invalid UserId or Password"); delay(1000); //while (1); } else if (iot_status == InvalidData) { lcd.print("Invalid Data"); delay(1000); // while (1); } else if (iot_status == VALID) { if (door_status[0] == 1) { digitalWrite(Relay1, HIGH); // operate door pin lcd.clear(); lcd.print("Relay Turned ON"); delay(1000); } else if (door_status[0] == 0) { digitalWrite(Relay1, LOW); lcd.clear(); lcd.print("Relay Turned OFF"); delay(1000); } } else { lcd.clear(); lcd.print("connection lost"); delay(1000); lcd.clear(); lcd.print("reconnecting..."); delay(1000); while (!gecko.GeckoReconnect()) // Reconnect to the iotgecko.com { lcd.clear(); lcd.print("failed conncetion. reconnecting"); delay(2000); } lcd.clear(); lcd.print("succesfully connected "); delay(1000); } Serial1.println(); */ if (iot_status == InvalidUserIdOrPassword) { lcd.clear(); lcd.print("Invalid UserId or Password"); // Invalid UserId or Password"); while (1); } else if (iot_status == InvalidData) { // Serial1.println("Invalid Data"); lcd.clear(); lcd.print("Invalid Data"); while (1); } else if (iot_status == VALID) { if (load_status[0] >= 0 && load_status[1] >= 0 && load_status[2] >= 0 && load_status[3] >= 0) { if (load_status[0] == 1) { //digitalWrite(Relay1,HIGH); // Serial1.println("Load 1 is ON"); //lcd.clear(); lcd.setCursor(0, 0); lcd.print(" "); } else { // digitalWrite(Relay1,LOW); // Serial1.println("Load 1 is OFF"); //lcd.clear(); lcd.setCursor(0, 0); lcd.print(" "); } if (load_status[1] == 1) { digitalWrite(Relay1, HIGH); // Serial1.println("Load 2 is ON"); //lcd.clear(); lcd.setCursor(8, 0); lcd.print("LOAD=ON "); } else { digitalWrite(Relay1, LOW); // Serial1.println("Load 2 is OFF"); //lcd.clear(); lcd.setCursor(8, 0); lcd.print("LOAD=OFF"); } if (load_status[2] == 1) { // digitalWrite(Relay1,HIGH); // Serial1.println("Load 3 is ON"); //lcd.clear(); lcd.setCursor(0, 1); lcd.print(" "); } else { // digitalWrite(Relay1,LOW); // Serial1.println("Load 3 is OFF"); //lcd.clear(); lcd.setCursor(0, 1); lcd.print(" "); } if (load_status[3] == 1) { // digitalWrite(Relay1,HIGH); // Serial1.println("Load 4 is ON"); //lcd.clear(); lcd.setCursor(8, 1); lcd.print(" "); } else { // digitalWrite(Relay1,LOW); // Serial1.println("Load 4 is OFF"); //lcd.clear(); lcd.setCursor(8, 1); lcd.print(" "); } } else { // Serial1.println("connection lost"); // Serial1.println("reconnecting..."); lcd.clear(); lcd.print("reconnecting..."); while (!gecko.GeckoReconnect()) // reconnect to the iotgecko.com { lcd.clear(); lcd.print("conncetion failed. reconnecting"); // Serial.println("conncetion failed.....reconnecting"); delay(2000); retrycount++; if (retrycount > 5) { retrycount = 0; break; } } // Serial.println("connected succesfully"); lcd.clear(); lcd.print("connected succesfully"); } } Serial.println(); } void Connect_to_wifi(void) { // Serial.println("conncecting to wifi"); lcd.clear(); lcd.print("WIFI CONNECTING"); Serial.print(ssid); Serial.print("\t"); Serial.println(pass_key); while (notConected) { if (gecko.GeckoConnect(ssid, pass_key)) // connect to wifi with given SSID and password { // Serial.println("connceted to wifi..."); lcd.clear(); lcd.print("CONNECTING TO WIFI"); notConected = false; } else { // Serial.println("can't connect to wifi"); lcd.clear(); disp_lcd_msg(LCDmsgwificantconnect); } delay(1000); } // Serial.println("connecting to iotgecko.com"); lcd.clear(); lcd.print("connecting to iotgecko.com"); while (!login) { if (gecko.GeckoVerify(id, pass)) // login to iotgecko.com with given ID and password { // Serial.println("connected succesfully"); lcd.clear(); lcd.print("CONNECTED SUCCESFULLY"); login = true; } else { lcd.clear(); lcd.print("FAIL TO CONNECT"); // Serial.println("fail to connect"); } } } void tostring(char str[], int num) { int i, rem, len = 0, n; n = num; while (n != 0) { len++; n /= 10; } for (i = 0; i < len; i++) { rem = num % 10; num = num / 10; str[len - (i + 1)] = rem + '0'; } str[len] = 'X'; len++; str[len] = '\0'; }
Successfully Made:
Check Electricity Meter Reading Wirelesly Using Arduino and GSM Module
Project Copyrights – IMAD ANWAR HARKARE | Collage- A G Patil polytechnic institute, solapur. | Email- [email protected]
Comments
One response to “Smart Home Automation and Energy Management | Final Year Project 2018”
How will IoT working there is no electricity. And thus the security systems would stop working. Making out home vulnerable.
Please tell a solution.