The following is more than 99% of you care to see, it is the code for my PLC. All the inputs and outputs were chosen randomly.
I have not included the program for the LEDs, as it is extensive and hard to follow. I have 50 LED's that simulate sunrise, sunset, moon phases and red for night viewing. Colors are amber, white, and red for sunup and down, and are stationary on both ends of the aquarium. There is a series of 10 4-up arrays spanning the length of the aquarium horizon that are blue and white for moon phases. The PLC times when each of the arrays come on and which bulbs are lit in each array. Phases are emulated by how many and what color are lit based on the date.
ORGANIZATION_BLOCK MAIN:OB1
TITLE=On_Off Aquarium Control
BEGIN
Network 1 // Check the time
// Read the clock on every scan and store the time starting at VB0. The hour:min:sec:msec start at VB3.
LD SM0.0
TODR VB0
Network 2 // Turn on Actinics @ 10:00 AM and 8:00 PM, and Turn Off @ 11:00 AM and 9:00 PM.
// If hour:min:sec:msec greater than or equal to 8 am and less than 8:30 am then turn lights on, else turn lights off. The 16# means the value is in hex. Time values are in BCD which is the same as hex for this app.
LDD>= VD3, 16#10000000
AD< VD3, 16#11000000
LDD>= VD3, 16#20000000
AD< VD3, 16#21000000
OLD
= Q0.0
Network 3 // Turn on Halide 1 at 11:00 AM and Turn off at 9:00 PM. Halides were separated due to power concerns on the outboard relays.
LDD>= VD3, 16#11000000
AD< VD3, 16#21000000
= Q0.1
Network 4 // Turn on Halide 2 at 11:00 AM and Turn off at 9:00 PM
LDD>= VD3, 16#11000000
AD< VD3, 16#21000000
= Q0.2
Network 5 // Calcium Reactor turns off if input at I2.7 goes high.
// If the pH level in the effluent goes below 6.8 the bubbler is shut off until the effluent pH reads 6.9.
LD I2.7
= Q0.3
Network 6 // The next three networks are the surge simulations, one powerhead on at a time from 7AM till 10PM.
// This network controls one of the three powerheads, on 8-9, 11-12, 2-3, 5-6, and 9-10. Off 10pm to 8am.
LDD>= VD3, 16#08000000
AD< VD3, 16#09000000
LDD>= VD3, 16#11000000
AD< VD3, 16#12000000
OLD
LDD>= VD3, 16#14000000
AD< VD3, 16#15000000
OLD
LDD>= VD3, 16#17000000
AD< VD3, 16#18000000
OLD
LDD>= VD3, 16#21000000
AD< VD3, 16#22000000
OLD
= Q0.6
Network 7 // This network controls another powerhead, on 7-8, 10-11, 1-2, 4-5, 8-9, off from 9PM till 7AM.
LDD>= VD3, 16#07000000
AD< VD3, 16#08000000
LDD>= VD3, 16#10000000
AD< VD3, 16#11000000
OLD
LDD>= VD3, 16#13000000
AD< VD3, 16#14000000
OLD
LDD>= VD3, 16#16000000
AD< VD3, 16#17000000
OLD
LDD>= VD3, 16#20000000
AD< VD3, 16#21000000
OLD
= Q0.5
Network 8 // This network on 9-10, 12-1, 3-4, 6-7, off 7PM ââ"šÂ¬Ã¢â‚¬Å“ 9AM.
LDD>= VD3, 16#09000000
AD< VD3, 16#10000000
LDD>= VD3, 16#12000000
AD< VD3, 16#13000000
OLD
LDD>= VD3, 16#15000000
AD< VD3, 16#16000000
OLD
LDD>= VD3, 16#18000000
AD< VD3, 16#19000000
OLD
= Q0.7
Network 9 // Thermometer turns off if input at I2.6 goes high. (See previous post for controlling circuit)
// If the temp in the tank is below 79degF the output Q0.9 is high, if above 79 degF I2.6 opens and shuts off output Q0.9 removing power from the heater(s).
LD I2.6
= Q0.9
Network 10 // Emergency main pump shutdown. When the moisture sensor outside the main tank senses any water the input to the PLC is driven low, diabling the pump. Simple circuit is available.
LD I2.5
= Q1.0
Network 11 // LED sequencing
.
END_ORGANIZATION_BLOCK