Subscribe To Our List

We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
Email address
Secure and Spam free...

In the DIY Arduino Home Automation System, we will control four light bulbs and two fans with speed control. The relay module will control the four bulbs and the two motors will be controlled by L298N motor driver. The Bluetooth module will make the connection between the Arduino and the Android App. The App that we are going to use can be downloaded from here.

Required Components for DIY Arduino Home Automation System

The components required for DIY Arduino Home Automation System are as follows

  • Arduino
  • L298N Motor Driver
  • HC-05 or HC-06 Bluetooth Module
  • 4 channel Relay module
  • 4 X light bulbs
  • 2 X DC motors
  • 12V battery (I have used three rechargeable cells)

Circuit Diagram

Firstly make the connections for the L298N motor driver with the Arduino. The connections are as follows

L298N

Arduino Uno

ENA

Pin 11

IN1

Pin 13

IN2

Pin 12

IN3

Pin 9

IN4

Pin 8

ENB

Pin 10

12V

Positive end of 12V Battery

Gnd

Negative end of 12V battery and to GND of Arduino

5V

Vin of Arduino

Then connect the two DC motors to the two sides of the L298N motor driver.

After that, connect the 4 channel relay module with the Arduino. The connections for the input side of the relay module with the Arduino are as follows

Relay Module Arduino
GND GND
IN1 Pin 7
IN2 Pin 6
IN3 Pin 5
IN4 Pin 4
VCC 5V Pin

On the output side of relay, make the connections as follows

Warning

High Voltage. Be careful

  • Connect the one wire of AC source to the Common(C) of all the four relays.
  • Connect the other wire of AC source to one end of all the four bulbs.
  • Connect the Normally open (NO) of all the four relays to other end of the four bulbs.

If you want to read more about Relay module interfacing with Arduino, then read this tutorial | Relay Module interfacing with Arduino

In the end, make the connections for the Bluetooth module with the Arduino.

Bluetooth Module Arduino
VCC 5V
GND GND
TX Pin 2
RX Pin 3

If you want to read more about Bluetooth module interfacing with Arduino, then read this tutorial | Arduino Bluetooth Module Tutorial

DIY Arduino Home Automation System

How it works

First of all, download the App from here. The App will look like shown below.

DIY Arduino Home Automation System

Start the Bluetooth of your mobile and press the “Press to connect Bluetooth” button. From the options, select your Bluetooth module. After connecting, when you will press the buttons on the App, the respective bulb or LED will ON or OFF.

Code

#include <SoftwareSerial.h> // TX RX software library for bluetooth
int bluetoothTx = 2; // bluetooth TX to pin 2
int bluetoothRx = 3; // bluetooth rx to pin 3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

//Initializing pins for relay which will control bulbs
int Bulb1 = 4;
int Bulb2 = 5;
int Bulb3 = 6;
int Bulb4 = 7;

//Initializing pins for L293N motor controller
int EN_A = 11; //Enable pin for first motor
int IN1 = 13; //control pin for first motor
int IN2 = 12; //control pin for first motor
int IN3 = 8; //control pin for second motor
int IN4 = 9; //control pin for second motor
int EN_B = 10; //Enable pin for second motor

void setup()
{
//Making the relay pins as output pins
pinMode(Bulb1,OUTPUT);
pinMode(Bulb2, OUTPUT);
pinMode(Bulb3, OUTPUT);
pinMode(Bulb4, OUTPUT);

//Relay works opposite so relay pins will be HIGH when powering on
//For relay HIGH means LOW and LOW means HIGH
//In below lines,we have made the relay pins lower because these will HIGH when powering
digitalWrite(Bulb1, HIGH);
digitalWrite(Bulb2, HIGH);
digitalWrite(Bulb3, HIGH);
digitalWrite(Bulb4, HIGH);

//Making the L298N motor driver pins as output pins
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(EN_A, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(EN_B, OUTPUT);

//Setup usb serial connection to computer
Serial.begin(9600);
//Setup Bluetooth serial connection to android
bluetooth.begin(9600);
}

void loop()
{
//Read from bluetooth and write to usb serial
if(bluetooth.available()> 0 ) // receive number from bluetooth
{
int command = bluetooth.read(); // save the received number to command
Serial.println(command); //Printing on the Serial Monitor
//Turning Bulbs and Fan ON according to the buttons pressed on Android App

switch (command){
case 1:
digitalWrite(Bulb1, LOW);
break;

case 2:
digitalWrite(Bulb1, HIGH);
break;

case 3:
digitalWrite(Bulb2, LOW);
break;

case 4:
digitalWrite(Bulb2, HIGH);
break;

case 5:
digitalWrite(Bulb3, LOW);
break;

case 6:
digitalWrite(Bulb3, HIGH);
break;

case 7:
digitalWrite(Bulb4, LOW);
break;

case 8:
digitalWrite(Bulb4, HIGH);
break;

case 9:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
break;

case 10:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
break;

case 11:
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;

case 12:
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
}

//Controlling the speed of Fan motors
//On moving the Top slider, we will get value from 20 to 90 in serial monitor
//We will map this value to 0-255 to control the speed of motor
if(command >=20 && command <=90){
int motor1_speed = map(command, 20, 90, 0, 255);
analogWrite(EN_A, motor1_speed);
}

//On moving the Bottom slider, we will get value from 91 to 180 in serial monitor
//We will map this value to 0-255 to control the speed of motor
if(command >=91 && command <=180){
int motor2_speed = map(command, 91, 180, 0, 255);
analogWrite(EN_B, motor2_speed);
}
}
}

Video


If you have any questions, feel free to ask us in the comment section.

JOIN OUR NEWSLETTER
We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
We hate spam. Your email address will not be sold or shared with anyone else.

Leave a Reply

Your email address will not be published.

Subscribe To Our List

We help electronics hobbyists to create projects related to Micro-controllers. Join our newsletter to get access to new projects first.
Email address
Secure and Spam free...
Skip to toolbar