I am new in this world and i have never used an esp32-s3 so i dont know if im doing good with my ADC or why this sensor is not reading well.
My code is this one:
float sensitivity = 0.066;
void setup() {
Serial.begin(9600);
}
void loop () {
float I = getCurrent(200);
if (I <= 0) {
Serial.print("Current: ");
Serial.print("0.00");
Serial.println("A");
delay(1000);
} else {
Serial.print("Current: ");
Serial.print(I);
Serial.println("A");
delay(1000);
}
}
float getCurrent (int numSamples)
{
float sensorVoltage;
float current = 0;
for (int i = 0; i < numSamples; i++)
{
sensorVoltage = analogRead(A0) * (5.0 / 4095.0);
current = current + ((sensorVoltage - 2.5) / sensitivity) / 2;
}
current = current / numSamples;
return current;
}
4 posts - 4 participants