Before we go any further, is it okay to change your code to this:
/*
testing sketch for the ACS712 current sensor module
PARAMETERS:
vcc: 4.5 - 5.5 v
icc: 13 - 15 ma
zero current output voltage: vcc × 0.5 (2.5 v)
SENSITIVITY:
+- 5 a: 185 mv/a (+-13513 mamper @ 5v)
+-20 a: 100 mv/a (+-25000 mamper @ 5v)
+-30 a: 66 mv/a (+-37878 mamper @ 5v)
theoretical resolution for 5v analog pin:
(arduino resolution: 4.8828 mv)
5a: 26.4ma
20a: 48.8ma
30a: 74.0ma
error @ 25c: +-1.5 %
*/
#include <LiquidCrystal.h>
#include <Streaming.h>
int mVperAmp = 185; // 185 (5A), 100 (20A), 66 (30A) mvperAmp value used, using ACS712 sensors
int testVoltage = 24;
const int numReadings = 64;
const byte AIN[] = {0, A1, A2, A3, A4, A5, A6, A7, A8};
uint16_t raw_value[9] = {0};
float acs_offset[] = {0, 2414.467, 2424.242, 2399.804, 2409.580, 2419.355, 2414.467, 2429.130, 2409.580};
float voltage[9] = {0};
float amps[9] = {0};
float power[9] = {0};
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // initialize library and associate LCD pins with Arduino pins
//unsigned long TOn = 3000; // delay time to turn relay on/off (60,000 ms = 1 minute)
uint16_t TOn = 3000; // delay time to turn relay on/off (60,000 ms = 1 minute)
uint16_t qton = 750;
uint16_t TOff = 3000;
//unsigned long TOff = 3000;
void setup ()
{
lcd.begin(16, 2); // LCD's columns and rows: 16 columns, 2 rows
lcd.setCursor(0, 0); // Printing position on lcd screen is column 0, row 0
Serial.begin(9600);
lcd << "On:" << (TOn/60000) << "m, Off:" << (TOff/60000) << "m" ;
DDRA = 0B11111111; // set PORTA (digital 22-29) to outputs
int maxnumber = 600; // set cycle count
for (int count = 0; count < maxnumber;) //Counter will stop counting after certain amount of cycles
{
lcd.setCursor(0, 1); //clears lcd before incrementing to next number
count++;
lcd << "Cycle Count:" << count;
PORTA = 0B00000000;
for (byte i = 1; i <= 4; i++)
{
ReadCurrent();
delay(qton);
}
ReadCurrent();
PORTA = 0B11111111;
delay(TOff); //relay off time
}
DDRA = 0B00000000;
}
void loop(void)
{
}
void ReadCurrent()
{
for (int x = 0; x < numReadings; x++) // 64 analogue readings for averaging
{
for (byte i = 1; i <= 8; i++) (raw_value[i] += analogRead(AIN[i]));
delay(2); // wait 2 milliseconds before the next loop, for the analog-to-digital converter to settle, after the last reading
}
for (byte i = 1; i <= 8; i++) (voltage[i] = (((raw_value[i] / numReadings) / 1023) * 5000));
for (byte i = 1; i <= 8; i++) (amps[i] = ((acs_offset[i] - voltage[i]) / mVperAmp));
for (byte i = 1; i <= 8; i++) (power[i] = (amps[i] * testVoltage));
for (byte i = 1; i <= 8; i++)
{
Serial << "Raw value " << i << " = " << (raw_value[i] / numReadings) << "\tmV " << i << " = " << _FLOAT(voltage[i],3) << "\tAmps " << i << " = ";
if (amps[i] > 0) Serial.print(" ");
Serial << _FLOAT(amps[i],3) << "\tPower1 = " << _FLOAT(power[i], 3) << "\n";
raw_value[i] = 0;
}
Serial.println();
//delay(1000);
}
It's 2590 bytes lighter (code) and uses ~300 less RAM plus its a lot easier to read (I think).