Esp32 acs 712 5a

can anyone provide the code for acs712 5a esp 32

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}
void loop() {
  analogReadResolution(10);
  // put your main code here, to run repeatedly:
  int adc = analogRead(32);
  float voltage = adc * 3.3 / 0.805;
  float current = (voltage - 1.60) / 1096;
  if (current < 0.16) {
    current = 0;
  }
  Serial.print("Current : ");
  Serial.println(current);
  delay(300);
}

this code gives incorrect value

void setup() {
  Serial.begin(9600);
  analogReadResolution(10);
}
void loop() {
  float current = float(abs(analogRead(32) - 512)) / 102.4; //Ampere. 5A max.
  //if (current < 0.16)current = 0;
  Serial.print("Current : ");
  Serial.println(current,3);
  delay(300);
}

when no load is connected its showing
15:50:28.624 -> Current : 1.416

show schematic. i think you power module with 5v and try to read on 3v input.

acs712 siganl pin is connected to D35
acs 712 is connected to 3.3v

show

image

void setup() {
  Serial.begin(9600);
  analogReadResolution(10);
}
void loop() {
  float current = float(abs(analogRead(32) - 512)) / 102.4; //Ampere. 5A max.
  //if (current < 0.16)current = 0;
  Serial.print("Current : ");
  Serial.println(current,3);
  delay(300);
}

their was an . in between 1024 line afte fixing no volt is showing 0.067 but when i connect load nothing hapens

ACS712.pdf (662.5 KB)
minimum 4,5V supply

now i changed to 5v and no volt changed to 0.161 but when i connect load nothing happens

void setup() {
  Serial.begin(9600);
  analogReadResolution(10);
}
void loop() {
  float current = float(abs(analogRead(34) - 512)) / 102.4; //Ampere. 5A max.
  //if (current < 0.16)current = 0;
  Serial.print("Current : ");
  Serial.println(current,3);
  delay(300);
}
// Include the required libraries
#include <ACS712.h>

// Define the pin number for the ACS712 sensor
#define ACS712_PIN 35

// Define the sensitivity of the ACS712 sensor
#define ACS712_SENSITIVITY 185 // 185mV/A for ACS712-05A module

// Declare the ACS712 object
ACS712 acs712(ACS712_PIN, ACS712_SENSITIVITY);

void setup() {
  // Initialize the serial communication
  Serial.begin(9600);
}

void loop() {
  // Read the current value from the ACS712 sensor
  float current = acs712.getCurrentDC();

  // Print the current value to the serial monitor
  Serial.print("Current: ");
  Serial.print(current);
  Serial.println("A");

  // Wait for a short period before taking another reading
  delay(100);
}

why ist showing Compilation error: 'class ACS712' has no member named 'getCurrentDC'

i have no responsibility of not my code.

brother i dont know what to do next i have tried everthing to get the acs712 working dtill no use

free module from wiring, connect 5v to 5V, GND to GND, take multimeter and watch voltage between signal and GND, you should see 2,5V.

yes bro its 2.5

well. reconnect module 5v to 3,3V and measure signal now

now its 1.59

take Li-Ion cell and resistor, or other constant current source. measure current with MM, it should be about 1A, then connect to load pins and measure signal output voltage

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.