8 relays and 8 acs712 sensors and 8 solenoids, delay off time is not working

I'm not sure if this is a power issue or if it's a programming issue.
The program works correctly when no load is applied to it.
(Well most of the program ;), the current is not displaying via the serial monitor but the delay times work for the right amount of time).
However, when I hook up my 8 solenoids to each relay and 8 ACS712 sensors,
the Toff delay time only works for 1 second. It's supposed to be off for 15 minutes.

Schematic and code are below:

#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to

const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

/****************************************************************************/
unsigned long TOn = 1800000; // Adjust delay time in milliseconds to turn relay on/off (60,000 ms = 1 minute)
unsigned long TOff = 900000;

/* Measuring DC Current Using ACS712 */

double mVperAmp = 185; // use 185 for 5A Module, 100 for 20A Module, and 66 for 30A Module
float ACSoffset = 2423.6;

double RawValue1 = 0;
double RawValue2 = 0;
double RawValue3 = 0;
double RawValue4 = 0;
double RawValue5 = 0;
double RawValue6 = 0;
double RawValue7 = 0;
double RawValue8 = 0;

double V1 = 0;
double V2 = 0;
double V3 = 0;
double V4 = 0;
double V5 = 0;
double V6 = 0;
double V7 = 0;
double V8 = 0;

double Amps1 = 0;
double Amps2 = 0;
double Amps3 = 0;
double Amps4 = 0;
double Amps5 = 0;
double Amps6 = 0;
double Amps7 = 0;
double Amps8 = 0;

const int S1 = A0; // Analog input pin that sensor is attached to
const int S2 = A1;
const int S3 = A2;
const int S4 = A3;
const int S5 = A4;
const int S6 = A5;
const int S7 = A6;
const int S8 = A7;

void setup () {
  lcd.begin(16, 2);   // set up the LCD's number of columns and rows:
  lcd.setCursor(0, 0); // set printing position on lcd screen, currently that is column 0, row 0)
  Serial.begin(9600);

  DDRA = B11111111; // set PORTA (digital 22-29) to outputs

  int maxnumber = 2; // set cycle count

  for (int count = 0; count < maxnumber;) //Counter will stop counting after certain amount of cycles
  {
    PORTA = B00000000;
    delay(TOn); //delay between turning on each relay
    PORTA = B11111111;
    delay(TOff); //delay between turning off each relay

    RawValue1 = analogRead(S1);
    RawValue2 = analogRead(S2);
    RawValue3 = analogRead(S3);
    RawValue4 = analogRead(S4);
    RawValue5 = analogRead(S5);
    RawValue6 = analogRead(S6);
    RawValue7 = analogRead(S7);
    RawValue8 = analogRead(S8);

    V1 = (RawValue1 / 1023.0) * 5000; // Gets you mV
    V2 = (RawValue2 / 1023.0) * 5000;
    V3 = (RawValue3 / 1023.0) * 5000;
    V4 = (RawValue4 / 1023.0) * 5000;
    V5 = (RawValue5 / 1023.0) * 5000;
    V6 = (RawValue6 / 1023.0) * 5000;
    V7 = (RawValue7 / 1023.0) * 5000;
    V8 = (RawValue8 / 1023.0) * 5000;

    Amps1 = ((V1 - ACSoffset) / mVperAmp);
    Amps2 = ((V2 - ACSoffset) / mVperAmp);
    Amps3 = ((V3 - ACSoffset) / mVperAmp);
    Amps4 = ((V4 - ACSoffset) / mVperAmp);
    Amps5 = ((V5 - ACSoffset) / mVperAmp);
    Amps6 = ((V6 - ACSoffset) / mVperAmp);
    Amps7 = ((V7 - ACSoffset) / mVperAmp);
    Amps8 = ((V8 - ACSoffset) / mVperAmp);

    Serial.print("Amps1 = "); // shows the voltage measured
    Serial.println(Amps1, 3); // the '3' after voltage allows you to display 3 digits after decimal point

    Serial.print("Amps2 = ");
    Serial.println(Amps2, 3);

    Serial.print("Amps3 = ");
    Serial.println(Amps3, 3);

    Serial.print("Amps4 = ");
    Serial.println(Amps4, 3);

    Serial.print("Amps5 = ");
    Serial.println(Amps5, 3);

    Serial.print("Amps6 = ");
    Serial.println(Amps6, 3);

    Serial.print("Amps7 = ");
    Serial.println(Amps7, 3);

    Serial.print("Amps8 = ");
    Serial.println(Amps8, 3);

    Serial.println("");

    lcd.clear(); //clears lcd before incrementing to next number
    count++;
    lcd.print(count);
    lcd.setCursor(0, 1);
    lcd.println(TOn/60000);
    lcd.print("minutes");
  }
  DDRA = B00000000;
}

void loop() {
}

It's unusual to see loop() empty. Is that your intent?

Hi yes it is the for loop in void setup will cycle the count for a finite number of steps and then cycle stops

Thanks for the clue. :slight_smile:

Added this and now it's cycling properly:

