recent posts

banner image

AVR Microcontroller Based Home Automation System

Introduction


In this project I have made a  microcontroller based home automation system. Automation of home appliance is done by the help of different sensors. I have used here programmable ATmega32 microcontroller chip which is able to read data from different sensors, analyze the data and control different home appliances simultaneously. The microcontroller is also able to show sensors data and home appliances ON-OFF status in a user friendly way.

It is essential to mention that; here we turn on or off different load such as room light, overhead tank water pump, central AC and central heating system automatically. This automation system is only active when the home is occupied by any person. The output from different sensors such as; person count, current room temperature, day night sensing and the level of water from overhead water tank shows on LCD display in real time. These mentioned works are accomplished by the predetermined program flashed on microcontroller chip. The ultimate goal of this project is to create a functional microcontroller & sensor based home automation where home appliances controlled without any human interaction. For this project, it is important that the Microcontroller scheme be able to save our time and reduces energy cost by precise sensing.

The Result


Our Scheme


Here is a figure of overview about our project.




Features


1. Counter dependent automatic switching system of home

In the system we have an intelligent person counter set at the entry/exit passage of the room or house. When the person enters to the home the counter gets incremented. Now whatever may be the number of people entering the house the counter will automatically get incremented by itself and on leaving the room the counter will get decremented but the system will keep on working .Once the counter is zero in other words once everyone leaves the house the switching system will automatically stop working.

2. Temperature sensing and control home appliance (AC, heater)

Temperature sensor precisely senses the temperature of the room. When the home temperature drops below 20°C then the central heating system will automatically switch on and when the home temperature goes above 26°C then the central AC will automatically switch on. On the normal room temperature both heater and AC remains switch off.

3. Day light sensing and control room light

If it is a day then the lights would not be switched on but if it is dark then the lights will automatically switch on. On foggy days where as daylight is low room light will be turned on.

4. Overhead tank water level sensing and control water pump

Water level sensor sense the level of water from the overhead tank. It will sense 4 levels of water; Empty or less than 25%, Quarter or more than 25%, Half or 50%, and Full or 100%. If it is empty then the water pump will automatically switch on and when tank is full, the water pump will automatically switch off.

5. Display on LCD

Our project included a 16x2 LCD display for displaying the number of person present in the home, current room temperature, Day/Night status and current water level from the overhead tank. It will also display the ON/OFF status of room light, AC, Heater and the water pump.


Flowchart


Fig. Flow diagram of the project




Circuit Design and Diagram

  • Two way Person Counter Module

Person counter module made of two pair of Infrared transmitter and receiver sensor set at the entry-exit passage of the home. If the 1st pair of IR sensor interrupted first and then it comes from 2nd pair of IR then person count will incremented by 1. If the number of person is greater than zero (0), the MCU will enter to the main program and follow the predetermined task. If the interruption come from 2nd pair of IR sensor first and then from 1st pair of IR then person count will decremented by 1. If the number of person in the home is equal to zero then MCU will return to the person check loop. In this loop all relay will keep turned off.
Circuit Diagram:
Fig. 4.6: Circuit diagram of two way person counter module
The following circuit shown in Figure 4.6 is our person counter with two Infrared transmitter-receiver pair. D1 and D3 are the Infrared transmitter LEDs. Q1 and Q2 are the Infrared receiver phototransistors. D1 and D3 are set to emit infrared light beam on corresponding IR receiver phototransistors. We have used two Operational Amplifier (LM358) as comparator. We gives a voltage of 2.5volt on Op-amps non-inverting input (pin 3) and the collector terminal of NPN phototransistor is connected to the inverting input of the Op-amp. When Q1 is on active mode the voltage on collector is around zero and the comparators output keeps high as non-inverting input is greater than inverting input. The output of Op-amps are connected to MCUs corresponding INT0 and INT1 pin. When infrared light falling on receiver phototransistors base are interrupted by obstacle the phototransistors goes cut-off mode and thus the voltage on inverting terminal goes high (around 5volts). For this case the output of Op-amps goes low (around 0 volt). In this falling edge of output from LM358 shown as Fig. 4.7 MCU generates an interrupt.

Output:
Case 1: When the number of person in the room is 0,
Case 2: When the number of person is greater than 0, the number of person will be displaying on LCD and the others predetermined task executed simultaneously.
4.3 Temperature Sensing and AC & Heater Control
Temperature sensor module will sense the temperature of the house. If the temperature is less than 20°C then the room heater will turned on and if the temperature is above 26°C the AC will turned on. On the normal room temperature both AC and heater will remain off.

Circuit Diagram:
Fig 4.10: Circuit diagram of temperature sensor
LM35 sensor:
Fig 4.11: LM35 precise centigrade sensor
We have used LM35 shown as Fig. 4.11 for sensing room temperature. The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35’s low output impedance, linear output, and precise inherent calibration make interfacing to readout or control circuitry especially easy.  As it draws only 60μA from its supply, it has very low self-heating, less than 0.1°C in still air. The LM35 is rated to operate over a −55° to +150°C temperature range. It works linear + 10.0 mV/°C scale factor.

