Testing HC-SR04 with XIAO ESP32-C3 using Multimeter
Testing HC-SR04 with XIAO ESP32-C3 using Multimeter
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.
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.
The following materials and instruments were used to assemble the system and perform the power consumption measurements of the DC motor.
| Instrument | Function |
|---|---|
| Multimeter | Used to measure voltage (parallel) and current (series) |
| DC Power Supply | Provides stable voltage for the motor and driver module |
| 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 |
| 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 |
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.
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.
// 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);
}
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 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 was measured in series with the motor using a multimeter.
| Rotation Direction | Current (mA) |
|---|---|
| Clockwise | 12.10 mA |
| Counterclockwise | -12.10 mA |
Electrical power is calculated using the fundamental formula:
P = V × I
Where:
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.
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.