Current sensor ACS712 error

One thing I noticed is this line

  current = map(current/5, 0, 1023, 0, 5000);

Since the Spark Core sports a 12bit ADC with 3.3V you’d need to map the range 0..4095 to your voltage range 0..3300mV rather than 10bit 0..1023 to 0..5000mV.

One word of caution, too. Since you got your sensor supplied with 5V (minus about 0.2V voltage drop across protective diode) you have to be careful that your output never exceeds 3.3V otherwise you’ll possibly fry your analog pin!
Either you limit the output or you see if the sensor also works with 3V3 supply (e.g. ACS711).

Before looking at it closer, could you please reformat your code as outlined in this thread

4 Likes