Analogue to Digital Conversation (ADC):
We live in an analog world where the information we see, hear, process and exchange with each other, is always an analog quantity; pressure, temperature, voltage and current are always analog entities. Here in LM35 for every degree centigrade of temperature change LM35 sensors output changes 10mVolt respectively. Thus the input of temperature data to the MCU is analogue. But most of our Microcontrollers are digital in nature. They can only differentiate between HIGH or LOW level on input pins. For example, if input is more than 2.7v it will be read as 1 and if it is below 2.7 then it will be read as 0 (in case of 5v systems). So we cannot measure voltage directly from MCUs. To solve this problem most modern MCUs have an ADC unit. Our ATmega32A features a 10-bit successive approximation ADC. The ADC is connected to an 8-channel Analog Multiplexer which allows 8 single-ended voltage inputs constructed from the pins of Port A. The single-ended voltage inputs refer to 0V (GND). The reference voltage of ADC is connected to 5 volt with a filter circuit (AREF pin).
The output of LM35 is connected to the MCU’s PA0 pin which is also named as ADC0 pin. Since ATmega32 has 10 bit ADC it can converts analogue voltage to 210=1024 levels. While the 10 bit ADC will break the range in 5/1024 = 4.8mV approx. So we can see that the 10 bit ADC precisely measure 4.8mV range.
We need to measure and show the analog temperature data from MCU. For this case Digital to Analog conversation is needed.
The formula is, temperature = (5/1024)*adc_read
temperature = temp*100
Since the LM35 measures temperature in mili-volt scale we can get our final temperature by multiplying 100 with previous result and the formula for showing temperature in Fahrenheit scale is,
temperature in Fahrenheit = (9.0 / 5.0) * temp + 32.0
Fig. 4.12: 8 channel ADC of ATmega32A Micro-controller
We have connected the relay of AC and Heater to the MCUs PB1 and PB0 pin respectively. This pins are set to output with the help of Data Direction Registers (DDR) and initially this pins are set to low by PORT register of Microcontroller. These PINs goes high for several pre-defined task.
Fig. 4.13: Relay Connection for AC and Heater
Output:
Case 1: Temperature in between 20°C to 26°C. This is our preset normal room temperature. In this situation both relay for Ac and Heater will remain off

Case 2: Temperature is more than 26°C. For this condition the relay for AC will turned on.
Case 3: Temperature is less than 20°C. For this condition the relay for Heater will turned on.



4.4 Daylight Sensing & Room light control
Automatic room light will be controlled with varying the intensity of daylight presence in the room. On low light or night the room lights are turn on and on the daylight room lights are remain off. We have done this by using light dependent resistor (LDR) with the help of MCUs analog to digital conversation (ADC) module.

Light Dependent Resistor, LDR:
LDRs or Light Dependent Resistors also known as photo resistor are very useful especially in light/dark sensor circuits. A LDR works on the principle of photo conductivity. Photo conductivity is an optical phenomenon in which the materials conductivity (Hence resistivity) reduces when light is absorbed by the material. When light falls i.e. when the photons fall on the device, the electrons in the valence band of the semiconductor material are excited to the conduction band. These photons in the incident light should have energy greater than the band gap of the semiconductor material to make the electrons jump from the valence band to the conduction band. Hence when light having enough energy is incident on the device more & more electrons are excited to the conduction band which results in large number of charge carriers. The result of this process is more and more current starts flowing and hence it is said that the resistance of the device has decreased.

Fig. 4.14: Light Dependent Resistor (LDR)
In dark, its resistance is very high. This resistance is called as dark resistance. It can be as high as 10MΩ. When a light level of 1000 lux (bright light) is directed towards it, the resistance decreases to only few hundred ohms.
Fig. 4.15: Resistance vs. Illumination chart

Circuit Diagram:
Fig. 4.16: Circuit diagram of LDR and relay with MCU
We have connected LDR with a 10K ohm resistor and the common point of two resistors following to the MCUs ADC channel ADC1 (PA0) pin as shown Fig. 4.15. The relay of room light is connected to the PB3 pin which is declared as output with the help of PORT register of MCU. In night LDR’s Dark resistance is almost 1M ohm. For this instance voltage on ADC1 pin is almost 5volt. In low light LDRs resistance decreases around 200K ohm to 35K ohm. From the voltage divider rule we will get voltage across the LDR (ADC1 pin) around 4.7volt to 3.7volt. With the help of Analog to Digital Conversation ADC for both of night and low light condition MCU will turn on the relay for light.
In daylight LDRs resistance fall down from 20K ohm to 500 ohm. In this condition the voltage on ADC1 pin also decreases from 3.5 volts to 0.25 volts. For this condition the output pin PB3 goes low and the relay RL3 for room light turns off.
Output:
Case 1: No daylight
Case 2: Low daylight
Case 3: Bright daylight
4.5 Overhead Tank Water Level Sensing and Water Pump Control
Overhead water level sensor is made of different current conducting probes placed at different levels of water tank. Probe-1 placed at full level, probe-2 at half level, probe-3 at quarter level and probe-4 is GND. Probe 1, 2 & 3 connected with Q1, Q2 & Q3 transistors base with 1K ohm resistor terminal respectively. These are bipolar NPN transistor. For level sensing Microcontrollers PB5, PB6 & PB7 pins are connected to Q1, Q2 & Q3 transistors collector terminal respectively.

