Bluetooth Controlled Home Automation System Along With LDR Based Night Light
by ArpitAgrawal in Circuits > Wireless
1900 Views, 17 Favorites, 0 Comments
Bluetooth Controlled Home Automation System Along With LDR Based Night Light
Hello All,
This is an instructable about control of light and door of a house using an android app. The light is also controlled by an LDR, which is overridden by the app.
I have used a Bluetooth module HC-05 for interfacing the MCU with the app.
Here is the list of equipment required for this instructable:
Input:
1)BT Term application installed on Bluetooth enabled Cell phone
2)LDR
Output :
3) LED light (When there is dark)
4) Door Opening/Closing
Actuator :
4)Motor- 12V DC, 30 rpm
Electrical components:
6) Microcontroller - Arm Cortex M4 (TM4C123GXL)
7) Bluetooth Module – HC-05
8)Relay switch, 120VAC, 10 Amp
9)Motor Driver (Battery)
10) LDR – 12mm
Understanding LDR and HC-05
A Light Dependent Resistor (LDR) is a resistor whose resistance varies with the intensity of light. The higher the intensity of incident light, lower will be the resistance offered by an LDR. It is very similar to a Metal Oxide Varistor (MOV) whose resistance varies with the voltage across it.
The LDR can be connected in series with the 60K resistor and connected across the 5V source. In daylight, the resistance of the LDR will be low and so the voltage across the 60K resistor will be high. During the night, high resistance of the LDR will lead to almost 0V across the 60K resistor. This voltage difference can be sensed by the MCU, which can then turn on/off the light.
The resistor value can be appropriately selected depending upon the used LDR (attached image shows the used circuit with a 10K resistor).
HC-05 module is an easy to use Bluetooth SPP (Serial Port Protocol) module, designed for transparent wireless serial communication setup. Serial port Bluetooth module is fully qualified Bluetooth V2.0 + EDR (Enhanced Data Rate) 3Mbps modulation with complete 2.4GHz radio transceiver and baseband.
UART interface is used to connect HC-05 and MCU. HC-05 has an auto pairing PINCODE, which can be modified thereby making it secure. The default baud rate in slave mode is 9600. Data bits:8, Stop bit:1, Parity: No parity. The above format can be modified by programming the HC-05
The MCU UART should be programmed according to the selected format.
Operating the Door
The door is operated using a motor. An SPDT relay is used for controlling the motor. The relay is an electro-mechanical device, which provides power to the load when its coil is actuated. This serves multiple purposes:
1. Controlling the motor
2. Providing high voltage to the motor
3. Isolating the low voltage MCU side from the high voltage side.
Using Bluetooth Application
Here an available application (S2 terminal for Bluetooth) is used for control. Power the setup and notice the blinking pattern of the LED provided with the HC-05 module.
Open the application and pair it with the HC-05 module. When the device is paired the LED blinks 1 time/2sec.
We can then send the pre-decided signals to operate the automation system.
Flow Chart and Program
I have attached the system flow chart and the corresponding program is as below:
#include
#include
#include"C:\ti\TivaWare_C_Series-1.1\inc\tm4c123gh6pm.h"
#include"C:\ti\TivaWare_C_Series-1.1\driverlib\sysctl.h"
volatile unsigned long j=0;
volatile unsigned long a=0x0;
volatile unsigned long i=0;
int main()
{ SYSCTL_RCGCUART_R |=0x0000008;
//SYSCTL_RCGCSSI_R|= 0x00000001;
SYSCTL_RCGC2_R|= 0x00000004;
SYSCTL_RCGC2_R|= 0x00000002;
SYSCTL_RCGC2_R|= 0x00000020;
GPIO_PORTC_DEN_R|=0XFF;
GPIO_PORTC_AFSEL_R|=0XC0;
GPIO_PORTC_PCTL_R|=0X11000000;
i=0;
while(i<1000)
{
i=i+1;
}
UART3_CTL_R&=0XFFFFFFFE;
UART3_IBRD_R|=0X68;
UART3_FBRD_R |=0X0B;
UART3_LCRH_R|=0X60;
// GPIO_PORTC_DR2R_R|=0XC0;
//GPIO_PORTD_AMSEL_R=0X00;
// GPIO_PORTC_DEN_R|=0XFF;
//GPIO_PORTC_DEN_R&=0XbF;
GPIO_PORTF_DIR_R=0XFF;
GPIO_PORTF_DEN_R=0XFF;
//GPIO_PORTA_DATA_R|=0XC0;
//GPIO_PORTF_DATA_R|=0X02;
UART3_CTL_R|=0X01;
GPIO_PORTB_DIR_R|=0X10;
GPIO_PORTB_DIR_R&=0Xbf;
GPIO_PORTB_DEN_R|=0XFF;
GPIO_PORTB_AFSEL_R&=0XdF;
//GPIO_PORTC_PCTL_R|=0X11000000;
while(1)
{//UART3_DR_R=0X31;
if ((GPIO_PORTB_DATA_R&0X20)==0X00 )
{GPIO_PORTF_DATA_R|=0X04;
GPIO_PORTB_DATA_R&=0XEF;
}
// while ((UART3_FR_R &0X10)!=0 )
// {}
a=UART3_DR_R&0xff;
if (a==0x31 )
{GPIO_PORTF_DATA_R=0X04;
GPIO_PORTB_DATA_R&=0XEF;
}
else if (a==0X32 )
{GPIO_PORTF_DATA_R&=0XFB;
GPIO_PORTB_DATA_R|=0X10;
else if (a==0X33 )
{GPIO_PORTF_DATA_R|=0X04;
GPIO_PORTB_DATA_R|=0X10;
else
{GPIO_PORTF_DATA_R&=0XFB;
GPIO_PORTB_DATA_R&=0XEF;}
}
}