0

I'm using several ACS712-based 5A current sensors. They're non-polar and so (I gather) the output is biased to Vcc/2 to allow a swing in either direction. The sensor outputs +/- 185mV/A, plus the bias.

The example sketch I've seen does a computation like amps = ((analogRead(A0) * 5.0) / 1023) - 2.5 (where 2.5v is the bias).

In my case the actual current value and polarity aren't important, just the presence of current. Is there anything untoward about doing this instead?

boolean isCurrent = (abs(analogRead(A0) - 512) > thresholdValue);

This avoids floating point (unless abs() forces it?) and an ADC count of 512 should be equivalent to a bias of Vcc/2. The threshold just cores out some noise / jitter / drift. Seem OK? Can anyone suggest a better approach?

  • yes, but most (all?) of the "negative" is noise anyway right? or is the flow reversible? – dandavis Oct 8 '17 at 6:13
  • @dandavis - For any given sensor the flow will be one-way, but I can't assume that all will be wired the same. There are 12+ of these and their inputs will arrive as pairs of black wires. Since the reading code is common to all (in a loop), I have to accommodate both polarities. – Jim Mack Oct 8 '17 at 12:45
1

No, there is nothing untoward about that - it is perfectly acceptable and, in fact recommended, since as you note it uses no floating point.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.