Hey folks
Very first topic here, just registered. I’m also preeeeetty new to the Arduino-world, so please, polar-bear with me.
I’m trying to use an ACS712-module to measure the current pulled by a DC-motor. This is all fine and dandy.
Now I’d like to take this value and display it on one of those LED-bars
I’m using those modules not primarily for their controller they come with but because they’re easy to mount on a panel - anyway.
As I said, the current measuring works fine. I got it working up to a point where the current is measured and the desired range of LEDs are lit up.
Problem is - it only works ONCE. It’s not “looping” for a lack of a better word. Without the LED-part in the code, the ACS712 produces a steady amount of values posted in the serial monitor. As soon as I put in the code-bits for the LEDs and upload it, the current get’s measured once, I get one single value posted in the serial monitor and the LEDs light up accordingly to the value it measured. So, in principal it’s working, just not continuously.
I am very new to this and I’m quite impressed that I got this far already. But now I’ve hit a wall.
I am quite sure that I made something very basic very wrong.
Here’s the code. I’d be very happy if someone could point me in the right direction…
Thanks a lot guys!
/*
Measuring Current Using ACS712
*/
#include "LED_Bar.h"
LED_Bar myLED;
const int analogIn = A0;
int mVperAmp = 100; // use 100 for 20A Module and 66 for 30A Module
int RawValue= 0;
int ACSoffset = 2500;
double Voltage = 0;
double Amps = 0;
void setup(){
Serial.begin(9600);
}
void loop()
{
RawValue = analogRead(analogIn);
Voltage = (RawValue / 1024.0) * 5000; // Gets you mV
Amps = ((Voltage - ACSoffset) / mVperAmp);
//Serial.print("Raw Value = " ); // shows pre-scaled value
//Serial.print(RawValue);
//Serial.print("\t mV = "); // shows the voltage measured
//Serial.print(Voltage,3);
// the '3' after voltage allows you to display 3 digits after decimal point
Serial.print("\t Amps = "); // shows the voltage measured
Serial.println(Amps,3);
// the '3' after voltage allows you to display 3 digits after decimal point
delay(200);
if (Amps >2)
{for (int i=10;i<=10;)
myLED.set_LED_Range(i);}
if (Amps <1.99 && Amps >1)
{for (int i=5;i<=10;)
myLED.set_LED_Range(i);}
if (Amps <0.99 && Amps >0.1)
{for (int i=2;i<=10;)
myLED.set_LED_Range(i);}
}