I have 8 outputs (relays), have 8 inputs (switch), each relay has corresponding switch or trigger.
When switch 4 closed it activates every relay except 4.
Here is the tricky part: Relays default state must be Open which is digitalWrite(relay, LOW); once corresponding switch is activated Arduino has to keep corresponding relay open and all others closed.
If at the same time another switch is activated it has to keep both active switches corresponding relays open and rest closed.
switch 4 triggeredrelay 4 open, relay 1-3 + 5-8 closed.
15 sec later... switch 8 triggeredkeep relay 4 open and relay 8 open, relays 1-7 closed
sometime later.. all switches offall relays open
I think it is important to keep relays open, once opened, otherwise if not taking that into the consideration in the loop it will just cycle these two.
so far I thought to use array but can't figure out how would I implement "not-this-one or everyone-but-this-one" logic
sketch.ino
#include "relays.h"
void setup() {
for( int i = 9; i < 17; i++ ) // initialize pin 9 - 16 for relays
{
pinMode(i, OUTPUT);
}
}
int relay[8] = { 9, 10, 11, 12, 13, 14, 15, 16 }; // array with relays pins
void loop() {
for( int i = 0; i < 4; i++ ) // this activates relays, CLOSE cycle
{
int relayNum = ( relay[i] );
digitalWrite( relayNum, HIGH );
delay(100);
}
srelays.h // I also could not figure out how to initiate all relays with function.
#ifndef RELAYS_H
#define RELAYS_H
//relays
const int relay1 = 9;
const int relay2 = 10;
const int relay3 = 11;
const int relay4 = 12;
const int relay5 = 13;
const int relay6 = 14;
const int relay7 = 15;
const int relay8 = 16;
#endif
How is your relay module powered?
Are you using a separate DC supply?
Can you show us a schematic diagram or picture?
The High/Low jumpers select how each relay responds its input signal. For example, High is "High Level Trigger" which means the relay is energized when the input signal is high.
It sounds like you need most of the relays energized, but if you connect to COM and NC, then the relays can be normally off. Then energizing a relay will turn off its load.
What us the purpose of the 8-relay module (what are you controlling)?
Exactly like this. All channels have high/low level trigger. All set to high. (energized once arduino applies power).
Relay is powered by 24v power supply. These relays power solenoids 12v, powered by separate PS. Ground tied together with 5v PS and Arduino ground. 5v supply used to power other sensors.
In the final build it is 2 of 8 relay modules. Controlling 2 way 5 position pneumatic solenoids valves which in turn move pneumatic cylinders, which move blast gate to Open or Close position for a dust collection system.
This might not be an option, I need to keep at least one gate open. They will control blast gates for dust collection system and one has to stay open for safety, it might destroy ductwork if all closed for a short period of time.
Thank you for pointing out, fixed it. I meant to say when switch 4 closed all relays except relay 4 are activated.
switch closed
well.. there will be few switches connected using pullup resistor connected to ground. However I am not sure yet, as I have to route them approximately 40` away and don't know if this is going to work properly. Will test with wires tomorrow.
And there will be current sensors with threshold values to activate corresponding relay.
I am trying to figure out the logic first and will plug "triggers" in it.
Yes, I meant to say relay module powered by 24v supply and solenoids by 12v. However I think to simplify things and get 12v relay modules for 12v solenoids.
Yes I installed flyback diodes, Arduino was going crazy without them, but survived.
And for extra safety I run separate V- to solenoids.
Low level trigger: digitalWrite(relayPin, LOW) will energize the relay
High level trigger: digitalWrite(relayPin, HIGH) will energize the relay
To take advantage of the built-in opto isolators, you'll need a separate supply for the Arduino. Need to see the schematic for your relay board to verify connections.
Yes, I have that option on my board. However I run wires from Arduino to relay modules ~30' and don't know how it will affect it by keeping it all energized.
However in my final design to activate Open Solenoid cycle:
The long control wires shouldn't be an issue if you take advantage of the opto isolation. Ideally, the optos would be at the Arduino end of the control wires, but using the ones on the relay module is still helpful.
Keeping the control wires energized isn't a power issue, its only about 10mA per wire (relay).
I will do the schematic to post here.
Right now I have:
12v PS powers Arduino and solenoids with some 4-20mA-toVolt converter.
24v PS powers relay module and another relay along with Volt-to-4-20mA converter and 4-20mA-to-Volt converter.
5v PS powers LCD screens, sensors.
V- from all power supplies tied together with Arduino V-. ( this was suggested to me to have good readings from sensors)
Do you suggest to get separate power supply for solenoids and isolate V+ and V- from the system?
I will have ~30' of wire running form Arduino to relay board, they supply 5v to activate relays. I figured voltage drop with small current even on 30` is minimal (0.089%) 4.9955v at the end with 18AWG and 4.982v with 0.36% drop with 24AWG(CAT6).