Overview:
Home automation has elevated convenience to new heights, from controlling the lights in your bedroom to automatically turning your home appliances on and off to a schedule. Instead of using mechanical switches, you can now operate all of your home's electronics with just your smartphone.
This blog demonstrates how to set up a simple automated lightbulb using DFRobot Beetle, a very small-form-factor Arduino board that's the size of your thumb!
Hardware Used:
Software Used:
Application Description:
- DFRobot Beetle
- HC - 05 (Bluetooth Module)
- Relay
A relay module is an electrical switch that is operated by an electromagnet. The electromagnet is activated by a separate low-power signal from a micro controller, in this case the Beetle. When activated, the electromagnet pulls to either open or close an electrical circuit.
The relay module used in the project is a single channel relay (those blue cubes). There are other models with two, four and eight channels.
Hardware Setup:
Pin Configuration
HC-05 Connections
- TXD pin in HC-05 to RX contact point in DFRobot Beetle.
- RXD pin in HC-05 to TX contact point in DFRobot Beetle.
- We will not be using the STATE and EN pins on the HC-05 module, since they are not required for this setup.
- S pin on relay module to D9 hole in DFRobot Beetle
-
Now we need to connect the power supply to the relay module. If you look carefully at the terminal block on the relay module, you’ll find these three terminals:
C: Common
NC: Normally Closed
NO: Normally Open
-
We want to turn the bulb on only when we send a signal from the smartphone. That’s the reason we connect the load to the NO (Normally Open) terminal, so by default the light bulb is OFF.
When the relay is triggered from the Beetle, the relay contact switches from the NO terminal to the NC terminal, thereby completing the circuit, and turning ON the light bulb.
Software setup:
Code:
const int relay = 9;
void setup() {
Serial1.begin(9600);
pinMode(relay, OUTPUT);
}
void loop() {
char state = Serial1.read();
if (state == '1'){
Serial.println("Lights ON");
digitalWrite(relay, HIGH);
} else if (state == '0'){
Serial.println("Lights OFF");
digitalWrite(relay, LOW);
}
delay(100);
}
Code Breakdown:
- At the start, we initalize the variables needed for this project. Since the S pin of the relay module is connected to the D9 hole in the Beetle, we assign the value 9 to the variable named relay.
- In the setup() method, we set the baud rate to 9600 and declare the D9 pinmode in the OUTPUT mode.
- In the loop() method, Serial1 is read and if ‘1’ is received as input, it turns ON the relay, and if ‘0’ is received, it turns OFF the relay.
Arduino Controller App:
- To send input signals to the HC-05 Bluetooth module, we will be using the Arduino Bluetooth Controller App.
- Once installed, pair the HC-05 to your smartphone via the app. The first time you pair the HC-05, you are required to enter the password. By default, the password is either 1234 or 0000.
- Once paired, A menu will pop up with the different modes we can use to connect to the HC-05. For this project, we will be connecting in Switch mode.
- Make sure that in the Setting menu, the ON and OFF commands are set to 1 and 0 respectively.
- Here is a link to a video demo on how to setup the Arduino Bluetooth Controller App
Output:
Below is a video demonstration of the working project.
Conclusion:
This project demostrates a simple DIY automated lightbulb that can be controlled using a cellphone via bluetooth. Since the Arduino bluetooth contoller app can be configued to send different types of inputs rather just ON and OFF state, these inputs can be used to futher improve the complexity of your DIY project.
References:
https://howtomechatronics.com/tutorials/arduino/arduino-and-hc-05-bluetooth-module-tutorial/
https://www.seeedstudio.com/blog/2020/01/03/arduino-tutorial-control-high-voltage-devices-with-relay-modules/