2

current sensor (5v) with a 3.3v MCU

I am trying to make a hall effect current sensor (ACS712ELCTR-20A-T) work with a 3.3v MCU. The current sensor is powered with 5v. I specifically choose this sensor because I need to measure current up to 7A powering a led strip. I know INA219 is easier to use (i2c) but it can only read up to 3A. My ACS712 has a sensitivy of 100mV/A according to the datasheet. Here is my code :

void getCurrent() {
  //float acs_rest_voltage = (float) (analogRead(currentPin) * (3.3 / 1023));
  float acs_value = 0.0, acs_sum = 0.0, acs_rest_voltage = 2.5;

for (uint8_t i = 0; i < 11; i++) { acs_sum += analogRead(currentPin); delay(3); // wait for the ADC to settle } acs_value = acs_sum / 11;

float currentRaw = ((((acs_value) * (3.3 / 1023.0)) - acs_rest_voltage) / 0.100);

//current = 2.178956044 * currentRaw - 0.2223241758; // linear regression calibration current = currentRaw;

if (current < 0.0 || current > 321.0) { current = 0.0; } }

it reads 11 samples, averages them, applies a formula, and returns the current. The returned current value is so inaccurate that I even tried to apply a linear regression calibration formula.

The wiring is quite simple : ACS712 has VCC to 5v rail. MCU (seeeduino xiao) has vcc to 3.3v through a LDO voltage regulator (AMS1117). So ACS712 and MCU share the same ground. ACS712 data out pin goes to MCU analog pin (I believe adc is 10 bits) through a voltage divider. I assumed DOUT could output up to 5v so i divided accordingly so the MCU can get 3.3v max data. This did not work great (inaccurate values). I was so desperate that I even tried plugging the ACS712 data OUT to the MCU directly. Since my current wont reach more than 10A, i'm confident it wont output more than 3.3v (it outputs 100mv/A)

Here are 2 schematics of 2 options I tried :

enter image description here

enter image description here

The voltage measured at ACS712 data out when current is zero is 2.5v

When i increase the current (higher brightness on led strip), here is something weird : the voltage I read with my DMM decreases when the amps increases... ? ? ?

I must be doing something wrong, either circuit or code (or both)

Musa
  • 167
  • 1
  • 8

0 Answers0