How To Control Lights Through Mobile App Using Bluetooth Module HC-06 and Arduino
Nowadays the home automation is becoming more and more popular due its abundant advantages. Home automation systems can range from simple remote control of lighting through to complex computer/micro-controller based networks with varying degrees of intelligence and automation. Home automation is adopted for reasons of ease, security and energy efficiency. Here, our aim is to design a kit that can be used for controlling AC Loads from Android phone via Bluetooth by using Arduino as microcontroller. Here I’m using Arduino Uno r3 which is a microcontroller board based on the ATmega328 that can be purchased from amazon, sparkfun etc.
To control the relays and thereby the lights we need to make a driver circuit which is needed for the driving purpose as well as for the isolation of the AC power with the Arduino (Dc power). For the driving purpose the LM293d can also be used. In the upcoming posts I’ll discuss about the motor driver IC i.e. LM293d.
List of components required-
- Arduino Uno r3
- HC-06 Bluetooth module
- Power supply for Arduino and relay circuit (battery can be used)
- Mosfet (IRF510)
- Jumper Wires
- DC Relays (12 V DC)
- Diode 1N4007 (To block the reverse current)
- Resistances 1K and 10 K
- Ac Mains (230 V)
- Lamp
Circuit Diagram To Drive The Relay Through Arduino
Pin configuration of IRF510
The IRF510 is a N-Channel enhancement mode silicon gate power field effect transistor. For further details you can see the datasheet of the MOSFET. And the pin configuration is shown below-
Connecting Arduino with the driver circuit
Driver Circuit Arduino
Vin – Pin 13
GND – Arduino Ground
And the Vcc is connected with the 12 V power supply that we’ve designed (full wave bridge rectifier) in the previous post: how to design your own DC Power Supply for Arduino.
Connecting the Bluetooth Module HC-06
The Bluetooth module is used for communication between smart phone and the Arduino. The module is powered from Arduino 3.3 volt supply. The HC-06 Bluetooth module contains four pins namely TXD (for the transmission of data), RXD (for receiving the data), VCC and GND (used for powering up the module). The Arduino pins 0 and 1 are specified for Universal Asynchronous Receiver/Transmitter (UART) that control the interface with its attached serial devices.
HC-06 Arduino
TX – RX (pin 0)
RX – TX (pin 1)
VCC – 3.3 volt supply from Arduino
GND – Arduino ground
Working
When the switch on button is pressed in the application the mobile will send a signal to the Arduino board through HC-06 module which will put pin 13 in HIGH state, meaning 5V on pin 13. This voltage is used to drive the MOSFET that will switch ON the relay and the load will be powered from the main power supply. Similarly, when the command sent is switch off through the app then the pin 13 will be in LOW state therefore switching OFF the lights.
We’ve used an external power supply (Vcc) that is between 7 to 12 volts to power up the Arduino board and the transistor + relay. For this purpose we’ve already made a full wave bridge rectifier. The load uses its own power supply, for instance if you use a light bulb then you might connect it to the 110/220V mains or any other power source.
Arduino code to control lights through HC-06
[code language=”c”]
const int relay = 13;
int val;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(relay, OUTPUT);
Serial.begin (9600);
}
// the loop routine runs over and over again forever:
void loop()
{
if(Serial)
{
if(Serial.available()>0)
{
val=Serial.read();
Serial.println(val,DEC);
relaycontrol(val);
}
}
}
void relaycontrol(int val)
{
switch(val)
{ case 97 : turnon();
break;
case 101 : turnoff();
break;
default: turnoff();
}
}
void turnon()
{
digitalWrite(relay, HIGH);
delay(1000);
}
void turnoff()
{
digitalWrite(relay, LOW);
delay(1000);
}
[/code]
You can also learn how to make Android Application For Bluetooth Controlled Lights suing MIT App Inventor.
If you still have any doubts feel free to ask. Suggestions are welcomed. Thank you for reading.