Circuit Diagram:
Fig. 4.17: Circuit diagram of water level sensor
We have enabled pull up for MCU’s PB5, PB6 & PB7 pin. We have used 3 NPN transistor for switching. Initially when the tank is empty the voltage on base terminal of all 3 transistors are zero. At this stage all transistors remains OFF. So we get the voltage at PB5, PB6 & PB7 high. This is the logic for Empty tank in our program. For this instance PB2 pin will be high and the relay RL4 for water pump will turned on. The relay is switched on by a NPN transistor which base is connected to PB2 pin.
Fig. 4.18: Relay for pump and Buzzer connection
When the water level touches Probe-3 it will be connected to 5V and thus the base terminal of Q3 will get a voltage. So the NPN Q3 will switched on and we get the voltage at collector terminal (PB7) low. For this condition MCU displayed Level Quarter on LCD and the pump will keep turned ON.
When the water level touches Probe-2 it will be connected to 5V and thus the base terminal of Q2 will get a voltage. So the NPN Q2 will switched on and we get the voltage at collector terminal (PB6) low. For this condition MCU displayed Level Half on LCD and the pump will keep turned ON.
When the water level touches Probe-1 it will be connected to 5V and thus the base terminal of Q1 will get a voltage. So the NPN Q1 will switched on and we get the voltage at collector terminal (PB5) low. For this condition MCU displayed Level Full on LCD, The buzzer beeped for a moment and the pump will turned off.


Water Discharging State:
At the period of water discharging from the water tank level sensing will going on with the previous logic. At this stage water pump will remain turned off. The water pump will turned on only when the water level goes on empty state.
Buzzer:
Piezoelectricity is the charge which accumulates in certain solid materials in response to mechanical pressure, but also providing the charge to the piezoelectric material causes it to physically deform. One of the most widely used applications of piezoelectricity is the production of sound generators, called piezo buzzers. Piezo buzzer is an electric component that comes in different shapes and sizes, which can be used to create sound waves when provided with analog electrical signal.
                                         Fig. 4.19: Buzzer volume control on PWM
Microcontrollers can create sound by generating a PWM (Pulse Width Modulated) signal – a square wave signal, which is nothing more than a sequence of logic zeros and ones. Frequency of the square signal determines the pitch of the generated sound, and duty cycle of the signal can be used to increase or decrease the volume in the range from 0% to 100%.
We have connected our Piezo buzzer to the MCU’s PB7 pin. When the water tank is full the buzzer plays a tone of 880Hz for 500 millisecond and 698Hz for 500 millisecond.
Output:
Case 1: When tank is empty.

Case 2: When water level is quarter.

Case 3: When water level is half.

Case 4: When tank is full.



Water discharging state:
Case 1: Water level is half.

Case 2: Water level is Quarter.

4.6 LCD Display
We have used LM016L 16x2 LCD for displaying. It is a 16 character x 2 lines display. The pin out is given below:
Fig. 4.20: Pin out of 16x2 LCD
Pin Description:
Ø  VE is the LCD’s contrast voltage and should be connected to GND through 2.2K.
Ø  RS is the register select pin. To write display data to the LCD, this pin has to be high.
Ø  R/W is the data direction pin. For WRITING data TO the LCD it has to be low, for READING data FROM the LCD it has to be high. In our project we only want to write to the LCD so we can tie it to ground.
Ø  E is the Enable pin. When writing data to the LCD, the LCD will read the data on the falling edge of E.
Ø  D0 to D7 are data pin. We have use 4 bit data transfer so in our circuit diagram D0 to D3 are grounded.
Circuit Diagram:
Fig. 4.21: Circuit diagram of LCD connection
·        RS is connected to PC0 pin.
·        E is connected to PC1 pin.

D4, D5, D6 and D7 are connected to microcontrollers PC2, PC3, PC4 and PC5 pin respectively.



AVR Microcontroller Based Home Automation System AVR Microcontroller Based Home Automation System Reviewed by Musfikur on March 22, 2018 Rating: 5

No comments:

Powered by Blogger.