Skip to content

Solenoid Bank

A solenoid bank will often be used in industrial automation to control multiple pneumatic actuators. Some vendors provide a single word as the output for controlling multiple solenoids, where each bit in the word corresponds to a specific solenoid. This example will expand upon the Digital Output example to demonstrate how each bit can be injected into separate Digital Output components.

Step 1: Declare a variable that matches the hardware datatype

First, declare a variable that matches the hardware datatype for the solenoid bank. This is typically a WORD or DWORD, depending on the number of solenoids. Because we are using BIT level access we must pass the individual bits into a BOOLEAN variable before injecting them into the Digital Output component.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
PROGRAM MAIN
VAR
    SolenoidBankVar at %Q*: WORD; 
    Solenoid1Var : BOOL; // Must be declared before injected into the component
    Solenoid2Var : BOOL; // Must be declared before injected into the component
    Solenoid3Var : BOOL; // Must be declared before injected into the component
    Solenoid4Var : BOOL; // Must be declared before injected into the component
    Solenoid1 : DigitalOutput(Output := Solenoid1Var);
    Solenoid2 : DigitalOutput(Output := Solenoid2Var); 
    Solenoid3 : DigitalOutput(Output := Solenoid3Var);
    Solenoid4 : DigitalOutput(Output := Solenoid4Var);
    // Add more solenoids as needed
END_VAR

Step 2: Control individual solenoids

You can now control each solenoid individually through its respective Digital Output component.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
    // Energize Solenoid 1
    Solenoid1.On := TRUE;

    // De-energize Solenoid 2
    Solenoid2.On := FALSE;

    // Energize Solenoid 3
    Solenoid3.On := TRUE;

    // De-energize Solenoid 4
    Solenoid4.On := FALSE;

    // Update the solenoid bank variable to reflect the current states
    SolenoidBankVar.0 := Solenoid1Var;
    SolenoidBankVar.1 := Solenoid2Var;
    SolenoidBankVar.2 := Solenoid3Var;
    SolenoidBankVar.3 := Solenoid4Var;

Step 3: Complete Example

Here is the complete example of a solenoid bank using the Digital Output component.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
PROGRAM MAIN
VAR
    SolenoidBankVar at %Q*: WORD; 
    Solenoid1Var : BOOL; // Must be declared before injected into the component
    Solenoid2Var : BOOL; // Must be declared before injected into the component
    Solenoid3Var : BOOL; // Must be declared before injected into the component
    Solenoid4Var : BOOL; // Must be declared before injected into the component
    Solenoid1 : DigitalOutput(Output := Solenoid1Var);
    Solenoid2 : DigitalOutput(Output := Solenoid2Var); 
    Solenoid3 : DigitalOutput(Output := Solenoid3Var);
    Solenoid4 : DigitalOutput(Output := Solenoid4Var);

    EnergizeSolenoid1   : BOOL;
    DenergizeSolenoid1  : BOOL;
    EnergizeSolenoid2   : BOOL;
    DenergizeSolenoid2  : BOOL;
END_VAR

// Control Solenoid 1 On
IF EnergizeSolenoid1 THEN
    EnergizeSolenoid1 := FALSE;
    Solenoid1.On := TRUE;
END_IF

// Control Solenoid 1 Off
IF DenergizeSolenoid1 THEN
    DenergizeSolenoid1 := FALSE;
    Solenoid1.On := FALSE;
END_IF

// Control Solenoid 2 On
IF EnergizeSolenoid2 THEN
    EnergizeSolenoid2 := FALSE;
    Solenoid2.On := TRUE;

END_IF

// Control Solenoid 2 Off
IF DenergizeSolenoid2 THEN
    DenergizeSolenoid2 := FALSE;
    Solenoid2.On := FALSE;
END_IF

// Update the solenoid bank variable to reflect the current states
SolenoidBankVar.0 := Solenoid1Var;
SolenoidBankVar.1 := Solenoid2Var;
SolenoidBankVar.2 := Solenoid3Var;
SolenoidBankVar.3 := Solenoid4Var;

END_PROGRAM

Conclusion

By using the Digital Output component for each solenoid in the bank, you can easily manage and control multiple solenoids while adhering to the SOLID principles. This approach promotes reusability and maintainability in your automation projects.