Arduino programming novice

Hi all,

I'm a novice at arduino programming and can do the basics.

What i'm trying to write is a programme to energise three 240V solenoids in series.
So one solenoids is "on" for 60 seconds then off, the second solenoid "on" for 60 seconds then off and then the third. Then repeat all over again.

The arduino is set up via 8 module relay.

The code i have written at the moments switches all solenoids at the same time.

Any help would be appreciated.

joe

We can't see your code.

Don't forget the code tags.

joeian:
The arduino is set up via 8 module relay.

For completeness, always a good idea to provide a link to some info on the hardware.

And a diagram of how you've wired the whole shebang together.

Hi,

this a simple sketch of the time regime of the solenoids.

joeian:
Hi,

this a simple sketch of the time regime of the solenoids.

That does NOT explain what the sketch actually does. That does NOT explain what you expect the code to do. That does NOT explain what your problem is.

And, "this" doesn't refer to anything, so the whole statement is semantically null.

Dealing with 240V needs extra care for safety.

Are you sure you have read and understand rules for insulation, cabling etc?
The relay may be can handle 240V, are your wires and connections capable for it?

What i'm trying to write is a programme to energise three 240V solenoids in series.
So one solenoids is "on" for 60 seconds then off, the second solenoid "on" for 60 seconds then off and then the third. Then repeat all over again.

I don't see any code in this thread, but if the full requirement is described above then the solution is simple.

const byte relayPins[] = {3, 5, 6};
byte pinIndex = 0;
const unsigned int sixtySeconds = 60000;

void setup()
{
  Serial.begin(115200);
  for (int pin = 0; pin < 3; pin++)
  {
    pinMode(relayPins[pin], OUTPUT);
    digitalWrite(relayPins[pin], HIGH); //all off at start
  }
  Serial.println(sixtySeconds);
}

void loop()
{
  digitalWrite(relayPins[pinIndex], LOW); //turn on current relay
  delay(sixtySeconds);
  digitalWrite(relayPins[pinIndex], HIGH); //turn off current relay
  pinIndex++;  //ready for the next relay
  pinIndex = pinIndex % 3;  //reset index to zero if at the end of the array
}

I await with interest to hear whether the requirements have been fully described

Sorry had problem uploading sketch for some reason. I have also added photo of rig i made.

try again

solenoid time regime.pdf (18.7 KB)

thanks for all your help so far, much appreciated.

joeian:
Sorry had problem uploading sketch for some reason. I have also added photo of rig i made.

Just put the sketch in a post as text, tagged like this [code] sketch goes here [/code]

Here's the pic for others' convenience:

Not 100% clear from the pic (diagram would be better) but looks like that is one of those relay boards with the JD jumper, and it's still in place, top right of board? The jumper's presence and the black ground wire, would indicate the relay coil is powered from the Arduino.

If I'm reading the photo correctly (please confirm) you may want to rethink that:

  • With the ground between the relays and the Arduino, you have compromised the opto-isolation
  • Those relays draw about 70mA each, and presumably you have used an 8-relay board to allow for up to 8 relays to be in play? That will be too much current, and you shouldn't use your Arduino as a power supply.

Here's a better way to connect those relay modules, with a separate power supply to the relays and the jumper off:

D0upWXs_d.jpg

Thanks elvon_blunden,

The photo shows the first test which is a 5 second pulse test of the solenoid on/off.

The second test I will only be using 3 of the 8 relays to open and close 3 electro mechanical solenoids for 60 seconds.
I will also put snubber diodes across the solenoid to protect the circuit
There is a jumper on the relay board.
Can I use the same supply for the Arduino to supply the relay board? or do I use separate supply.

thanks again

joeian:
Can I use the same supply for the Arduino to supply the relay board? or do I use separate supply.

I'm not sure, others may be able to answer.

I do vaguely recall (or perhaps imagined) reading that power supplies to inductors (like a relay coil) should not also supply other stuff, due to possible interference, but rather wait for someone who really knows to reply.

While your style and tidiness of construction is commendable - if this is for any production styie installation - I'd replace those jumpers with a screw-terminal shield.

Pushing wires into the Arduino headers will be reliable for about 6-months in most environments.

One question: Why not use low-voltage (coil) solenoids driven directly from a MOSFET shield (a solenoid is just a variation of a relay) - atm, you're driving a 'relay' with a 'relay'.
It's not wrong, but in most cases redundant - and you have more switched mains 'floating' around than necessary - not really a good thing.

Hi UKHeliBob,

Thanks for code it works perfectly. Out of interest for future reference if I wanted to change the time regime for instance 1st solenoid 60 sec on/off, 2nd solenoid 120 sec on/off and 3rd solenoid 180 sec on/off and so on, how would I change the code.

Thanks again for your help.

Hi UKHeliBob,

Thanks for code it works perfectly. Out of interest for future reference if I wanted to change the time regime for instance 1st solenoid 60 sec on/off, 2nd solenoid 120 sec on/off and 3rd solenoid 180 sec on/off and so on, how would I change the code.

Thanks again for your help.

37 minutes - maybe he’s still asleep ?

joeian:
Hi UKHeliBob,

Thanks for code it works perfectly. Out of interest for future reference if I wanted to change the time regime for instance 1st solenoid 60 sec on/off, 2nd solenoid 120 sec on/off and 3rd solenoid 180 sec on/off and so on, how would I change the code.

Thanks again for your help.

If you mean that relay 1 should be on for 60 seconds, then off followed by relay 2 on for 120 seconds then of then relay 3 on for 180 seconds then off and repeat you would need to change the delay period each time you change to the next LED. The neatest way would be to declare an array of unsigned long variables containing the three periods corresponding to the three relay pins like this

const unsigned long periods[] = {60000, 120000, 180000};

Then later in the code use the array in the delay() function like this

delay(periods[pinIndex]);