void loop(void) { 
}

It has cycled properly so far just waiting to see if it will remain off for the period stated in the program.

knightridar:
Thanks for the clue. :slight_smile:

Well, it wasn't a clue in the sense that I knew what would happen - it's just that normally the main body of code that accomplishes some task is placed in loop(). setup()'s more of an initialization thing, setting I/O pins, opening communication with serial devices, and whatnot.

I guess I spoke too soon.

:frowning:

The code worked with 1 solenoid, but not 8 solenoids.
So there’s potential that the previous code could have worked with 1 solenoid as well.

Could it possibly be a power related issue?
The power supply is 24V,21A (max), 500 watts.

I am powering the arduino and relay with 24 to 12v dc converters, and 24 to 5 volt dc converters respectively.

The solenoids are 24V DC, and power ranges from 10-12 watts on each one.
That would mean they have a max. amperage of .5 amps.

Attached is the latest code (I’ve changed it so I get more data shown on the LCD screen).

#include <serLCD.h>
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to

const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

/****************************************************************************/
unsigned long TOn = 1800000; // Adjust delay time in milliseconds to turn relay on/off (60,000 ms = 1 minute)
unsigned long TOff = 900000;

/* Measuring DC Current Using ACS712 */

double mVperAmp = 185; // use 185 for 5A Module, 100 for 20A Module, and 66 for 30A Module
float ACSoffset = 2423.6;

double RawValue1 = 0;
double RawValue2 = 0;
double RawValue3 = 0;
double RawValue4 = 0;
double RawValue5 = 0;
double RawValue6 = 0;
double RawValue7 = 0;
double RawValue8 = 0;

double V1 = 0;
double V2 = 0;
double V3 = 0;
double V4 = 0;
double V5 = 0;
double V6 = 0;
double V7 = 0;
double V8 = 0;

double Amps1 = 0;
double Amps2 = 0;
double Amps3 = 0;
double Amps4 = 0;
double Amps5 = 0;
double Amps6 = 0;
double Amps7 = 0;
double Amps8 = 0;

const int S1 = A0; // Analog input pin that sensor is attached to
const int S2 = A1;
const int S3 = A2;
const int S4 = A3;
const int S5 = A4;
const int S6 = A5;
const int S7 = A6;
const int S8 = A7;

void setup () {
  lcd.begin(16, 2);   // set up the LCD's number of columns and rows:
  lcd.setCursor(0, 0); // set printing position on lcd screen, currently that is column 0, row 0)
  Serial.begin(9600);

  lcd.print("TOn:");
  lcd.print(TOn/60000);
  lcd.print("m");
  lcd.print(",");
  lcd.print("TOff:");
  lcd.print(TOff/60000);
  lcd.print("m");

  DDRA = B11111111; // set PORTA (digital 22-29) to outputs

  int maxnumber = 2; // 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.print("Cycle Count:");
    lcd.print(count);

    PORTA = B00000000;
    delay(TOn); //delay between turning on each relay
    PORTA = B11111111;
    delay(TOff); //delay between turning off each relay

    RawValue1 = analogRead(S1);
    RawValue2 = analogRead(S2);
    RawValue3 = analogRead(S3);
    RawValue4 = analogRead(S4);
    RawValue5 = analogRead(S5);
    RawValue6 = analogRead(S6);
    RawValue7 = analogRead(S7);
    RawValue8 = analogRead(S8);

    V1 = (RawValue1 / 1023.0) * 5000; // Gets you mV
    V2 = (RawValue2 / 1023.0) * 5000;
    V3 = (RawValue3 / 1023.0) * 5000;
    V4 = (RawValue4 / 1023.0) * 5000;
    V5 = (RawValue5 / 1023.0) * 5000;
    V6 = (RawValue6 / 1023.0) * 5000;
    V7 = (RawValue7 / 1023.0) * 5000;
    V8 = (RawValue8 / 1023.0) * 5000;

    Amps1 = ((V1 - ACSoffset) / mVperAmp);
    Amps2 = ((V2 - ACSoffset) / mVperAmp);
    Amps3 = ((V3 - ACSoffset) / mVperAmp);
    Amps4 = ((V4 - ACSoffset) / mVperAmp);
    Amps5 = ((V5 - ACSoffset) / mVperAmp);
    Amps6 = ((V6 - ACSoffset) / mVperAmp);
    Amps7 = ((V7 - ACSoffset) / mVperAmp);
    Amps8 = ((V8 - ACSoffset) / mVperAmp);

    Serial.print("Amps1 = "); // shows the voltage measured
    Serial.println(Amps1, 3); // the '3' after voltage allows you to display 3 digits after decimal point

    Serial.print("Amps2 = ");
    Serial.println(Amps2, 3);

    Serial.print("Amps3 = ");
    Serial.println(Amps3, 3);

    Serial.print("Amps4 = ");
    Serial.println(Amps4, 3);

    Serial.print("Amps5 = ");
    Serial.println(Amps5, 3);

    Serial.print("Amps6 = ");
    Serial.println(Amps6, 3);

    Serial.print("Amps7 = ");
    Serial.println(Amps7, 3);

    Serial.print("Amps8 = ");
    Serial.println(Amps8, 3);

    Serial.println("");
  }
  DDRA = B00000000;
}

