WEEK 09 — Input Devices

Testing HC-SR04 with XIAO ESP32-C3 using Multimeter

Group Assignment – Input Devices Analysis

Testing HC-SR04 with XIAO ESP32-C3 using Multimeter

Group Assignment – Measuring Power Consumption of an Output Device

The objective of this assignment is to measure the electrical power consumption of an output device. In this case, a 5V DC motor controlled by a XIAO ESP32-C3 through an L298N driver is analyzed. The motor rotates alternately in both directions every 4 seconds.

System Description

The system consists of a DC motor connected to an H-bridge driver (L298N), allowing bidirectional rotation. A microcontroller (XIAO ESP32-C3) controls the motor direction using timed signals.

  • Motor rotation: 4 seconds clockwise
  • Motor rotation: 4 seconds counterclockwise
  • Measurement tools: Multimeter and power supply

Materials and Equipment

The following materials and instruments were used to assemble the system and perform the power consumption measurements of the DC motor.

Measurement Instruments
Instrument Function
Multimeter Used to measure voltage (parallel) and current (series)
DC Power Supply Provides stable voltage for the motor and driver module
Main Components
Component Description
XIAO ESP32-C3 Microcontroller used to control motor direction
L298N Motor Driver H-bridge module used to control motor direction and power
DC Motor (5V) Output device used for rotation and power measurement
Additional Materials
Material Purpose
Protoboard Used to assemble the circuit without soldering
Jumper Wires Electrical connections between components
USB Cable Used to program and power the XIAO ESP32-C3
Resistors (optional) Used if needed for signal conditioning or protection
System Overview

The system integrates a microcontroller (XIAO ESP32-C3) with an H-bridge driver (L298N) to control the direction of a 5V DC motor. Measurement instruments such as a multimeter and a power supply are used to analyze electrical parameters, including voltage, current, and power consumption.

Workflow

  1. Design and assemble the circuit on a protoboard
  2. Connect the motor to the L298N driver (OUT1 and OUT2)
  3. Upload the control code to the XIAO ESP32-C3
  4. Verify bidirectional motor operation
  5. Measure voltage across the motor terminals (parallel measurement)
  6. Measure current flowing through the motor (series measurement)
  7. Calculate electrical power using measured values

Code Description – Bidirectional DC Motor Control

This program controls a DC motor using an H-bridge driver (L298N) to alternate its rotation direction at fixed time intervals. The motor rotates in one direction for 3 seconds, then reverses its direction for another 3 seconds, creating a continuous oscillating motion.

Code Implementation
// DC Motor Bidirectional Control with Time Intervals

const int IN1 = 6; // D4
const int IN2 = 7; // D5

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
}

void loop() {

  // Rotate in one direction
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  delay(3000);

  // Rotate in opposite direction
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  delay(3000);
}
    
Program Logic
  • The pins IN1 and IN2 control the direction of the motor through the L298N driver
  • When IN1 is HIGH and IN2 is LOW, the motor rotates in one direction
  • When IN1 is LOW and IN2 is HIGH, the motor rotates in the opposite direction
  • The delay function defines the duration of each movement (3 seconds)
Key Concept

By alternating digital signals and using time delays, the system achieves bidirectional motion without sensors. This technique is useful in applications requiring repetitive or oscillating movement.

Voltage Measurement

Voltage was measured in parallel across the motor terminals while operating in both directions.

Rotation Direction Voltage (V)
Clockwise 3.56 V
Counterclockwise -3.56 V

The negative voltage indicates a reversal in polarity due to the H-bridge configuration.

Current Measurement

Current was measured in series with the motor using a multimeter.

Rotation Direction Current (mA)
Clockwise 12.10 mA
Counterclockwise -12.10 mA

Power Calculation

Electrical power is calculated using the fundamental formula:

P = V × I

Where:

  • P = Power (Watts)
  • V = Voltage (Volts)
  • I = Current (Amperes)
Calculation

Converting current to amperes:

12.10 mA = 0.0121 A

Power:

P = 3.56 × 0.0121 = 0.043076 W

Therefore, the motor consumes approximately:

0.043 W (43 mW) in both directions.

Group Reflection

As a group, we learned how to measure electrical parameters in a real system and how to correctly use a multimeter for both voltage and current measurements. We understood the importance of measuring voltage in parallel and current in series, as well as the implications of polarity when working with bidirectional motor control.

Additionally, we gained practical experience in calculating power consumption and analyzing how electronic components behave under real operating conditions. This process reinforced our understanding of basic electrical principles and their application in embedded systems.