Creating a Home Automation Project Using Xiao board and Wi-Fi
Creating a Home Automation Project Using Xiao board and Wi-Fi
You must've read one of my previous blogs where I used a Xiao ESP32C3 board to control an LED using Arduino IoT Cloud's dashboards using the integrated wi-fi of the board.
This blog is about the next step. In this blog, we'll learn how to actually integrate it in our home. We'll be using the Arduino IoT Cloud's dashboard.
What you'll need:
- A XIAO ESP32C3 board and its cable
- A single-channel relay
- The circuit from inside an AC-DC 5V adapter
- A light bulb holder
- 7-8 electrical wires
- A zero PCB
- 2 screw connectors
- Some wires
- A 10x10x5 cm box with screw connecting pillars
- Screw driver
- Computer/PC/Laptop
- Soldering gun and its accessories
1) First, take your XIAO ESP32C3 board and its cable and connect it to your computer. Open Arduino IoT Cloud on your browser. We're first going to set up our XIAO ESP32C3 board.
2) Do all the necessary steps to sign in to Arduino Cloud. After that, you'll see the default homescreen and other things like things, dashboards, devices, etc.
3) Then, go to things and click on Create things. Then, add a Thing by clicking on Add.
4) Name it as Home Automation LED and select its variable type as Boolean, and then click Add Variable.
5) After that, click on Associate Device and then select Third Party Device.
6) Then, select the device type as ESP32 and its model as Xiao_ESP32C3. After that, you'll see your device's ID and its secret key. Download the PDF; it is necessary. Then, tick the box below.
7) After that, select Configure Network and type your Wi-Fi name, Wi-Fi password and the device's secret key from the downloaded PDF.
8) Now, you'll have to download Arduino Cloud Agent. Click this link to visit the site- https://cloud.arduino.cc/download-agent/To download it, click on Download, then do all the necessary steps to install and then after that, you'll see a tab showing 'Your Agent is ready. You can now close this tab.'
9) After that, upload the code given below
#include "thingProperties.h"
#define LED_PIN D6
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(115200);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of the network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
}
/*
Since Led is READ_WRITE variable, onLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onHomeAutomationLedChange() {
Serial.print("LED received: ");
Serial.println(home_automation_led);
if (home_automation_led) {
digitalWrite(LED_PIN, HIGH);
} else {
digitalWrite(LED_PIN, LOW);
}
}
10) Creating a Dashboard to control the light
To control the light, we need a Dashboard. So, click on Dashboards and create a dashboard. Then, click the Edit button and select the widget of a switch in the Add option and then select the device according to your preference, but most probably, choose the mobile phone. For controlling the light through your phone, you'll need the Arduino Cloud app on your phone, so install it.
11) After that, go back to the dashboard window, then click on Switch widget and then click on Add Variable to add the previously created variable and select your variable to link it. Then, click Done.
12) Now, we'll make the circuit. Make the circuit according to the diagram given below.
After that, take a plastic electric box with a built-in bulb holder to keep all the components. Then, fix the whole box on the wall and the two-pin connector in one of the sockets for the power supply.
13) After this, test it and then your Home Automation Project is Ready!!!
Here is my working project:












Comments
Post a Comment