Finally, I worked on my childhood dream of having my own JARVIS to bring it true!!! This is my contribution to the upcoming lifestyle trend of IoT enabled smart homes. The title Home Automation using IoT – Arduino project with code sounds cool, right?
Do watch the entire video with sound on, it’s interesting.💡
In this article, I will be giving a summary of how I made this project using IoT and Arduino. You can find this IoT project in my GitHub repository as well.
I will also mention the essential steps to accomplish the project.
This is one of the Arduino projects in my LinkedIn profile which gained popularity with 3.8k+ views, 400+ likes, 70+ Comments
1. About home automation using IoT-Arduino project with code –
With this project, I was able to control the functioning of the Lights, Fan, Curtains, Music, and Ambience from the app which I developed (Code and steps of developing it will also be shared in this article).
To be honest, the coding part on the micro-controller and the app was bit tricky. But, finally after many attempts it worked.
Secondly, I have even added voice recognition. And to make it easier, rather than saying the entire word you can just say the corresponding letter to complete the action.
(For example, h=Music off, d=dim lights off, etc)
Just by replacing the HC-05 with ESP8266 (wifi-module) I can control this from anywhere in the world using internet.
Isn’t this the best and easy iot project for beginner?
Let’s get into more detail now.
2. Following is the list of Components that are needed for this –
[PS: You can click on the links and buy them from Amazon.]
- HC-05 [Bluetooth module, a bridge to connect our phone to Arduino]
- Servo Motors [To control lights and fans]
- Relays [for ac supply appliances i.e the dim lights and bulbs]
- BO motor [100 rpm] and l298n [For controlling the curtains]
- Jumper wires
- Resistors [for forming]
- Battery [9 Volts]
- laptop [To develop an Android application]
Step 1 –
Firstly, I created an android app. Using Android Studio to develop would have cost lots of time. So, I developed it from MIT App inventor.
It is an online cloud-based tool that lets you develop an android app using a web browser.
You can either connect a phone or use an emulator for it. Also, it uses a block-based programming language that is built on Google Blockly.
The language used for Coding is basic “C” itself. And it uses blocks of code where we need to attach them one after the other depending on our need.
Arduino based mini-projects are mostly developed using this platform.
Every button when pressed sends data to the Arduino. Like on the app, when button 1 is pressed it sends data a, b, c, etc
I have even added google voice recognition then helps in voice commands and in the start Bluetooth client, which helps me to connect the hc-05 (Bluetooth module) phone to Arduino.
Walkthrough of Home Automation using IoT – Arduino project Code
A. Importing C header files, libraries, and creating necessary instances.
Servo library allows an Arduino board to control Servo Motors. Click on Arduino’s software help menu and then click on reference. Find and follow the Libraries link. S1 and S2 are two servo variables.
- a and b are the pins where the signal wire or servo motors are connected.
- r1 and r2 are the pins where the relay module is attached.
- m1 and m2 are the pins where the l298n(motor driver) In1 and In2 pins are connected with a jumper on ENA pin
B. Defining a Setup function which returns nothing.
(Setup function run only once and in the setup function the configuration of the pins are defined if they are INPUT or OUTPUT)
- s1 and s2 are attached to pin a and b respectively
- Serial.begin is used to run the serial monitor.
- r1,r2,m1,m1 are all set to OUTPUT are they would complete some action.
C. Defining a loop void function (void loop is the function which is gonna run the code repeatedly)
Here, I have used if-else loop (even “switch” statement would work).
The data (a,b,c…)is sent from the app to the Arduino and then Arduino sends data to servo/l298n/relay respectively.
With this, the coding for Arduino project of our app is done.
Step 2 –
Next Step is to turn on your phones bluetooth. Then open the MIT app inventor which you have downloaded on your phone.
Scan the code from the MIT app inventor web page. Now connect the hc-05 (Bluetooth module) to the Arduino and it will now show connected.
The hc-05 is basically a bridge to connect our phone to Arduino. BO motor and l298n are used for controlling the curtains while the relay module is used for the dim lights.
Instead of using the traditional way of using a relay for fan and lights, after opening the circuit board, I have used servo motor and attached eternal and it presses the switches.
If you zoom in properly you would see 2 bo-motors as my curtains were bit heavy so they needed 2 motors.
Now you can control everything by pressing the button or by just using the voice command. Here we complete this project.
You can buy this book called “Getting started with Internet of Things” by Cuno Pfister. This book is great if you are looking to start building your own IoT models. It requires basic programming skills and affordable electronic devices. The author teaches in a very simple and efficient way from start to end including everything.
Hence, I ended up getting this amazing Arduino project with coding done. You can also add many other devices in this network.
Before implementing this project, I would suggest you go through the Ultimate Guide to IoT once.
This might trigger a new idea and maybe you develop home automation using IoT ideas. Being an IoT developer is pretty amazing.
It also gives a feeling of satisfaction for developing something great. Make sure to share your project with me too. I would love to watch it.
Give your opinions about this Home Automation using IoT- Arduino project with code in the comment section. Also If you have queries regarding this project, you can write it down in the comment section below.
Feel free to contact us!
What Author Says,
I am a 3rd-year Electronics having a tremendous interest in IoT and embedded systems. Learning new things and implementing ideas is what I love to do. Apart from this, I’m an athlete and as a hobby, I love playing Guitar. Check out my profiles Instagram, LinkedIn for the ideas which I have implemented out of curiosity during this lockdown with limited resources. In case of any discussion with me about the projects, you can drop a mail here or dm me on LinkedIn.
Keep innovating, Stay Connected, Seek Discomfort. Thank You 🙂