ACS 712 20A Current Sensor Interfacing with ESP 32

Keirishan Balachandran
2 min readSep 28, 2023

--

Required components

  1. ESP 32
  2. ACS 712 20A current sensor
  3. 6.8k resistor
  4. 12k resistor
  5. Jumper wires

ACS712 current sensor :

The ACS712 integrated circuit, developed by Allegro Micro Systems, utilizes the Hall effect principle to accurately measure current. This IC contains a highly precise and linear Hall sensor circuit, along with a copper conduction path on its surface. It’s capable of measuring both AC and DC currents and is available in 5A, 20A, and 30A modules. Moreover, it offers isolation from the load, making it suitable for various applications. Integrating it with a microcontroller is straightforward, as it outputs an analog voltage with a known scale factor.

ACS712 modules has 3 versions with different sensitivities.

Circuit Diagram:

In the circuit diagram shown above, the ACS712 current sensor’s VCC and GND pins receive power from the VIN and GND pins of the ESP32. If you don’t have a 5-volt voltage supply coming from the ESP32's VIN pin, you should connect an external 5-volt power source to the ACS712 module because it needs precisely 5 volts for its calculations to work correctly.

The ACS712's Data pin, labeled as OUT, produces an analog voltage ranging from 0 to 5 volts. However, this voltage range isn’t directly compatible with the ESP32's ADC, which operates between 0 to 3.3 volts. When there’s no load connected, the OUT pin reads 2.5 volts. This voltage increases when the load is added in a positive direction and decreases to zero when the load is applied in a negative direction.

To ensure smooth operation with the ESP32, a voltage divider is created. This involves connecting a 6.8k ohm resistor and a 12k ohm resistor in series. The voltage across the 12k ohm resistor, which is connected to the ESP32's Analog pin D15, is depicted in the image and connected using an orange wire.

Software Platforms

Arduino IDE

Firmware:

#define currentpin = 4;

float R1 = 6800.0;
float R2 = 12000.0;

void setup() {
Serial.begin(115200);
pinMode(currentpin, INPUT);
}

void loop() {
int adc = analogRead(currentpin);
float adc_voltage = adc * (3.3 / 4096.0);
float current_voltage = (adc_voltage * (R1+R2)/R2);
float current = (current_voltage - 2.5) / 0.100;
Serial.print("Current Value: ");
Serial.println(current);
delay(1000);
}

--

--