Hi,
I'm doing a project on load control. I have designed a system to turn ON four loads (L1, L2, L3, L4) sequentially at 4 second interval. Then used ACS712 (30A) module to monitor the total current of the loads. When the current is greater than 1.6, I want to turn OFF L4. The code attached here is the code I have been able to write and upload to the board. However, I am finding it difficult in turning OFF L4 when result (total current) is greater than 1.6.
For the hardware description: I connected the output of the Arduino to drive 25A solid state relays and I am able to measure the current accurately using the serial monitor.
Please I need suggestions on how to make this work out , thanks.
/*
Code for load control system
*/
// constants won't change. They're used here to set pin numbers:
const int L1 = 2; // Load 1
const int L2 = 3; // Load 2
const int L3 = 4; // Load 3
const int L4 = 5; // Load 4
const int sensorIn = A0;
int mVperAmp = 66; // use 100 for 20A Module and 66 for 30A Module
double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;
void setup() {
Serial.begin(9600);
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(L3, OUTPUT);
pinMode(L4, OUTPUT);
digitalWrite(L1, HIGH);
delay(4000);
digitalWrite(L2, HIGH);
delay(4000);
digitalWrite(L3, HIGH);
delay(4000);
digitalWrite(L4, HIGH);
delay(4000);
}
void loop() {
float result;
if (result > 1.6)
{
digitalWrite(L1, HIGH);
digitalWrite(L2, HIGH);
digitalWrite(L3, HIGH);
digitalWrite(L4, LOW);
}
Voltage = getVPP();
VRMS = (Voltage / 2.0) * 0.707;
AmpsRMS = (VRMS * 1000) / mVperAmp;
Serial.print(AmpsRMS);
Serial.println(" Amps RMS");
}
float getVPP()
{
float result;
int readValue; //value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1024; // store min value here
uint32_t start_time = millis();
while ((millis() - start_time) < 1000) //sample for 1 Sec
{
readValue = analogRead(sensorIn);
// see if you have a new maxValue
if (readValue > maxValue)
{
/*record the maximum sensor value*/
maxValue = readValue;
}
if (readValue < minValue)
{
/*record the maximum sensor value*/
minValue = readValue;
}
}
// Subtract min from max
result = ((maxValue - minValue) * 5.0) / 1024.0;
return result;
}