Multiple pins at once

Please help me finish my project.Struggling with cods..
I need to set multiple output pins at exactly the same time.
So, pin 6 has to open and close in loop together with pin 7,8,9,10.
In practice the ping 7,8,9,10 will control hydraulic directional solenoid valve.
The pin 6 will control relief valve.
Thanks for help

void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);

}

void loop() {
pinMode(7, OUTPUT);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
delay(5000);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
delay(5000);
pinMode(8, OUTPUT);
digitalWrite(6, LOW);
digitalWrite(8, LOW);
delay(5000);
digitalWrite(6, HIGH);
digitalWrite(8, HIGH);
delay(10000);
pinMode(9, OUTPUT);
digitalWrite(6, LOW);
digitalWrite(9, LOW);
delay(2000);
digitalWrite(6, HIGH);
digitalWrite(9, HIGH);
delay(600);
pinMode(10, OUTPUT);
digitalWrite(6, LOW);
digitalWrite(10, LOW);
delay(2000);
digitalWrite(6, HIGH);
digitalWrite(10, HIGH);
delay(600);

static unsigned long count = 0;
count++;
Serial.println(count);

}

(deleted)

If you post your code as described in the how to use this forum sticky, more members will read it.

Just guessing from your question, you need to look at Arduino Port Manipulation.

To change timing is not a problem.
I can't manage how set up two output pins at exactly the same time. So relife valve (pin6) will open with directional valves

v1.ino (863 Bytes)

(deleted)

If you can group the pins as either 2-7, 8-13, or A0-A5 (the analog pins can be used as digital pins), that would put all your outputs on a single port and allow for simultaneous control. Otherwise, you will need one or two direct port instructions to control the pins, depending on which ports they are on.

I don't really see a problem with using digitalWrite() with hydraulic valves, unless you are using some very special and very expensive valves they will have a reaction time much greater than a few nanoseconds (that's millionths of a second).

Unrelated to your timing question, but the pinMode() instructions should be in setup() not loop(). You also neglected to set pin 6 as output.

First declair all the pins as OUTPUT! Your Arduino might have a malfunction. You didn't declair all the pins as OUTPUT and you are using the digitalWrite() fucntion. That could cause a malfunction in the board. Declair all that pins as OUTPUT in the setup function.

Perhaps also start with all pins in a “legal” start state?

[
void setup() {
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);

  digitalWrite(6,  LOW);
  digitalWrite(7,  LOW);
  digitalWrite(8, HIGH); 
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);

}

Otherwise they are floating inputs at startup (without pinMode) or all low (with pinMode and without digitalWrite).

Thank you for trying to help me.
I just testing new schematic on simulator tinkercad.com and circuit board and it still not working for me. (schematic is attached)
To keep simpler I just have led lights (schematic is attached)
Still same problem. The pin 6 has to switch on /off together with pin 10,9,8,7
Probably I have to insert few more relay to do that function -option B
Thanks

