Do you need to map analog inputs?

Generic question. I am using an ACS712 current sensor attached to an analog input. I want two things to happen. A. Send the amperage to a gauge in a Nextion HMI that reads real time, and B. Will flash an alarm that if the current gets above a certain set.

My question, do I NEED to map the value or can I just leave it in its raw form as the Arduino interprets it?

Are there any benefits to mapping this value?

In your case, you can simply determine the set of analog values that represents the alarm condition.

e.g.

if (analogRead(A1) > 917) sound_alarm();

Benefits of mapping the value might be to make the program more understandable to someone else.

1 Like

Hi,
If you are going to display an actual Amp value, you can use map the convert the raw analog to Amps value.

Tom... :smiley: :+1: :coffee: :australia:

1 Like

Analog pins read voltage but current may be calculated.

Take care to not burn IO pins!

Use the raw value and avoid Arduino floating point.

5V is 5000mV. Working units, mV and mA, we don't need decimals.

The ADC error margin is wide enough that I can cheat to make it easier...

5000mV / 1023 = 4.88mV per step x raw read = can be 5V instead of 4.99.

Benefits? Faster math w/o losing what accuracy you have and smaller memory space.

1 Like

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