Week14

Assignment: Interface and Application Programming

Individual Assignment:

Creating a PCB with Seeed Studio XIAO ESP32-C3 and an input sensor. For this assignment accelerometer sensor is used to blink LEDs positioned to that direction.

Learning Experience:

During this assignment, I had a valuable and hands-on learning experience while developing an ESP32-C3-based LED control system. I worked with web-based wireless communication to control multiple LEDs through an HTML interface. This project gave me practical insight into Wi-Fi-based embedded networking, web server creation, and GPIO control.

I learned how to:

This improved my confidence in embedded development and gave me a clear understanding of how microcontrollers interact with the internet and control hardware in real time.

Key Accomplishments:

Create Schematic in PCB Design Tool (KiCAD):

For full documentation, refer: Electronics Production Assignment

  1. Place ESP32-C3 module

  1. Add 4 Resistors

  1. Add 4 LEDs

  1. Wire it

Design the PCB:

Hardware Implementation:

GPIO Mapping for LEDs:

LED Color

GPIO

Function

LED1

3

LED1 Control

LED2

4

LED2 Control

LED3

5

LED3 Control

LED4

6

LED4 Control

Each GPIO was connected to an LED through a 220Ω resistor to limit current.

Communication: Wi-Fi (HTTP Server):

My project used Wi-Fi as the communication backbone. The ESP32-C3 connected to a local Wi-Fi network and hosted an HTTP server that users could access from any device on the same network.

Even though it’s not “network communication,” it's still digital communication:

🔌 Wired Communication

📡 Wireless Communication

🌐 IoT Communication

Power Supply

 Arduino IDE Setup:

  1. Open Arduino IDE.
  2. Go to File > Preferences, and add this URL to Additional Board Manager URLs:

https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json

      3. Go to Tools > Board > Board Manager, search for ESP32 and install it.

  1. Board: ESP32C3 Dev Module
  2. Port: Select the COM port assigned to your ESP32-C3

Code Verification and Upload:

Figure 1: Code successfully verified and uploaded to the board

After writing and verifying the code, I uploaded it to the ESP32-C3 board. The compilation was successful, and the code was uploaded without any errors.

Wi-Fi Connection Established:

Figure 2: Device connecting to Wi-Fi as shown in the Serial Monitor

The Serial Monitor showed that the device was successfully connecting to my Wi-Fi network using the SSID and password provided in the code.

Cloud Connection:

Figure 3: Device successfully connected to the cloud platform

Along with the Wi-Fi connection, the device also connected to the cloud platform using the API key, confirming that the cloud communication setup was working properly.

Data Transmission Success:

Figure 4: Real-time data monitoring and successful communication

ESP32-C3 LED Control via Web Server:

For my individual assignment, I focused on learning wireless web-based control of hardware using ESP32-C3. I explored how to:

In addition to basic hardware handling, I learned to serve real-time UI updates via HTTP requests, a core IoT technique.

Web Interface Functionality:

The HTML page consisted of:

Complete Arduino Code:

#include <WiFi.h>

#include <WebServer.h>

// Wi-Fi Credentials

const char* ssid = "MYNAVATHI S";

const char* password = "Desha2416";

// LED pins

const int ledPins[4] = {3, 4, 5, 6}; // GPIOs for Red, Green, Blue, Pink

WebServer server(80);

// HTML Page with JavaScript and CSS

const char MAIN_page[] PROGMEM = R"rawliteral(

<!DOCTYPE html>

<html>

