Introduction: Arduino IoT Cloud Smart Home With Alexa Using NodeMCU - IoT Project 2022

About: This Page is for different Electrical and Electronics Projects, DIY, Circuits, etc. All the projects are explained with circuit diagram, Breadboard schematic, working principle, Arduino sketches so it becomes …

In this IoT project, I have shown how to make an IoT-based Smart Home with Arduino IoT Cloud & Alexa using ESP8266 Arduino to control 4 home appliances with voice commands, IR remote, and manual switches. If the internet is unavailable, you can control the home appliances from IR remote & manual switches. In the article, I have shown all the steps to make this smart home system.

This Arduino Home Automation system has the following features:

  1. Control appliances with Arduino IoT Cloud Dashboard.
  2. Control appliances with Alexa.
  3. Used Arduino EEPROM to remember previous states
  4. Control appliances with IR remote.
  5. Control appliances manually with switches or pushbuttons
  6. Monitor real-time feedback and room temperature in the Amazon Alexa app.
  7. Control home appliances manually without internet.
  8. All resources used for this project are FREE.

So if you follow all the steps, you can easily make this IoT project just by using Arduino UNO, NodeMCU, and relay module.

Although the PCB is not mandatory, I have used PCB to make the circuit compact and give the project a professional look.

Supplies

Required Components for this IoT Project (without PCB)

  • Arduino UNO
  • NodeMCU ESP8266
  • 1838 IR receiver (with metal case)
  • DHT11 Sensor
  • 4-channel 5V SPDT Relay Module
  • Switches or Push Buttons
  • 5V DC supply.

Required Components for the Arduino control Relay PCB:

  • Atmega328P microcontroller
  • ESP8266 NodeMCU
  • PC817 Optocuplors (4 no)
  • 510-ohm 0.25-watt Resistor (4 no) (R1 -- R4)
  • 1k 0.25-watt Resistors (6 no) (R5 -- R10)
  • 10k 0.25-watt Resistors (2no)
  • 22pF ceramic capacitor
  • 104 ceramic capacitor
  • 220uF 25V Capacitor (2no)
  • 1uF Box capacitor (1no)
  • 16MHz Crystal
  • LED 5-mm (6 no)
  • 1N4007 Diodes (4 no) (D1 -- D4)
  • Push Buttons (8 no)
  • BC547 Transistors (4 no)
  • Relays 5v (SPDT) (4 no)
  • Terminal Connectors
  • Jumper (5no)
  • Switch (1no)
  • Hi-link ac-dc 220v-5v

Step 1: How This Arduino IoT Project Works?

This Arduino ESP8266 Home Automation works in the following steps.

  1. When you ask Alexa to control appliances, it sends the signal to the Arduino IoT Cloud server.
  2. NodeMCU will receive the signal from the Arduino IoT Cloudthrough the internet.
  3. NodeMCU sends the same signal to Arduino through the serial terminal.
  4. Arduino UNO will process that signal and turn the relays on or off.
  5. Arduino sends the feedback to NodeMCU through Serial communication.
  6. NodeMCU sends feedback to the Arduino IoT Cloud server through the internet.
  7. Real-time feedback can be monitored in the Amazon Alexa app.


Step 2: Circuit Diagram of the ESP8266 Arduino Control Relays

The circuit is very simple, I have used the digital pins D4, D5, D6 & D7 to control the 4 relays.

And the digital pins D10, D11, D12 & D13 are connected with switches to control the 4 relays manually.

The output pin of the IR receiver is connected with A0 and the DHT11 sensor is connected with A1.

I have used the INPUT_PULLUP function in Arduino IDE instead of using the pull-up resistors.

I have used D2 as RX and D3 as TX for the serial communication with the NodeMCU module.

If you use the latched switches then just connect the pushbutton across the digital pins and GND instead of the pushbuttons.

I have used a 5V mobile charger to supply the smart relay module.

Please take proper safety precautions while working with high voltage.

Step 3: Alexa Control Relay Using ESP8266 NodeMCU

You can control the home appliances from Amazon Alexa App if the NodeMCU is connected to 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.

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.

Step 4: Control Relays With IR Remote & Manual Switches

You can always control the relays with IR remote and manual switches.

I will explain how to get the IR codes (HEX codes) from any remote in the following steps.

And if the NodeMCU is connected to Wi-Fi, you can monitor the real-time feedback in the Amazon Alexa App & Arduino cloud dashboard.

If the WiFi is unavailable, you can still control the relays with IR remote and manual switches.

When the WiFi is available, the NodeMCU will automatically reconnect with the WiFi.

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:

GitHub link to Download PCB Gerber File

Step 6: Why You Should Use JLC SMT Service?

On JLCPCB's one-stop online platform, customers enjoy low-cost & high-quality & fast SMT service at an $8.00 setup fee($0.0017 per joint).

$27 New User coupon & $24 SMT coupons every month.

Visit https://jlcpcb.com

JLCPCB SMT Parts Library 200k+ in-stock components (689 Basic components and 200k+ Extended components)

Parts Pre-Order service https://support.jlcpcb.com/article/164-what-is-jlcpcb-parts-pre-order-service

Build a Personal library Inventory, save parts for now or the future

Assembly will support 10M+ parts from Digikey, mouser.

