Group Assignment
This week's group assignment consisted of measuring the power consumption of an output device using laboratory measurement equipment. The objective was to understand how much current and power an output device consumes during operation and how this affects power supply requirements and circuit design.
The complete documentation of the group work can be found in the following page:
Group assignment documentation
Individual Assignment — Week 10
In this part of the assignment, an interactive output system was developed using the XIAO ESP32C3 board, a servo motor, a switch, and an LED. The objective was to understand how output devices respond to information received from sensors or digital inputs, and how to build an interactive system in which the microcontroller processes information and generates a physical or visual response.The process was not completed all at once, but progressively, by adding components step by step and verifying the operation of the system at each stage.
1. Electronic Board
For this week, I worked again with the same custom electronic board used as the base of the system. The board was designed in KiCad, beginning with the schematic and then developed into the PCB layout.
The board is based on a XIAO ESP32 microcontroller, chosen for its compact dimensions and its processing and communication capabilities. The VBUS and GND lines were clearly organized and distributed to simplify the integration of external devices.
The board includes:
- 1kΩ resistors for current limiting in outputs
- 10kΩ resistors used as pull-down or pull-up resistors in inputs
- Header connectors for sensors and actuators
- Accessible pads to facilitate testing and electrical measurements
The PCB routing was made on a single side, optimizing the trace layout and avoiding crossings, which is important for CNC fabrication. The trace width was set to 0.4 mm, and adequate spacing was maintained to ensure proper milling.
The fabrication process consisted of milling the copper board, manually drilling the required holes, and soldering the THT components. After assembly, continuity was verified with a multimeter and the circuit was tested to confirm its basic operation.
On top of this base, output devices such as a servo motor and an LED were connected. The board design allowed signal and power to be distributed efficiently, making it possible to control these devices directly from the microcontroller.
2. Servo Controlled by Sensor Information
The first stage consisted of controlling a servo motor according to the information coming from an input sensor. In this case, the sensor provided a digital signal (HIGH or LOW), and the servo motor responded by changing its position.
The servo was connected as follows:
| Servo | XIAO ESP32C3 |
|---|---|
| Red wire | 5V / VBUS |
| Brown wire | GND |
| Yellow | Digital pin D3 |
The servo operates through a PWM signal that allows it to move to a specific angle. To control the servo, the ESP32Servo library was used.
The system logic was the following:
- If the sensor detects motion or activation, the servo moves.
- If the sensor does not detect anything, the servo returns to its initial position.
This was the first step in building an interactive system in which the microcontroller not only receives information, but also acts physically on the environment.
Code used:
#define PIR_PIN D4
#include
Servo myServo;
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
myServo.attach(D3);
}
void loop() {
int estado = digitalRead(PIR_PIN);
Serial.println(estado);
if (estado==1){
delay(200);
myServo.write(0);
delay(1000);
myServo.write(180);
delay(1000);
}
else{
myServo.write(0);
}
}
This stage helped to understand the relationship between: sensor → microcontroller → actuator.
3. Integration of a Switch as System Control
In the second stage, a switch was added to the system in order to activate or deactivate the operation of the servo. In this way, the system was not always active, but could be manually controlled.
The switch was connected using a pull-down configuration:
| Switch | XIAO ESP32C3 |
|---|---|
| One side of the switch | 3.3V |
| Other side of the switch | Pin D6 |
| 10k resistor | Between D6 and GND |
Code used:
#define PIR_PIN D4
#define SWITCH_PIN D5
#include
Servo myServo;
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
pinMode(SWITCH_PIN, INPUT);
myServo.attach(D3);
}
void loop() {
int encendido = digitalRead(SWITCH_PIN);
Serial.print("boton:");
Serial.println(encendido);
delay(200);
if (encendido == 1) {
int estado = digitalRead(PIR_PIN);
Serial.print("pir:");
Serial.println(estado);
if (estado == 1) {
delay(200);
myServo.write(0);
delay(1000);
myServo.write(180);
delay(1000);
} else {
myServo.write(0);
}
}
}
With this configuration:
- When the switch is open, the pin reads 0.
- When the switch is pressed, the pin reads 1.
The system logic then changed to:
- If the switch is activated, the system runs.
- If the switch is deactivated, the servo does not respond to the sensor.
- If the switch is activated and the sensor detects motion, the servo moves.
This made it possible to introduce the concept of manual system control through an additional digital input, adding a new layer of interaction.
4. Integration of an LED as a System Indicator
In the third stage, an LED was added as a visual indicator of the system state. The LED makes it possible to know whether the system is active or not without checking the code or the Serial Monitor.
The LED was connected as follows:
| LED | XIAO ESP32C3 |
|---|---|
| Anode | Resistor → output pin |
| Cathode | GND |
Code used:
#define PIR_PIN D4
#include
#define SWITCH_PIN D5
#define LED_PIN D6
Servo myServo;
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
myServo.attach(D3);
pinMode(SWITCH_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
int encendido = digitalRead(SWITCH_PIN);
Serial.print("boton:");
Serial.println(encendido);
delay(200);
if (encendido==1){
digitalWrite(LED_PIN, HIGH);
int estado = digitalRead(PIR_PIN);
Serial.print("pir:");
Serial.println(estado);
if (estado==1){
delay(200);
myServo.write(0);
delay(1000);
myServo.write(180);
delay(1000);
}
else{
myServo.write(0);
}
}
else{
digitalWrite(LED_PIN, LOW);
}
}
The LED works as a simple digital output:
- HIGH → LED ON
- LOW → LED OFF
The final system logic was:
- The switch activates the system.
- When the system is active, the LED turns on.
- If the system is active and the sensor detects motion, the servo moves.
- If the system is deactivated, the LED turns off and the servo does not move.
In this way, a complete interactive system was built by combining:
- an input device (sensor),
- manual control (switch),
- visual output (LED),
- mechanical output (servo motor).
5. System Architecture
The final system can be understood as a chain of information:
Switch → enables the system
Sensor → detects motion
Microcontroller → processes the information
Servo → generates movement
LED → indicates the system state
This flow represents a basic embedded system in which the microcontroller acts as the control unit between inputs and outputs.
5. Learning Outcomes
During this process, I learned:
- How to control a servo motor from a microcontroller.
- How to use a library to generate PWM signals.
- How to use a switch with a pull-down configuration.
- How to control an LED as a digital output.
- How to combine multiple inputs and outputs in the same system.
- How to design the logic of an interactive system.
- The importance of testing the system step by step instead of all at once.
- The relationship between hardware and software in embedded systems.
This exercise was important because it made it possible to move from individual tests to a more complex interactive system, which is essential for the development of the final project.
Download Files
The design files used in this assignment can be downloaded below.