void loop(void) {
}

Something I'm not sure about is if the relay is designed for DC loads.

p/n:
Songle SRD-05VDC-SL-C

it's on an 8 relay module

My impression is that it is.

5v relay.PNG

That relay should have no problem driving a 500mA solenoid. Have you tried running without the solenoids just to make sure the code performs as desired?

This is how I read the code: In the program proper, all relays are on for one minute then off for one minute then readings are taken. If this much is correct, how will the current readings have valid values when the solenoids are off?

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you post a picture of your project so we can see your component layout?

Thanks… Tom… :slight_smile:

@dougp

I have tried to run it without solenoids.
That's is when it works right. The relay stays off for the stated time period.
It works with 1 solenoid.
When I plugged all 8 in, none of the relays stayed off for the required amount of time.
They go off for about a second and turn back on.

Your thoughts about the code being able to read the current values are correct.
When i start the serial monitor nothing is read. I will have to reposition or rewrite the code.

I have an updated version of the code where I am making sure the solenoids stay on and off for the amount of time that I need them to stay on and off.

#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to

const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

/****************************************************************************/
unsigned long TOn = 1800000; // delay time in milliseconds to turn relay on/off (60,000 ms = 1 minute), therefore relay is on for 30 minutes
unsigned long TOff = 900000; // relay is off for 15 minutes

void setup () {
  lcd.begin(16, 2);   // set up the LCD's number of columns and rows: 16 columns, 2 rows
  lcd.setCursor(0, 0); // set printing position on lcd screen, currently that is column 0, row 0)
  Serial.begin(9600);

  lcd.print("On:");
  lcd.print(TOn/60000);
  lcd.print("m");
  lcd.print(",");
  lcd.print("Off:");
  lcd.print(TOff/60000);
  lcd.print("m");

  DDRA = B11111111; // set PORTA (digital 22-29) to outputs

  int maxnumber = 2; // 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.print("Cycle Count:");
    lcd.print(count);

    PORTA = B00000000;
    delay(TOn); //delay between turning on each relay
    PORTA = B11111111;
    delay(TOff); //delay between turning off each relay
  }
  DDRA = B00000000;
}

void loop(void) {
}

@TomGeorge my circuit schematic is in the first post.

Here are actual pictures of the setup:
The circuit is a mess, I am going to update the wiring connections to put into a nice controls box.

One thing I did try to do is read current via a multimeter at the end of the white quick disconnect connectors (+/- terminals) while a solenoid was plugged into them. I was about to measure the amount of current going into the solenoid and I connected the leads into the 10A and common plugs of the fluke multimeter I had.

When I made contact with the quick disconnect connections the power supply almost shut down and there was a spark at the quick disconnect (that quick disconnect is now scorched black on the inside but it still works). Did I end up shorting it (they are +/- connections)? I don't get how I did?

knightridar:
The power supply is 24V,21A (max), 500 watts.

I am powering the arduino and relay with 24 to 12v dc converters, and 24 to 5 volt dc converters respectively.

The solenoids are 24V DC, and power ranges from 10-12 watts on each one.
That would mean they have a max. amperage of .5 amps.

Eight solenoids at 500mA per (if that's what they actually draw) is 4A. That should be no problem for a 21A supply. Just to know, I'd power up one each of the devices fed by the 5V converter and measure the current they each draw, then you'll have some numbers to calculate total current draw on the converter when all are on. What is the wattage on the two DC-DC converters?

I know things can get messy in the early stages but I'd think about putting some kind of temporary insulator, maybe a piece of paperboard, like from a cereal box, between the relays / ACS712s / terminal strips. It's too easy for parts to get together in ways you don't want them to.

I'd also suggest to you to stage the relay turn-ons. That is, instead of energizing all eight at once and creating a big power supply spike (transient voltage), space out and reduce the power supply spikes by putting a short delay, maybe half a second between each turn-on.

Hi,

@TomGeorge my circuit schematic is in the first post.

Sorry NO, that is a diagram of how you havde connected your power supply.

We need a circuit diagram that has;

  • pin labels
  • component labels
  • terminal labels
  • wiring for power supply
  • wiring for signals, signal and output devices.

Tom... :slight_smile:

@dougp

I'll try turning them on one by one to see if that fixes anything.

The 24v to 12v dc converter is rated for 5A/60W.
Its sole purpose is to power the arduino mega2560

The 24v to 5v dc converter is rated for 5A/25W.
It's powering the D1 robot lcd shield.
Also it powers the 8 relay module.
(I read somewhere on the forum that this model of songle relays consume 72 mA each, so that's near ~576mA total)
Not sure how true the 72mA draw is.

@TomGeorge

:slight_smile: I see what you mean makes total sense.
I'll put one together.

I hooked up diodes at the leads where the solenoids are connected and that solved the issue.
Seems it was voltage spikes from the solenoids.