I am trying to use an ACS712 with an ESP32, I am however struggling to calibrate it to zero at zero/short circuit current. Even when I get the value close to zero, just unplugging the usb and plugging it shifts the value to +0.5A or sometimes more.
I am using the 20A version , the esp32 is powered therough the USB of a pc and the ACS712 I am powering from the 5v pin of the ESP32. I tried and added decoupling caps on the power pins of the sensor and on the power of the ESP32 and still no success.
@shamooooot
The ESP32 pins are limited to 3.3V.
Do you have a voltage divider between the ACS712 and the ESP?
Does you ESP board have a voltage divider on it?
Which library are you using?
You need a stable and low noise 5V power supply for the ESP and ACS712.
espressif recommends putting a 100nF capacitor on the ADC pin and averaging several readings
To correct the readings of current using ACS712 and ESP32, follow these steps:
Calibration: Measure known currents using a reliable multimeter and compare them with the readings from the ACS712. Note any discrepancies.
Offset Adjustment: If there's a constant offset error (a difference between zero current readings), adjust the software to compensate for it by subtracting or adding a constant value to the readings.
Gain Adjustment: If there's a scale error (difference in sensitivity), adjust the gain in the software to match the actual sensitivity of the sensor. This may involve multiplying or dividing the readings by a correction factor.
Testing and Iteration: Test the corrections thoroughly under various conditions to ensure accuracy. Iterate adjustments as needed until the readings align closely with the actual currents.
Consider Environmental Factors: Factors like temperature and electromagnetic interference can affect sensor accuracy. Minimize these effects or incorporate compensatory measures in your calibration process.
Documentation: Keep thorough documentation of your calibration process and any adjustments made to ensure repeatability and traceability.
Consider External Calibration: For precise applications, consider calibrating the sensor externally using a known current source and adjusting the software accordingly.
By following these steps and ensuring thorough testing, you can correct the readings of current using ACS712 and ESP32 for improved accuracy in your project.
The ACS712 is a ratiometric 5volt-logic only sensor.
You will never get is to play nicely with the 3.3volt-logic absolute A/D of an ESP.
With this combo, values will depend on current and supply voltage of the ACS.
What are you measuring.
if grounds can be shared, then an INA219 could be a much better solution.
Leo..
I have bought like 10 INA226 sensors, I tried everything to get data from them, but it didn't work no matter how much I have tried, there's no data/response from it. Either they are a scam or it's really complicated, that's why I shifted to the ACS712 as they are less complicated..
You need to give us a lot more information if you don't want this thread to end as your previous one. We can't help you if we don't know what you're measuring, how you have connected things, and what your code looks like.
Leo..
Another bad tutorial.
You never will get an ACS712 to play nicely with an ESP. An ACS712 has a ratiometric output that needs a ratiometric A/D, which the ESP doesn't have (An Uno R3 does). With an ESP, current and zero point also depend on supply voltage of the ACS. If you want to get it sort-off ok, then you also need to measure ACS supply voltage, and add that variation to the current equation.
Leo..
I have tried almost everything listed here and elsewhere, Wawa is right you can't get it to play nicely, just plugging/unplugging the USB cable will cause the zero current value to drift substantially. I finally used a Zero function, so whenever I need to measure current it first consider whatever value coming from the sensor to be zero. Then the results are good enough.
I tried several 30A sensors with esp32 and found out:
Use a Voltage divider like pin0010 said.
Connections are really important. Solder on the connections.
Each sensor has a different zero and sensitivity. Measure and calibrate for each sensor once. Use an average of multiple measurements to calculate the offset and sensitivity, I use 1000 measurements.
If the connections are good, there should be almost no difference in current measurements the next time you connect the same ACS712 to an ESP32.
It seems like starting up the ESP32 has some effect on the measurements values, at least in my case where I am using WiFi. So calculate the offset in the main loop, not in the setup.
The code I use to calculate the offset:
if (this->iteration < 1000) {
right_current_offset += analogRead(RIGHT_MOTOR_CURRENT_PIN)*0.001;
this->iteration++;
}
Do this while supplying 0 ampere and X ampere (I used 4A from a lab supply), and then calculate offset and sensitivity.
multiplier: -4/(offset_minus - offset_zero)/2 + 4/(offset_plus - offset_zero)/2
offset: offset_zero
right motor
offset_minus at -4A: 1595.0
offset_zero at 0A: 1808.3
offset_plus at 4A: 2025.0