Voltage measurement on Analog PIN

Hi,
I am using an ACS712 with puts out 2.56V in idle on my Analog0 Pin (measured with voltmeter between A0 and GND). The sample sketch for voltage measurement puts out 3.98. What can cause this?
Thanks!

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);
}

Every practical (real) sensor has gain and offset which are determined by 2-point calibration. The data sheets says that that the output sensitivity of the ACS712 current sensor is 66 to 185 mV/A. It looks like that the sensor possesses some offset in addition to gain.

The equation float voltage = sensorValue * (5.0 / 1023.0); is valid for a sensor which has no offset like LM35 Temperature Sensor. For your sensor, you have the idle response (idle to me 0A) is 2.56V. Now apply some current to the load (say, 5A) and measure the output voltage, and then you determine the response equation y = mx +C.

That's very strange... What happens when you ground A0 or connect it to Vcc (with the current sensor disconnected).

Is your Arduino running on 5V? (The default ADC reference is Vcc so a low Vcc would give you a higher input-voltage reading.)

...Maybe you're Arduino is blown??? Maybe try a different analog input?

Are you powering the ACS712 from the 5volt pin of the Arduino?

Which Arduino.

3.98volt out makes me think you're using a 3.3volt Arduino (with 3.3volt default Aref).

Your German post mentions an ESP8266.
Leo..

GolamMostafa:
For your sensor, you have the idle response (idle to me 0A) is 2.56V. Now apply some current to the load (say, 5A) and measure the output voltage, and then you determine the response equation y = mx +C.

The ACS712 is a RATIOMETRIC sensor.
Zero current output is therefore not a constant 2.5volt (or 2.56volt), but VCC/2.

Therefore A/D result is always ~512 at any supply voltage if you power the sensor from the MCU supply with default Aref. Assuming you stay within the voltage range of the sensor (4.5-5.5volt).
Sensor gain has AFAIK the same ratiometric behaviour.
Gain goes up with supply voltage and A/D goes down with voltage, resulting in a stable gain.
Leo..

I am using a Wemos D1 mini and I am powering the Sensor from the 5V Pin. Is that ok?

jankir:
I am using a Wemos D1 mini and I am powering the Sensor from the 5V Pin. Is that ok?

No.
A 5volt ratiometric sensor needs to run on a 5volt Arduino.
Better find another current sensor.
Leo..

So should i power it from my 230V to 5V converter then?

The problem is that there is no ratiometric relationship between sensor supply and ~1volt Aref of the Wemos.
You never will have a stable zero and stable current readings.

For testing, change this line
float voltage = sensorValue * (5.0 / 1023.0);
into
float voltage = sensorValue * (3.3 / 1024.0);

I assume you know that the ACS712 (and the circuit boards) are not designed to measure 230volt AC.
Potentially very dangerous if you are planning to measure three fase currents in a metal/grounded cooktop.
Leo..

Hi,
Try setting the pin as an input. Like pinMode(pin,INPUT).

I will try your suggestion, in this case I am trying to measure the consumption of a washing machine. Which sensor is then suitable for 230v AC?
Thanks!

tauro0221:
Hi,
Try setting the pin as an input. Like pinMode(pin,INPUT).

No that makes no difference at all, the analogRead call dose that for you.

Try this for a sensor

Can I use a 5V to 3,3V logic level converter to convert the signal for my 3.3 input pin?

Yes, but a pair of resistors as a potential divider will work just as well.

A Wemos D1 Mini has a 220k:100k voltage divider on the A/D input.

A clamp-on sensor is in this case as bad as an ACS sensor, because Aref of an ESP8266 is not related to it's VCC.
But at least it's a lot safer.
Leo..

I tried something completely different now, with sucess.
I sent 3,3V to the ACS712 and tweaked the center of the RMS a bit and am now getting readings that make sense. The whole circuit is enclosed in a case, so I think it should be safe.

If you want to stick with the ACS712...
If you use a 180k resistor between sensor output and analogue-in, then the analogue input range of the Wemos is 0-5volt.
Then you can power the sensor from 5volt, and you should get about 512 without current (zero crossings).
5volt supply to the sensor must be stable.
Leo..

The whole circuit is enclosed in a case, so I think it should be safe.

When we say not safe we mean safe for your Arduino. Having it in a case in no way mitigates against this.

jankir:
I tried something completely different now, with sucess.
I sent 3,3V to the ACS712 and tweaked the center of the RMS a bit and am now getting readings that make sense. The whole circuit is enclosed in a case, so I think it should be safe.

The ACS711 is the 3V capable chip in the series, the ACS712 is 5V only...