Home Automation is the new trend among urban households. Home automation system allows controlling home appliances through a remote. The remote can be an IR remote, RF remote or even a mobile phone. An internet based home automation system could be most accessible setup because such a system can be controlled from anywhere and anytime. Like, one is returning home and before leaving office and getting into the car, he can switch on the AC of his living room so that by the time he reaches home, the living room is already cooled. Such an advantage can be availed only on a home automation which is controlled over the internet.
This is IOT project for home automation built on Particle Photon. The home appliances are connected to the Particle Photon through a relay circuit. Some sensors like DHT-11 Temperature and humidity sensor and LDR sensor for detecting light intensity are also interfaced to the Particle Photon. The Photon is connected to the cloud service via Wi-Fi connection and commands to control the appliances are passed through a web page which is transferred via Particle’s Cloud Service.
Particle Photon is an Arduino compatible IOT board. For writing the program code for any Photon, the developer needs to create an account on Particle website and register the Photon board with his user account. The program code then can be written on Web IDE at the Particle’s website and transferred to a registered IOT board over the internet. If the selected Particleboard, Photon here, is switched on and connected to cloud service of the Particle, the code is burnt to the selected board over the air via the internet connection and the board starts operating according to the transferred code.
For controlling board over the internet, a web page is designed which uses Ajax and Jquery to send data to the board using HTTP POST method. The web page identifies the board by a device ID and connects to the Particle’s Cloud Service through an access token.
Components Required –
Receiver Side:
1. Particle Photon.
2. DHT11 sensor.
3. LDR sensor.
4. A home Wi-Fi connection.
5. 12V Relay
6. BC547 transistor
7. 1K ohm resistor
8. 5 mm LED
9. Two pin plug
10. Three pin holder
Transmitter Side:
1. Web Page (EngineersGarageIoT.html)
Block Diagram –
Fig. 1: Block Diagram of Particle Photon based IoT Home Automation System
Circuit Connections –
Fig. 2: Prototype of Particle Photon based IoT Home Automation System
The relay circuit operating the switching function of appliances is connected to the Particle Photon. There are also two sensors – DHT-11 Temperature and Humidity sensor and LDR sensor interfaced to the board for monitoring temperature, humidity, and light intensity. The circuit is assembled in the following manner –
Power Supply – In the circuit, Particle Photon and sensor modules need a 5V regulated DC while relays need 12V regulated DC for their operation. The AC mains is used as the primary source of power. The supply from the mains is stepped down by a transformer and rectified by a full-bridge rectifier. The rectified output is regulated to 5V and 12V using 7805 and 7812 ICs. The pin 1 of both the voltage regulator ICs is connected to the anode of the battery and pin 2 of both ICs is connected to ground. The respective voltage outputs are drawn from pin 3 of the respective voltage regulator ICs. A LED along with a 10K Ω pull-up resistor is also connected between common ground and output pin to get a visual hint of supply continuity.
Relays – The 12V 2A relays are used to switch the AC appliances ON or OFF in the project. The relays are connected to the pins D0, D1, D2 and D3 of Particle Photon via BC547 transistor circuits connected in a common emitter configuration. The phase wire from the AC supply is provided at the COM terminal of the relays. When a HIGH logic is received at the interfaced microcontroller pins, the COM point switches from NC to NO point where a relay short-circuits the phase with the neutral wire switching the supply to the appliance ON. The LEDs are connected parallel to the relay circuit with pull-up resistors in series. These LEDs give a visual hint of the ON/OFF status of appliances.
DHT-11 Temperature and Humidity Sensor – The DHT -11 sensor reads the ambient temperature and humidity and relays the data to the microcontroller as digital data. The data pin of temperature and humidity sensor DHT11 is connected to pin A0 of the Particle Photon and VCC and ground are connected to the common VCC and ground.
LDR Sensor – The LDR is used to sense the intensity of light. The sensor is connected to the A1 pin of Particle Photon. The sensor is connected in a potential divider circuit. The LDR provides an analog voltage which is converted to digital reading by the inbuilt ADC.
How the circuit works –
Fig. 3: Image showing Particle Photon based IoT Home Automation System in action
Once the program code is transferred to Particle Photon, it starts operating according to it. The Particle Photon should be connected to any internet hotspot via Wi-Fi. The Arduino compatible code on Photon initially switches all the appliances OFF by passing a LOW logic at the pins connecting the relays and starts fetching data from the sensors.
DHT11 Temperature and Humidity Sensor is a digital sensor with inbuilt capacitive humidity sensor and Thermistor. It relays a real-time temperature and humidity reading every 2 seconds. The sensor operates on 3.5 to 5.5 V supply and can read temperature between 0° C and 50° C and relative humidity between 20% and 95%. The DHT 11 Sensor sends data in the digital form to a controller pin on the one-wire protocol which must be implemented on firmware side. First, the data pin is configured to input and a start signal is sent to it. The start signal comprises of a LOW for 18 milliseconds followed by a HIGH for 20 to 40 microseconds followed by a LOW again for 80 microseconds and a HIGH for 80 microseconds.
After sending the start signal, the pin is configured to digital output and 40-bit data comprising of the temperature and humidity reading is latched out. Of the 5-byte data, the first two bytes are an integer and decimal part of reading for relative humidity respectively, third and fourth bytes are an integer and decimal part of reading for temperature and the last one is checksum byte. The one-wire protocol is implemented on the firmware using an open-source library available for Photon.
The IR sensor output an analog voltage at the interfaced controller pin. The analog voltage is read and digitized using inbuilt ADC channel. The analogRead() function is used to read analog voltage at the controller pin.
The read sensor data is passed to the Particle Cloud via Wi-Fi connection and the board waits for the command to switch appliances on the air. The user has displayed sensor data on the web page and has buttons to switch devices ON or OFF on the same web page. As the user taps a button to switch a device ON or OFF, the command is transferred over the internet via Particle’s Cloud service in the form of serial strings. The strings are received via HTTP POST method by the Particle Photon. On detecting command, the board switches the digital logic at the respective pin to either HIGH for switching the device ON or LOW for switching the device OFF.
Check out the photon code to learn how the Arduino compatible code detects command over the air and reads data from sensors and publish it on the linked data logging URL.
Programming Guide –
Photon Code
First of all the library for DHT sensor is imported. The library is automatically added by the particle’s Web IDE. A constant is defined to denote pin to which DHT 11 sensor is interfaced and a constant is defined to denote a variant of DHT sensor. Variables to hold the value of temperature, humidity and light intensity are declared. Variables denoting home appliances are declared and assigned microcontroller pins. An object of DHT type is declared.
A character array is declared to hold the sensor data to be sent to the web page.
The setup() function is called in which pin connected to relays are declared output pin using pinMode() function. The DHT sensor is initialized by calling begin() method on the DHT object. A variable getpos and function setpos are exposed from the cloud and retrieved through POST method by calling Particle.variable and Particle.function methods. The setup() function is run only once at the start of the code.
The loop() function is called which iterates infinitely. In the loop() function, the data from the DHT sensor is fetched using getTempCelcius() and getHumidity() methods on the DHT object. The data from LDR sensor is fetched by calling analogRead() method and converted to light intensity using standard formulae. The data from different sensors is stored in variables, wrapped in proper strings and sent to the data logging URL using publish() method on Particle object.
Fig. 4: Screenshot of Loop Function in Photon Code for IoT based Home Automation System
This is HTML file that needs to run for sending data to Particle’s Cloud service. The cloud service automatically connects to the Photon and Code on Photon operates according to the data received from the cloud.
HTML Code
For controlling the home appliances over the Internet, a web page needs to be created. The web page will have the following HTML and Javascript embedded inline.
The doctype is declared for setting the page to HTML 5 version and the head element is added. Inside the head element, the character set is defined utf-8 and the web page is set to span over the entire window. The Bootstrap for CSS and Javascript is included from CDN using the link element.
The body element is declared and an additional division element is declared to hold the content of web page. The web page is structured through other division elements and some headers paragraph and buttons elements are added.
The javascript is embedded in which the device ID and access token are declared as variables and a function switchLED is created to format the command string to be passed to the Particle board. The elements on the page are accessed through JavaScript function getElementbyID. The sensor data is fetched using JSON.parse() method and embedded to HTML elements using innerHTML method. The $.Post method is used to retrieve data from the cloud using HTTP POST method.
Fig. 5: Screenshot of Webpage controlling IoT based Home Automation System
This is HTML file that needs to run for sending data to Particle’s Cloud service. The cloud service automatically connects to the Photon and Code on Photon operates according to the data received from the cloud.
The complete code for internet-based home automation can be found in the source code tab.
Note: The HTML file can be downloaded from the attachment mentioned below.
You may also like:
Project Source Code
###
//Program to // This #include statement was automatically added by the Particle IDE. #include// DHT parameters #define DHTPIN A0 #define DHTTYPE DHT11 // Variables int temperature; int humidity; int light; int motion; int ultraviolet; int light_sensor_pin = A1; int uv = A3; int pos = 0; // Pins int Device0 = D0; int Device1 = D1; int Device2 = D2; int Device3 = D3; // DHT sensor DHT dht(DHTPIN, DHTTYPE); // publishjson.ino -- Spark Publishing Example unsigned long lastTime = 0UL; char publishString[64]; void setup() { Serial1.begin(9600); pinMode(Device0,OUTPUT); pinMode(Device1,OUTPUT); pinMode(Device2,OUTPUT); pinMode(Device3,OUTPUT); digitalWrite(Device0,LOW); digitalWrite(Device1,LOW); digitalWrite(Device2,LOW); digitalWrite(Device3,LOW); dht.begin(); Particle.function("setpos", setPosition); Particle.variable("getpos", &pos, INT); } void loop() { // Temperature measurement temperature = dht.getTempCelcius(); // Humidity measurement humidity = dht.getHumidity(); // Light level measurement float light_measurement = analogRead(light_sensor_pin); light = (int)(light_measurement/4096*100); int uvValue=analogRead(uv); ultraviolet = (uvValue*100)/4023; unsigned long now = millis(); Particle.function("led",ledControl); //Every 5 seconds publish uptime if (now-lastTime>5000UL) { lastTime = now; sprintf(publishString,"{"Temperature": %u, "Humidity": %u, "Light": %u}",temperature,humidity,light); Particle.publish("Uptime",publishString); } } int setPosition(String posValue) { pos = posValue.toInt(); Serial1.printf("%u", pos); return 0; } int ledControl(String command) { int state =0; int pinNumber = (command.charAt(1)-'0') - 1; if(pinNumber < 0 || pinNumber > 7) return -1; if(command.substring(3,7) == "HIGH") state = 1; else if(command.substring(3,6) == "LOW") state = 0; else return -2; digitalWrite(pinNumber,state); return 1; } ###
Circuit Diagrams
Project Video
Filed Under: Electronic Projects
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.