ACS712 Sensor High/Low

I think I finally got it. The code below eliminates all LED flickering and I switched to tracking the voltage now each ACS712 5amp sensor instead of the current itself. As you can see I am monitoring 2 sensors and I will be adding at least 3 more. Please take a look at my code and see if there is any place I can “clean” it up or condense even more. I will be experimenting with millis() later as I will be adding other functions. Thanks for the help so far :slight_smile:

int ledPin1 = 12;              

int ledPin2 = 11;             
int ledPin3 = 10;           
int ledPin4 =  9;

int sensorPin1 = A0;         
int sensorPin2 = A1;

void setup() {
pinMode(ledPin1,    OUTPUT); 
pinMode(ledPin2,    OUTPUT); 
pinMode(ledPin3,    OUTPUT); 
pinMode(ledPin4,    OUTPUT); 
pinMode(sensorPin1, INPUT);   
pinMode(sensorPin2, INPUT);   

void loop() {
float average  = 0;
float average2 = 0;
for(int i = 0; i < 1000; i++) {
average  = average  + (.0264 * analogRead(sensorPin1) -13.51) / 1000;
average2 = average2 + (.0264 * analogRead(sensorPin2) -13.51) / 1000;

if (average < -0.01 || average > 0.12) { 
digitalWrite(ledPin1, HIGH);                   
digitalWrite(ledPin2, LOW);               
} else {
digitalWrite(ledPin1, LOW);               
digitalWrite(ledPin2, HIGH);     

if (average2 < -0.05 || average2 > 0.05) {
digitalWrite(ledPin3, HIGH);             
digitalWrite(ledPin4, LOW);               
} else {
digitalWrite(ledPin3, LOW);             
digitalWrite(ledPin4, HIGH);     


hi Pilot, if i didn’t understand you wrong you want to learn, and i am happy to help you so i suggest you to Serial.print average and average2 after the for because you will have a “bad” surprise. then you will understand on your own what to correct

i also see that you love to clean up your code, that is great, have a look here:

@PilotinControl, please stop cross-posting. Thread locked.