In this IoT project, I have shown how to make an IoT-based Smart Home with Arduino IoT Cloud & Alexa using NodeMCU ESP8266 to control 4 home appliances with voice commands. If the internet is not available, then you can control the home appliances manually with switches. During the article, I have shown all the steps to make this smart home system.
This IoT-based Home Automation system has the following features:
- Control appliances with Alexa and Arduino IoT Cloud Dashboard
- Control appliances manually with switches.
- Control home appliances manually without internet.
- All resources used for this project are FREE.
So, you can easily make this home automation project at home just by using a NodeMCU and relay module. Or you can also use a custom-designed PCB for this project.
You can make this project just by using NodeMCU and 4-channel relay module. But if you use PCB then you need the following components.
- Relays 5v (SPDT) (4 no)
- BC547 Transistors (4 no)
- PC817 Optocuplors (4 no)
- 510-ohm 0.25-watt Resistor (4 no) (R1 – R4)
- 1k 0.25-watt Resistors (5 no) (R5 – R9)
- LED 5-mm (5 no)
- 1N4007 Diodes (5 no) (D1 – D5)
- Push Buttons (4 no)
- Terminal Connectors
- 5V DC supply
Step 1: Circuit Diagram of the NodeMCU Home Automation Project
This is the complete circuit diagram for this home automation project. I have explained the circuit in the tutorial video.
The circuit is very simple, I have used the GPIO pins D1, D2, D5 & D6 to control the 4 relays.
And the GPIO pins SD3, D3, D7 & RX connected with push buttons to control the 4 relays manually.
I have used the INPUT_PULLUP function in Arduino IDE instead of using the pull-up resistors.
I have used a 5V mobile charger to supply the smart relay module.
Here, the D3 pin should not be connected with GND during the booting process of NodeMCU.
Step 2: Alexa Control Relay Using NodeMCU
You can control the home appliances from Amazon Alexa App if the NodeMCU is connected with the WiFi.
You can also ask Alexa to turn on and off the appliances from anywhere in the world.
You don’t need any Echo DOT or other Alexa devices for this home automation project.
Step 3: NodeMCU Control Relays With Arduino IoT Cloud Dashboard
You can also control the home appliances from the Arduino IoT Cloud web dashboard and Arduino IoT Cloud Remote mobile app if the NodeMCU is connected with WiFi.
In this project, I have used the FREE plan of Arduino IoT Cloud. In the FREE plan, you can control maximum 5 relays.
When you control the relays from Arduino IoT Cloud Remote mobile app the current state of the relay also updated in the Amazon Alexa App.
Step 4: Control Relays Manually From Push Buttons
If the WiFi is not available, you can control the relays from the pushbuttons.
When the WiFi is available, the NodeMCU will automatically reconnect with the WiFi.
Please refer to the circuit diagram to connect the pushbuttons.
Step 5: Design the PCB for This Smart Home System
To make the circuit compact and give a professional look, I have designed the PCB after testing all the features of the smart relay module.
You can download the PCB Gerber file of this home automation project from the following link: https://drive.google.com/uc?export=download&id=1Jx4D_DSV_ei1y0a82AbtxbsNhy8sjCmY
Step 6: Solder All the Components on PCB
After that, I have soldered all the components as per the circuit diagram.
Then connect the NodeMCU board with the PCB.
Step 7: Create Arduino IoT Cloud FREE Account
For this smart house project, I have used the Arduino Cloud Free plan.
Click on the following link to create an Arduino IoT Cloud account.
- Click on “GET STARTED FOR FREE“, then click on “create one“.
- Enter your birthday, then click on “Next“.
- Enter the email ID, user name, set password. Then click on “Sign Up“
- Now click on “IoT Cloud“.
Step 8: Add NodeMCU ESP8266 Device in the Arduino IoT Cloud
Click on the Select Device on the right.
- Select “Set up a third Party device”, then select device type as ESP8266 and device model as NodeMCU 1.0.
- You will get a Device ID and Secret Key which will be required in the code.
- Click on “Continue“, You will find the device added.
Step 9: Add Varriable in Arduino IoT Cloud
Now to control 4 relays, you have to add 4 variables.
Click on the “ADD VARIABLE” button.
Enter name, then select Alexa compatible switch type. Variable Permission will be “Read & Write” and Variable Update Policy will be “On Change“.
In a similar way, you have to add the next 3 variables.
Step 10: Set Up Arduino IoT Cloud Dashboard
Now click on Dashboard on the top to set up the Arduino cloud dashboard.
Then click on Build Dashboard.
After that click on EDIT icon. Then click on ADD and select Switch.
Give a name to this Switch, then link a variable with this switch widget.
Then click on Done.
In a similar way, you have to add total 4 Switch widget to control 4 relays.
Step 11: Program the NodeMCU ESP8266
To program the NodeMCU, I have used Arduino IDE.
Download the attached code.
In the folder you will get 3 files (1 .ino file & 2 .h files). Keep all the files in the same folder. Now open the .ino file with Arduino IDE.
First, you have to install the ArduinoIoTCloud library. During installation, it may ask to install other dependencies. Then click on Install All.
In the code, you have to update the THING ID and DEVICE ID in the thingProperties.h file.
Then update the Wi-Fi credentials and Secret Key in the arduino_secrets.h file.
You will get the DEVICE ID and THING ID in the Arduino IoT cloud account. And Secret Key from the PDF which you have downloaded during adding the device in Arduino IoT cloud.
I have shown all the steps in the tutorial video.
After doing all these changes, you can upload the code to NodeMCU.
Step 12: Configure the Alexa App for Arduino IoT Cloud
Download and install the Amazon Alexa App from the Google play store or App Store.
- Tap on “More“.
- Then select “Skills & Games“.
- Search for Arduino and tap on “Arduino“.
- Tap on “ENABLE TO USE“.