Home automation project using Arduino

Home automation using Arduino is a revolutionary concept that brings the power of technology to our living spaces, enabling us to control and manage various household functions effortlessly. By seamlessly integrating the capabilities of Arduino microcontrollers with everyday appliances, lighting systems, and environmental sensors, home automation offers the convenience of remote control, energy efficiency, and enhanced security.

This innovative approach allows homeowners to transform residences into smart, interconnected ecosystems, where tasks such as adjusting lighting, regulating room temperatures, and controlling electronic devices can be accomplished with a simple smartphone touch or even voice commands. In this dynamic landscape, the Arduino platform emerges as a versatile tool that empowers individuals to create customizable, efficient, and intelligent living spaces tailored to their preferences and needs.

Home automation project using Arduino

Home automation involves using technology to control and automate various household tasks and functions. In this project, we'll use an Arduino board to create a basic home automation system to control lights and appliances remotely. For this project, we will utilize the Bluetooth module to connect devices and implement automation remotely. Here's a step-by-step guide for you.

Hardware required

  • Arduino board (e.g., Arduino Uno)

  • Bluetooth module (HC-05)

  • Relay module(s)

  • Power supply (5V)

  • High-voltage appliances (e.g., light bulbs, fans)

  • Jumper wires

  • Smartphone with Bluetooth capability

The description of these hardware components is given as:

  • Arduino board: Select a suitable Arduino board, such as Arduino Uno or Arduino Nano. The board serves as the brain of the automation system.

  • Relay modules: Relay modules act as switches to control high-voltage appliances like lights and fans. Opt for relay modules with the appropriate channels based on your requirements.

  • Power supply: Ensure a stable power supply for the Arduino board and relay modules. Depending on the power requirements, you might need a 5V power adapter.

  • Smartphone/computer: Any device with internet connectivity can remotely control the automation system. Install a suitable application or interface for controlling the Arduino.

  • Bluetooth module (HC-05): It is used in electronics and microcontroller projects for wireless communication. Bluetooth enables devices to establish wireless connections and exchange data over short distances.

  • High-voltage appliances: This includes light bulbs, fans, motors, and other appliances that will be automated.

Compatibility

Remember that the Bluetooth module is only compatible with Android devices. It can't be used with IOS.

Block diagram

This block diagram represents the connections.

BLock diagram
BLock diagram

Circuit connections

For this project, let us automate two appliances. The circuit connections are as follows:

Connections of relay:

  • Connect the Vcc of the relay to the 5V terminal from Arduino.

  • Connect GND terminal to ground.

  • Connect IN terminal of the relay to the pin of Arduino. In our case, it is pin 9 for the lamp and pin 10 for the fan.

  • The relay outlets (NO- normally open, NC- Normally closed, COM- common) are connected such that the appliances are connected to the relay at the NO terminal, and the live wire (9V) from the supply is given at the COM terminal.

  • The NC terminal is left open. You can implement an alternate circuit and use it as well.

For now, we are using all DC power devices. If you decide to automate the AC power devices, then at the COM terminal of the relay, you connect the 220V AC supply wire.

Connections to Arduino board:

  • Connect the relay module's IN pin to the desired digital pin of the Arduino board (pin 9 and 10).

  • Connect the TX pin of the Bluetooth module to RX pin on the Arduino board and RX pin of the Bluetooth module to TX pin of the Arduino board.

  • Vcc and GND connections for the Bluetooth and relay module.

Ensure all appliances' ground is common, and the circuit is closed.

Circuit diagram

Circuit diagram
Circuit diagram

Code

char val;
const int appliancePin1 = 9; // Pin to control appliance 1
const int appliancePin2 = 10; // Pin to control appliance 2
void setup() {
pinMode(appliancePin1, OUTPUT);
pinMode(appliancePin2, OUTPUT);
Serial.begin(9600);
digitalWrite(appliancePin1, HIGH);
digitalWrite(appliancePin2, HIGH);
}
void loop() {
if (Serial.available()) {
val = Serial.read();
Serial.println(val);
}
if (val == '1') {
digitalWrite(appliancePin1, LOW); // Turn ON appliance 1
} else if (val == '2') {
digitalWrite(appliancePin1, HIGH); // Turn OFF appliance 1
} else if (val == '3') {
digitalWrite(appliancePin2, LOW); // Turn ON appliance 2
} else if (val == '4') {
digitalWrite(appliancePin2, HIGH); // Turn OFF appliance 2
}
delay(100);
}

Code explanation

Here's a breakdown of what the code does:

  • It declares a variable val of type char to store the received data from serial communication.

  • It defines constant integer values for appliancePin1 and appliancePin2 to specify the PINs used to control the two appliances.

  • In the setup() function:

    • It sets the appliancePin1 and appliancePin2 as output pins.

    • Initializes serial communication with a baud rate of 9600.

    • Sets both appliance pins to a high state, turning both appliances OFF initially.

  • In the loop() function:

    • It checks if there is data available to read from the serial communication.

    • If data is available, it reads the incoming character and stores it in the variable val. It also prints this character to the serial monitor for debugging.

    • It uses the value of val to control the appliances:

      • If val is '1', it turns ON appliance 1 by setting appliancePin1 to a low state.

      • If val is '2', it turns OFF appliance 1 by setting appliancePin1 to a high state.

      • If val is '3', it turns ON appliance 2 by setting appliancePin2 to a low state.

      • If val is '4', it turns OFF appliance 2 by setting appliancePin2 to a high state.

  • The delay(100) introduces a delay of 100 milliseconds between iterations of the loop. This helps to prevent rapid processing and potential flickering of the appliances due to fast changes.

The code essentially listens for characters sent over serial communication and uses those characters to control two appliances connected to specific pins. It turns the corresponding appliance ON or OFF depending on the received character ('1', '2', '3', '4').

Upload the code

  1. Connect your Arduino board to the computer using the USB cable.

  2. Open the Arduino IDE and copy the code into a new sketch.

  3. Select the correct board and port under the "Tools" menu.

  4. Click on the checkmark icon (✓) to verify the error code. Fix any errors that appear.

  5. Click on the right-arrow icon (➔) to upload the code to your Arduino board.

While uploading the code, make sure the TX and RX wires of the Bluetooth module are disconnected from the Arduino.

Application required

To control the appliances, you need to download an application on your mobile phone, using which you will be able to control the devices.

  • Go to the play store on your mobile phone.

  • Type "Arduino Bluetooth Control" in the search bar.

  • Download the application.

Observations

To test the working, upload the code to the Arduino. Connect the TX and RX pins back to the Arduino. Now, your Bluetooth module will turn on. Turn on the Bluetooth on your Android device and search for the HC-05 in the application Bluetooth settings. Connect to this Bluetooth through the application. Once you are connected, set the switch states per your code description.

Set switch 1 high value to 1 and low value 2. Similarly, for switch 2, set the value to 3 and 4 as high and low, respectively. This means that when you turn the switch 1 on, it will send a value of 1 to the Arduino through the Bluetooth module, and this will, in turn, turn the device ON that is connected to pin 9.

And just like you can control all your home appliances with just one click from your phone.

Copyright ©2024 Educative, Inc. All rights reserved