ACS712 5A Youth - Easy Way to Measure Current in Your Projects

by KusTech in Circuits > Arduino

27 Views, 0 Favorites, 0 Comments

ACS712 5A Youth - Easy Way to Measure Current in Your Projects

ACS712 5A Youth.png

Hello fellas!

In this article, we’ll take a closer look at the ACS712 current sensor module, compare it to standard options available on the market, and connect it to the ESP32-S3 Youth to display readings in the Serial Port on a computer.

What is this module?

The ACS712 5A is a current sensor designed to measure currents up to 5A, both AC and DC. It outputs a voltage proportional to the current, making it easy to read with microcontrollers and display on a computer. Accurate and compact, it’s perfect for monitoring different circuits in your projects.

What did we improve?

The sensor is designed for 5V logic and outputs a 5V signal. To use it with 3.3V logic microcontrollers (like the ESP32), a voltage divider is typically added to the signal output.

We’ve gone a step further and integrated a separate channel with a precision resistor divider (1 kOhm and 2 kOhm resistors with 0.1% accuracy instead of the usual 5% -> resulting in 0.2% accuracy for the divider instead of 10%), which gives a 3.3V signal. Additionally, we’ve added a physical power switch and 8 unique Anime designs, each inspired by a different country.

Supplies

PXL_20241217_204546202.jpg

First Look

ACS712 Youth look 1#.png

This module is an upgraded version of the popular blue ACS712 current sensor, well known one by many electronics enthusiasts. In my experience, it lacked easy support for 3.3V logic microcontrollers. I always had to find extra resistors, combine them if I didn’t have the right values, and deal with unnecessary trouble.

The ability to turn off the sensor also helps with accurate calibration. Just remember—when turning it on, there should be no current flowing through it, as the sensor sets its reference voltage at that moment for future measurements.

Lastly, I really enjoy unique and cool-looking boards that catch the attention of my friends and even my professors.

That’s why I decided to design my own version.

Let's Measure Some Values

AMS1117 Measurment.png
AMS1117_1#_ACS712_code.png

For the test, we used the same setup as in the AMS1117 3.3V Youth tests, shown in the photo.

We supplied 5V through USB at the input and got just over 3V at the output, with about 1A of current flowing through a resistor. If you need help uploading the code to measure current, I explain it in another article.

Here’s what’s interesting: the circuit includes both a digital ammeter and the ACS712 Youth current sensor. The first photo shows the ammeter readings, and the second shows the ACS712 readings. The accuracy is pretty good.

Here’s the code for ESP32-S3 Youth:

#include <Arduino.h>

// Configuration
const int ACS712_Pin = 14; // ESP32-S3 Youth pin (A0) connected to ACS712 sensor
const float Sensitivity = 185.0; // Sensor sensitivity (185 mV/A for the 5A version)
const float ADC_Resolution = 4095.0; // ESP32 ADC resolution (12-bit)
const float V_Ref = 5.0; // Reference voltage for the divider (5V)
const float VoltageDividerGain = 1.5; // Voltage divider gain (1k + 2k) / 2k
const float noiseThreshold = 0.02; // Ignore current below 20 mA (noise reduction)
const float calibrationFactor = 1.075; // Calibration factor (adjust to match multimeter readings)

// Smoothing parameters
const float alpha = 0.5; // Smoothing factor (0.3-0.6 for faster response)

// Variables
float zeroCurrentVoltage = 0; // Voltage at zero current
float current = 0; // Current value
float smoothedVoltage = 0; // Smoothed voltage value

void setup() {
Serial.begin(115200);

// Measure "zero current" voltage
Serial.println("Calibrating sensor...");
zeroCurrentVoltage = calibrateSensor();
smoothedVoltage = zeroCurrentVoltage; // Initialize smoothed value
Serial.println("Calibration completed!");
Serial.print("Zero current voltage: ");
Serial.println(zeroCurrentVoltage, 3);
}

void loop() {
// Read raw voltage from the sensor
float rawVoltage = analogRead(ACS712_Pin) * V_Ref / ADC_Resolution * VoltageDividerGain;

// Apply exponential smoothing
smoothedVoltage = alpha * rawVoltage + (1 - alpha) * smoothedVoltage;

// Calculate current (voltage relative to zero point)
current = (smoothedVoltage - zeroCurrentVoltage) / (Sensitivity / 1000.0);

// Apply calibration factor
current *= calibrationFactor;

// Ignore noise below the threshold
if (abs(current) < noiseThreshold) {
current = 0; // Set current to zero
}

// Output data to the Serial Monitor
Serial.print("Smoothed Voltage: ");
Serial.print(smoothedVoltage, 3);
Serial.print(" V | Current: ");
Serial.print(current, 3);
Serial.println(" A");

delay(100); // Reduced delay for faster response
}

// Function to calibrate the sensor (measures voltage at zero current)
float calibrateSensor() {
float sum = 0;
const int samples = 100; // Number of samples for calibration

for (int i = 0; i < samples; i++) {
sum += analogRead(ACS712_Pin) * V_Ref / ADC_Resolution * VoltageDividerGain;
delay(10);
}

return sum / samples; // Return average voltage
}


In Conclusion

ACS712 Youth Check on Tindie 1#

In my opinion, this is a pretty interesting module that can compete with the standard blue ACS712 module. Personally, I’ll definitely use it in my projects whenever current measurement is needed.


Thank you for reading this article! If you have any questions or if something doesn’t work, feel free to ask in the comments section.


By the way - don't forget to check all Collection in my Tindie shop :)