void setup()
{
  pinMode(6, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop()
{
  digitalWrite(6, LOW);
  digitalWrite(10, LOW);
  delay(2000); // Wait for 2000 millisecond(s)
  digitalWrite(6, HIGH);
  digitalWrite(10, HIGH);
  delay(2000); // Wait for 2000 millisecond(s)
  digitalWrite(6, LOW);
  digitalWrite(9, LOW);
  delay(2000); // Wait for 2000 millisecond(s)
  digitalWrite(6, HIGH);
  digitalWrite(9, HIGH);
  delay(2000); // Wait for 2000 millisecond(s)
  digitalWrite(6, LOW);
  digitalWrite(8, LOW);
  delay(2000); // Wait for 2000 millisecond(s)
  digitalWrite(6, HIGH);
  digitalWrite(8, HIGH);
  delay(2000); // Wait for 2000 millisecond(s)
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  delay(2000); // Wait for 2000 millisecond(s)
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  delay(2000); // Wait for 2000 millisecond(s)
}

still not working

More details needed of the problem

I'd like to have cod which is able to switch on and off 2 led together in loop sequence please.
step 1 switch on LED (PIN6 and 10 for 2 sec)
step 2 switch off LED (Pin6 and 10for 2 sec)
step 3 switch on LED (PIN6 and 9 for 2 sec)
step 4 switch off LED (Pin6 and 9for 2 sec)
step 5 switch on LED (PIN6 and 8 for 2 sec)
step 6 switch off LED (Pin6 and 8for 2 sec)
step 7 switch on LED (PIN6 and 7 for 2 sec)
step 8 switch off LED (Pin6 and 7for 2 sec)
and continue in loop so on..

OP's pictures:

Don't see any reason the simulation would not be working correctly, other than you have the circuit wired to switch the LEDs on when HIGH, while the relay board generally will switch on when LOW.

The actual hardware will most likely not work, the relay board cannot reliably be powered from the 5v pin of the arduino, and the relays switching on and off tend to produce voltage spikes on the power supply leads, which can cause the arduino to malfunction.

const byte ledPins[] = {2, 10, 9, 8, 7};
const byte NUMBER_OF_LEDS = sizeof(ledPins);
const unsigned long period = 2000;
byte ledIndex = 1;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  for (int p = 0; p < NUMBER_OF_LEDS; p++)
  {
    pinMode(ledPins[p], OUTPUT);
    digitalWrite(ledPins[p], LOW); //all LEDs off
  }
}

void loop()
{
  digitalWrite(ledPins[0], HIGH); //on
  digitalWrite(ledPins[ledIndex], HIGH);
  delay(period);
  digitalWrite(ledPins[0], LOW);  //off
  digitalWrite(ledPins[ledIndex], LOW);
  delay(period);
  ledIndex++;
  if (ledIndex >= 5)
  {
    ledIndex = 1;
  }
}

Hi Lads.
I spend all day testing cods and this is cod works for me the best for some reason. (see below)
Tomorrow going to connect controller to 15 kwt hydraulic power-pack and see what is happen.
I think I have to upgrade with limit switches also.
The arduino looks to me very chaotic sometimes.
Thanks for help

void setup() {
 // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  

}

void loop()
{
  pinMode(6, OUTPUT);
  pinMode(10, OUTPUT);
  digitalWrite(6, LOW);
  digitalWrite(10, LOW);
  delay(1000); // Wait for 2000 millisecond(s)
  digitalWrite(6, HIGH);
  digitalWrite(10, HIGH);
  delay(1000); // Wait for 2000 millisecond(s)
  pinMode(9, OUTPUT);
  digitalWrite(6, LOW);
  digitalWrite(9, LOW);
  delay(4000); // Wait for 2000 millisecond(s)
  digitalWrite(6, HIGH);
  digitalWrite(9, HIGH);
  delay(4000); // Wait for 2000 millisecond(s)
  pinMode(8, OUTPUT);
  digitalWrite(6, LOW);
  digitalWrite(8, LOW);
  delay(4000); // Wait for 2000 millisecond(s)
  digitalWrite(6, HIGH);
  digitalWrite(8, HIGH);
  delay(4000); // Wait for 2000 millisecond(s)
  pinMode(7, OUTPUT);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  delay(4000); // Wait for 2000 millisecond(s)
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  delay(4000); // Wait for 2000 millisecond(s)
  static unsigned long count = 0;
  count++;
  Serial.println(count);

}
  delay(4000); // Wait for 2000 millisecond(s)

Have your requirements changed ?

Have you tried:

void loop()
{
  for (int i = 7; i < 11; i++)
  {
    digitalWrite(i, HIGH);
    write6();
    delay(2000);
    digitalWrite(i, LOW);
    write6();
    delay(2000);
  }
}
void write6()
{
  digitalWrite(6, digitalRead(7) or digitalRead(8) or digitalRead(9) or digitalRead(10));
}