In this article, we are introducing how to implement simple home automation by using an Arduino Uno microcontroller. By using this method, you can turn ON/OFF your devices in your home remotely by using your smartphone
Components required to perform home automation
Hardware
- Arduino Uno
- Lamp
- HC 05 Wireless Bluetooth Module
- Relay Module
- 2.2 K- Ohm resistor
- 1K Ohm resistor
- Breadboard
- Jumper Wires
Software
- Arduino IDE
- DIY smart home Android App
Circuit Diagram
How to Connect the Arduino to the Bluetooth HC-05
Step 1: As indicated in the circuit diagram, connect the Arduino’s +5V and GND pins to the bus strips on the breadboard.
Step 2: Connect the 5V and GND pins to the bus strips on the breadboard to power the HC-05 module. The HC-05 is supplied by 5VDC but has an onboard voltage regulator that provides a 3.3V supply to the transmitter. This means that the TXD and RXD pins are just 3.3V.
Step 3: Connect the RXD pin (Pin 0) on the Arduino to the TXD pin on the HC-05 module. The HC-05 may communicate data to the Arduino via this connection. The reason we use RXD on the Arduino and TXD on the Bluetooth module is easy. The RXD pin is used to receive data from the Arduino, while the TXD pin is used to transfer data from the Bluetooth transmitter.
Step 4: The TXD pin on the Arduino must now be connected to the RXD pin on the HC-05. The Arduino delivers data to the HC-05 over this connection, which is the second half of the two-way communication.
Because the HC-05’s receiver data lines are only 3.3V tolerant, we must convert the Arduino’s 5V transmit signal to a 3.3V signal. While a logic level converter is generally used for this, we’re merely using a basic voltage divider to convert the 5V signal to a 3.3V signal.
The STATE and EN pins on the HC-05 module are not used because they are not needed for this design.
The Arduino will then be linked to a relay module, allowing us to turn the connected device on and off. We’ll link the relay module in series with our electrical load, as indicated in the circuit diagram above so that we can break the connection to turn the device off and complete the circuit to turn it on.
We’re using a relay module with a relay driving circuit that allows it to connect directly to a microcontroller GPIO pin for this application.
Note: We’re utilizing a relay module that can take up to 10 amps of current at 240V AC. This is sufficient current for many gadgets, but not for high-power appliances such as a heater or dryer. You’ll probably need twice the current capacity (about 20 amps) for high-power appliances. You have the option of upgrading to a higher current relay or connecting numerous relays in parallel. Because half of the current passes via each relay, two 10-amp relays in parallel are equivalent to a single 20-amp relay.
To connect the relay module to the Arduino, follow these steps:
-
First, connect the relay module’s 5V and GND pins to the breadboard’s bus terminals.
-
Next, connect the relay module’s IN1 pin to the Arduino’s PIN 4. If you have a multi-channel module (2, 4, or 8 channels), you can connect IN2, IN3,… In(n) to separate digital pins on the Arduino and configure the other pins as shown below.
-
The AC load must now be connected to the relay module. These three terminals can be found on the terminal block of the relay module if you look closely:
C: Common
Normally Closed (NC)
Normally Open: NO
Code: The next step is to upload the code to the Arduino when you’ve successfully hooked everything up. Connect the Arduino to your computer via USB port and launch the Arduino IDE to upload the code. Then, in a separate window, copy the following sketch and try to execute it on your Arduino.
#define RELAY_ON 0
#define RELAY_OFF 1
#define RELAY_1 4
char data = 0;
void setup() {
// Set pin as output.
pinMode(RELAY_1, OUTPUT);
// Initialize relay one as off so that on reset it would be off by default digitalWrite(RELAY_1, RELAY_OFF);
Serial.begin(9600);
Serial.print(“Type: 1 to turn on bulb. 0 to turn it off!”);
}
void loop() {
if (Serial.available() > 0) {
data = Serial.read(); //Read the incoming data and store it into variable data
Serial.print(data); //Print Value inside data in Serial monitor
Serial.print(“\n”); //New line
if(data == ‘1’){
digitalWrite(RELAY_1, RELAY_ON);
Serial.println(“Bulb is now turned ON.”);
}
else if(data == ‘0’){
digitalWrite(RELAY_1, RELAY_OFF);
Serial.println(“Bulb is now turned OFF.”);
}
}
}