Creating a Home Automation Project Using a Xiao Board and an LED

 Creating a Home Automation Project Using a Xiao Board and an LED


You must've seen people using an app to control the lights in their homes to save the effort of getting up and switching the button on and off. Many companies are creating their own home automation devices and apps. But at the same time, they're costly. 

You can create your own home automation device using a Xiao ESP32C3 board and an LED.

For this you need:

  • A Xiao esp32C3 board 
  • A Computer
  • A 10mm LED

There are instructions given below stepwise.

Step 1: Setting your device up.

Open Google and search 'Arduino Cloud' or visit this link๐Ÿ‘‰ https://cloud.arduino.cc/

This is the default homepage of the website. Click on 'Get Started for Free'.
















Sign in with Google ๐Ÿ‘‡














This is the actual homepage where you'll see many options such as Devices, Things, Dashboards, etc.











Click on 'Things' and create a thing by clicking on 'Create Thing'. 


 
Add a thing by clicking on 'Add'  

Name it 'led' and select its variable type as 'Boolean' and then click 'Add Variable'.
















After that, click on 'Associate device' and select 'Third Party Device'.











Select the device type as 'ESP32' and its model type as 'Xiao_ESP32C3'.











After that, you'll see your device's ID and its Secret Key. Click on 'Download PDF' and then tick the box below.
















Then, select 'Configure Network' and type in your Wi-Fi name, Wi-Fi password and your device's Secret key from the PDF you've downloaded.












After that, comes the next step.
Step 2: Downloading Arduino Cloud Agent
To connect the board you'll have to download the Arduino Cloud Agent by typing it into Google or visiting this link- https://cloud.arduino.cc/download-agent/

To download it click on 'Download' then open the downloaded file. Do all the necessary things to install it and then after that, you'll see a tab showing 'Your Agent is ready. You can now close this tab.' 

Step 3: Uploading the code
After closing the tab go to the Things tab and click on 'Sketch' where you'll write and upload the code. I've provided the code below. Copy it and then CTRL-A all the pre-existing code and paste the copied code.

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/029ce034-e6f8-40f9-8ba4-993b23494a0d 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  bool led;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#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 onLedChange()  {
  Serial.print("LED received: ");
  Serial.println(led);
  if (led) {
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(LED_PIN, LOW);
  }
  // Add your code here to act upon LED change
}

Upload the code to your board.

Step 4: Creating a Dashboard to control the LED.
To control the LED we need a Dashboard. So, click on 'Dashboard' 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 choice. But, if you choose the mobile option, you'll have to download the Arduino Cloud app on your phone too. 
Download the app on your phone and then sign in.
Go back to our Dashboard making window and then click on the Switch widget and then click on 'Add Variable' to add your previously created variable and then select your variable to link your variable.























After clicking 'Done' you'll see this window:















Close all of the tabs and open your dashboard again and your Home Automation Project is READY!





Comments