Industrial FABLAB UCuenca

Week 11 – Networking and communications

BLYNK – ESP32 XIAO C3

Week 20 – Output Devices

Controlling a 5V DC Motor using HC-SR04 with XIAO ESP32-C3

Week 11

Networking and Communications


Development of a wireless communication system using a Xiao ESP32-C3 and Blynk platform to remotely control a light bulb (LED) through WiFi.

Assignment Overview

Objective

The purpose of this assignment is to explore networking and wireless communication between devices. In this project, a Xiao ESP32-C3 is connected to WiFi and controlled remotely using the Blynk IoT platform.

Project Description

A simple lighting control system was developed where a LED represents a household light bulb. Through the Blynk mobile application, the user can turn the light ON and OFF remotely using wireless communication.

Tools and Components

  • Xiao ESP32-C3
  • LED
  • 220Ω resistor
  • Breadboard
  • USB-C cable
  • Blynk IoT Platform
  • Arduino IDE

Software Analysis

Arduino IDE

Arduino IDE was used to program the Xiao ESP32-C3. The environment allows uploading the firmware, configuring the ESP32 board and managing WiFi communication libraries.

Blynk Platform

Blynk is an IoT platform that enables communication between mobile devices and microcontrollers through the internet. It provides a dashboard interface with widgets such as buttons, sliders and indicators.

WiFi Communication

The ESP32-C3 integrates WiFi communication capabilities. Using internet connectivity, the board receives commands from the Blynk application and controls the LED remotely.

Electronic Connections

LED Connection

  • LED positive pin → GPIO pin D2
  • LED negative pin → 220Ω resistor
  • Resistor → GND

The LED acts as a simulated light bulb that can be controlled remotely.

Power Supply

The Xiao ESP32-C3 is powered directly through the USB-C cable connected to the computer. This also allows programming and serial monitoring.

Step-by-Step Development

1

Create Blynk Account

Create an account on the Blynk IoT platform and start a new template project for ESP32 devices.

2

Create Device Template

Configure a new device template selecting ESP32 as hardware and WiFi as connection type.

3

Add Button Widget

In the Blynk mobile dashboard, add a button widget and configure it to use Virtual Pin V0.

4

Install Libraries

Install the following libraries in Arduino IDE:

  • Blynk Library
  • ESP32 Board Package
5

Configure WiFi Credentials

Add the WiFi name, password and Blynk authentication token inside the Arduino code.

6

Upload the Program

Connect the Xiao ESP32-C3 through USB-C and upload the code to the board.

7

Test Communication

Press the button in the Blynk application and verify that the LED turns ON and OFF wirelessly.

Arduino Code

The following code establishes communication between the Xiao ESP32-C3 and the Blynk platform.

#define BLYNK_TEMPLATE_ID "YOUR_TEMPLATE_ID"
#define BLYNK_TEMPLATE_NAME "ESP32 Light Control"
#define BLYNK_AUTH_TOKEN "YOUR_AUTH_TOKEN"

#include <WiFi.h>
#include <BlynkSimpleEsp32.h>

char ssid[] = "YOUR_WIFI_NAME";
char pass[] = "YOUR_WIFI_PASSWORD";

int ledPin = 2;

BLYNK_WRITE(V0)
{
int buttonState = param.asInt();

digitalWrite(ledPin, buttonState);
}

void setup()
{
pinMode(ledPin, OUTPUT);

Serial.begin(115200);

Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}

void loop()
{
Blynk.run();
}

Code Explanation

1. Initial Description

This section explains the purpose of the program. The Xiao ESP32-C6 connects with the Blynk platform to control a physical LED remotely.

  /********************
  XIAO ESP32-C6 + Blynk
  Control de LED físico desde botón virtual (V1)
  + Mensaje dinámico en Blynk (V2)
  ********************/
  

Communication flow:

  • Smartphone → Blynk Cloud → ESP32
  • ESP32 → LED Control
  • ESP32 → Dynamic Message in App

2. Blynk Configuration

These parameters connect the ESP32 board with the Blynk cloud server. Each project has a unique authentication token.

  #define BLYNK_TEMPLATE_ID "TMPL2VCa6f9pP"
  #define BLYNK_TEMPLATE_NAME "Industral FabAPP"
  #define BLYNK_AUTH_TOKEN "RhfphMdznryF3yoH_0ufmsMbR-QR9HhJ"
  
  • TEMPLATE_ID: Unique project ID
  • TEMPLATE_NAME: Project name inside Blynk
  • AUTH_TOKEN: Authentication key for the device

3. Libraries

Libraries allow communication between the ESP32 and WiFi/Blynk services.

  #include <WiFi.h>
  #include <BlynkSimpleEsp32.h>
  
  • WiFi.h → Enables WiFi connectivity
  • BlynkSimpleEsp32.h → Enables Blynk communication

4. Hardware Configuration

Defines the pin where the LED is connected.

  #define LED_PIN D10
  

The LED connected to pin D10 behaves as a simulated light bulb.

5. WiFi Credentials

Stores the WiFi network name and password used by the ESP32 to connect to the internet.

  char ssid[] = "iPhone de Rod";
  char pass[] = "0105rodri";
  
  • ssid → WiFi network name
  • pass → WiFi password

6. BLYNK_WRITE Function

This function is executed automatically every time the virtual button V1 changes state inside the Blynk app.

  BLYNK_WRITE(V1)
  {
    int value = param.asInt();
  
    digitalWrite(LED_PIN, value);
  
    if (value == 1) {
      Blynk.virtualWrite(V2, "Hola ZOI");
    } else {
      Blynk.virtualWrite(V2, " ");
    }
  }
  
  • Reads the button state from V1
  • Turns the LED ON or OFF
  • Sends a dynamic message to widget V2

7. Setup Function

The setup function runs only once when the ESP32 starts.

  void setup()
  {
    Serial.begin(115200);
    delay(1000);
  
    Serial.println("Iniciando sistema...");
  
    pinMode(LED_PIN, OUTPUT);
  
    Serial.println("Conectando a WiFi y Blynk...");
    Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
  
    Serial.println("Sistema listo.");
  }
  
  • Starts serial communication
  • Configures LED pin as OUTPUT
  • Connects ESP32 to WiFi
  • Connects ESP32 to Blynk Cloud

8. Loop Function

The loop function runs continuously while the ESP32 is powered.

  void loop()
  {
    Blynk.run();
  }
  

Blynk.run() keeps the communication active between the ESP32 and the Blynk cloud server in real time.

9. Final Result

The final system successfully demonstrates wireless networking and communication using IoT technology.

  • Remote LED control from smartphone
  • Real-time WiFi communication
  • Cloud interaction with Blynk
  • Dynamic messages displayed in app

Results

Wireless Control

The ESP32-C3 successfully connected to the WiFi network and received commands from the Blynk application in real time.

Remote Communication

The LED could be controlled remotely from a smartphone, demonstrating successful networking and communication between hardware and cloud platform.

Learning Outcomes

  • Understanding IoT communication
  • Using WiFi with ESP32
  • Integrating Blynk dashboards
  • Remote device control

Conclusion

This assignment demonstrated how networking and communication technologies can be integrated into embedded systems. By using the Xiao ESP32-C3 and Blynk platform, it was possible to remotely control a light through WiFi, introducing the fundamentals of IoT systems and cloud-based device interaction.