<head>

  <title>ESP32 LED Control</title>

  <style>

    body { font-family: Arial; text-align: center; margin-top: 40px; background: #f0f0f0; }

    h1 { color: #333; }

    button {

      font-size: 18px; padding: 10px 20px; margin: 10px;

      border: none; border-radius: 8px;

      cursor: pointer;

      color: white;

    }

    .red { background-color: #e53935; }

    .green { background-color: #43a047; }

    .blue { background-color: #1e88e5; }

    .pink { background-color: #d81b60; }

    .off { background-color: #757575; }

  </style>

</head>

<body>

  <h1>ESP32 LED Controller</h1>

  <div>

    <button class="red" onclick="send('red/on')">LED1 ON</button>

    <button class="off" onclick="send('red/off')">LED1 OFF</button><br>

    <button class="green" onclick="send('green/on')">LED2 ON</button>

    <button class="off" onclick="send('green/off')">LED2 OFF</button><br>

    <button class="blue" onclick="send('blue/on')">LED3 ON</button>

    <button class="off" onclick="send('blue/off')">LED3 OFF</button><br>

    <button class="pink" onclick="send('pink/on')">LED4 ON</button>

    <button class="off" onclick="send('pink/off')">LED4 OFF</button>

  </div>

  <script>

    function send(path) {

      fetch('/' + path)

        .then(response => response.text())

        .then(data => console.log(data));

    }

  </script>

</body>

</html>

)rawliteral";

void handleRoot() {

  server.send_P(200, "text/html", MAIN_page);

}

void setupRoutes() {

  server.on("/", handleRoot);

  server.on("/red/on", []() {

    digitalWrite(ledPins[0], HIGH);

    Serial.println(" LED1 ON");

    server.send(200, "text/plain", "Red ON");

  });

  server.on("/red/off", []() {

    digitalWrite(ledPins[0], LOW);

    Serial.println(" LED1 OFF");

    server.send(200, "text/plain", "Red OFF");

  });

  server.on("/green/on", []() {

    digitalWrite(ledPins[1], HIGH);

    Serial.println("LED2 ON");

    server.send(200, "text/plain", "Green ON");

  });

  server.on("/green/off", []() {

    digitalWrite(ledPins[1], LOW);

    Serial.println("LED2 OFF");

    server.send(200, "text/plain", "Green OFF");

  });

  server.on("/blue/on", []() {

    digitalWrite(ledPins[2], HIGH);

    Serial.println("LED3 ON");

    server.send(200, "text/plain", "Blue ON");

  });

  server.on("/blue/off", []() {

    digitalWrite(ledPins[2], LOW);

    Serial.println("LED3 OFF");

    server.send(200, "text/plain", "Blue OFF");

  });

  server.on("/pink/on", []() {

    digitalWrite(ledPins[3], HIGH);

    Serial.println("LED4 ON");

    server.send(200, "text/plain", "Pink ON");

  });

  server.on("/pink/off", []() {

    digitalWrite(ledPins[3], LOW);

    Serial.println("LED4 OFF");

    server.send(200, "text/plain", "Pink OFF");

  });

}

void setup() {

  Serial.begin(115200);

  for (int i = 0; i < 4; i++) {

    pinMode(ledPins[i], OUTPUT);

    digitalWrite(ledPins[i], LOW);

  }

  WiFi.begin(ssid, password);

  Serial.print("Connecting to WiFi");

  while (WiFi.status() != WL_CONNECTED) {

    delay(500);

    Serial.print(".");

  }

  Serial.println("\nWiFi connected. IP address: ");

  Serial.println(WiFi.localIP());

  setupRoutes();

  server.begin();

}

void loop() {

  server.handleClient();

}

Serial Monitor Output:

When running, you should see

And for LED control via web:

Accessing Web UI:

  1. Connect ESP32-C3 to Wi-Fi.
  2. Open Serial Monitor to get the IP.
  3. In a browser, enter http://<ESP32-IP>.
  4. Click buttons to toggle each LED.
  5. Serial Monitor logs each action.

How It Works:

Testing the System:

  1. Upload the code to the ESP32-C3.
  2. Open Serial Monitor at 115200 baud.
  3. Note the IP address (e.g., 192.168.1.125).
  4. Open a browser and visit: http://<IP_ADDRESS>.
  5. Click buttons and observe LEDs and Serial Monitor updates.

Learnings :

This assignment helped me strengthen my knowledge in:

Video link

Working file link: LINK

<<Back to Home