Step 7: Steps to Order the PCB Assembly From JLCPCB

  1. Visit https://jlcpcb.com/ and Sign in / Sign up.
  2. Click on the QUOTE NOW button.
  3. Click on the "Add your Gerber file" button. Then browse and select the Gerber file you have downloaded.
  4. Set the required parameter like QuantityPCB masking color, etc.
  5. Select the Assemble side and SMT Quantity.
  6. Now upload the BOM and PickAndPlace files.
  7. Now confirm all the components which you want to be soldered by SMT services.
  8. Click on SAVE TO CART button.


Step 8: Select Shipping Address and Payment Mode

  1. Type the Shipping Address.
  2. Select the Shipping Method suitable for you.
  3. Submit the order and proceed with the payment.

You can also track your order from the JLCPCB. My PCBs took 3 days to get manufactured and arrived within a week using the DHL delivery option.

PCBs were well packed and the quality was really good at this affordable price.

Step 9: 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.

https://store.arduino.cc/digital/create

  1. Click on "GET STARTED FOR FREE", then click on "create one".
  2. Enter your birthday, then click on "Next".
  3. Enter the email ID, user name, and set a password. Then click on "Sign Up".
  4. Now click on "IoT Cloud".


Step 10: Add ESP8266 Device in the Arduino IoT Cloud

First, click on the "Create Thing" button, then follow these steps.

  1. Click on the Select Device on the right.
  2. Select "Set up a third Party device", then select device type as ESP8266 and device model as NodeMCU 1.0.
  3. You will get a Device ID and Secret Key which will be required in the code.
  4. Click on "Continue", You will find the device added.


Step 11: Add Varriable in Arduino IoT Cloud

Now to control 4 relays, and get the reading from the DHT11 sensor, you have to add 5 variables.

Click on the "ADD VARIABLE" button.

Enter the 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.

For the room temperature reading, select Alexa compatible Temperature Sensor. Variable Update Policy will be "Periodically", and mention the interval time.

Step 12: 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 onthe 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 widgets to control 4 relays.

For the temperature, select Gauge widgets and link the Temperature variable. You can also set the MIN and MAX limits.

Step 13: Get the IR Codes (HEX Code) From Remote

Now, to get the HEX codes from the remote, first, we have to connect the IR receiver output pin with the A0 pin of Arduino UNO.

And give the 5V across the VCC and GND. The IR receiver must have a metallic casing, otherwise, you may face issues.

Then follow the following steps to get the HEX codes:

  1. Install the IRremote library(3.6.1) in Arduino IDE.
  2. Download the attached code, and upload it to Arduino UNO.
  3. Open Serial Monitor with Baud rate 9600.
  4. Now, press the IR remote button.
  5. The respective HEX code will populate in the serial monitor.
  6. Save all the HEX codes in a text file. You have to update these HEX codes in the main sketch.


Step 14: Program the ESP8266 NodeMCU With Arduino IDE

To program the NodeMCU, I have used Arduino IDE.

Download the attached code.

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, enter the following details.

  • const char DEVICE_LOGIN_NAME[] = ""; //Enter DEVICE ID
  • const char SSID[]        = "";  //Enter WiFi SSID (name)
  • const char PASS[]        = "";  //Enter WiFi password
  • const char DEVICE_KEY[]     = "";  //Enter Secret device password (Secret Key)

the DEVICE_LOGIN_NAME[] and DEVICE_KEY[] from the PDF which you have downloaded during adding the device to the 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 15: Program the Arduino UNO or ATmega328P With Arduino IDE

In the PCB I have used an ATmega328P microcontroller, so I have used FTDI232 USB to TTL board to program the microcontroller (Refer to tutorial video).

But if you don't use PCB then you can directly connect the Arduino UNO with the laptop.

For the main sketch, you need to install the following libraries

Then you have to update the HEX code in the sketch for IR remote control.

For momentary switch use the code: Code_ArduinoUNO_EEPROM_WiFi_IR_Button_4Relay.ino

and for latched switch use the code: Code_ArduinoUNO_EEPROM_WiFi_IR_Switch_4Relay.ino

Step 16: Configure the Alexa App for Arduino IoT Cloud

Download and install the Amazon Alexa App from the Google play store or App Store.

  1. Tap on "More".
  2. Then select "Skills & Games".
  3. Search for Arduino and tap on "Arduino".
  4. Tap on "ENABLE TO USE".


Step 17: Connecting Arduino Cloud Devices With Alexa

  1. Log in with the Arduino Cloud credentials.
  2. Tap on CLOSE.
  3. Tap on "DISCOVER DEVICES". It will take a minute to add devices. During this time the NodeMCU should be connected with the WiFi.
  4. Tap on "Devices", and tap on "Switches" to see all the devices.

Thus, all the devices from Arduino IoT Cloud will be added to Amazon Alexa App.

Step 18: Connect the Home Appliances

Connect the 4 home appliances with the relay module as per the circuit diagram.

Please take proper safety precautions while working with high voltage.

Connect the 110V/230V supply with the PCB.

Step 19: Finally!! the Arduino Cloud Smart Home System Is Ready

Now you can control your home appliances in a smart way.

I hope you have liked this Arduino IoT and Alexa control home automation project. I have shared all the required information for this project.

I will really appreciate it if you share your valuable feedback. Also if you have any queries please write in the comment section.

Thank you & Happy Learning.

Remote Control Contest

Participated in the
Remote Control Contest