Tutorial:Circuit network cookbook
Foreword
This page provides examples of simple circuit network designs and some not so simple designs that others can use, combine and modify. They are designed to be as easy to understand as possible. To see the settings of combinators without opening them, the option "Show combinator settings in "Alt-mode"" in the Interface/Alt-mode settings has to be checked and "Alt-mode" has to be turned on.
Lamp showing chest content condition
This is the simplest possible use of circuit-network. A lamp is light depending on the number of goods (in this example empty barrels) in a chest.
Setting up circuit connection
- The lamp is connected to the chest.
- The lamp is set to light if the chest contain less than 10 empty barrels.
To set the light condition
- Open the lamp (left click on it).
- Set the input to barrels.
- Set the operator to < (less than).
- Set the constant number:
- Left click on the constant number
- Move the slider until 10 is shown, or edit the value box directly.
- Press set.
Depending on the condition you set, the lamp may light if the chest is empty, or if it contains the required quantity of items.
The drawback with this scenario is that the lamp has a white light , and is therefore difficult to differentiate from an ordinary lamp at night.
Oil Setups
Light Oil Cracking
- This circuit provides balanced light oil and petroleum gas production by cracking excess light oil into gas.
- The pump is connected to the storage tank by a red wire.
- The pump has an enabled condition set to Light Oil > 20000.
Heavy Oil Cracking
- This circuit extends on the previous circuit by adding optional heavy oil cracking to provide lubricant etc.
- The pump has an enabled condition set to Heavy oil > 20000 .
Alternative Setup for Cracking and Lubricant Production
This setup compares different fluid levels to each other instead of checking fixed values. It offers some guarantees such as petroleum gas being produced when you have light oil to spare, and light oil not being cracked when you have plenty of petroleum gas, and similar rules for heavy oil cracking and lubricant production.
It takes 4 steps:
1. Have a fluid tank for heavy oil, light oil, petroleum gas, and lubricant. For each fluid, make sure to connect the tank via pipes to every location where the fluid is being produced or consumed.
2. For each chemical plant (or each row of them, if you use rows) add a pump to the non-water fluid input pipe to make it possible to block the flow. Note: Alternatively, the blocking pumps could be added to the chemical plant output pipes, but there is no need to add pumps to both inputs and outputs.
3. Connect every pump and every fluid tank to a single circuit network of red (or green) wire. The resulting circuit network will know about the fluid level in every storage tank and pass this information to every pump.
4. For each connected pump set the circuit “enable condition” to "[input fluid] > [output fluid]" , for its respective chemical plant recipe. E.g. set "heavy oil > light oil" for the heavy oil cracking input pump, set "heavy oil > lubricant" for the lubricant production input pump, and set "light oil > petroleum gas" for the light oil cracking input pump.
Done! Now all the pumps will move to equalize the fluid levels to each other. This will prevent fluid system deadlocks where you have plenty of one fluid but you are unable to make any of the other.
Lights
Conditional Lights
- In this circuit we connect a series of lamps to a storage tank.
- By setting different conditions on each lamp we can build an indicator strip.
- The Enabled condition of the first lamp is Petroleum gas > 100.
- The others light up when gas is greater than 200, 300, 400 and 500 respectively.
In this scenario you can connect the storage tank to the lamps directly.
Colored Lights
- To light a lamp with a color rather than white, you need an intermediate device like an arithmetic combinator that can send a color signal.
Instead of directly connect the the lamp and the Storage tank you need:
1 Add the arithmetic combinator.
2 Connect the storage tank with the input of the arithmetic combinator.
3 Connect the output of the arithmetic combinator with the lamp.
4 Set up the arithmetic combinator:
4.1 Setting the input to petroleum Gas + 0 (the constant 0 not the signal 0)
4.2 Set the output to the pink signal (on the bottom row of the last tab of signals.)
5 Set up the lamp:
5.1 Select the "Use colors" check box on the lamp.
5.2 Set the condition to the pink signal, and what value you want (i.e. > 100)
Misc
Multiple Storages
- If you connect multiple chests to a pole, the pole displays the sum of items in all the chests.
- This also works with storage tanks and roboports.
Constant Combinator
- With a constant combinator you can generate any signals you may need.
- In this example we have generated a signal of 50 Laser turrets and 200 Piercing round magazine.
- Constant combinators are not of much use on their own but we shall use them later.
Constant Combinator Signs (Words)
- You can use constant combinators to make signs, just set the letter signals in the combinator, each combinator can display 2 characters side by side.
- Note that to see these letters, Alt-mode must be on and the Interface setting “Show combinator settings in “Alt-Mode”” must also be enabled.
Constant Combinator Signs (Managing Belts)
- Somewhat similar to the previous example, constant combinator signals can be used with belts to help indicate what items should be on which belts. This is extremely useful when sharing blueprints, as it's possible for blueprints to be shared albeit with no indication on which items are meant for which belts.
Memory Cell / Counter
- Basic memory cell that counts all the items moved by the inserter
- The fast inserter is connected to BOTH ends of the arithmetic combinator.
- If the fast inserter hasn't picked anything up this tick the input to the Arithmetic combinator is the same as and output and hence the values are persisted.
- When the fast inserter does pick something up its value is added to the output from the previous tick thus incrementing that item.
Inserters
Limit items placed into a chest
- The inserter is connected to the wooden chest using a red wire.
- The inserter's enabled condition is Advanced Circuit < 10.
- In reality this means the inserter may place more than 10 Advanced circuits in the chest because it could pick up to 3 at once due to stack size bonuses.
- This effect can be even greater with Stack inserters because of their large carrying capacity.
- This technique still gives far greater control than limiting the inventory on the chest.
Balanced chest insert
Goal: Load n chests with approximately the same number of items.
- Place n chests and n inserters.
- Place 1 arithmetic combinator
- Set the combinator to take Each (yellow star) and divide by the negative number of chests. ie −n.
- Connect all chests to each other and to the input of the combinator using red wire.
- Connect all inserters to each other and to the output of the combinator using red wire.
- Connect each inserter to the box it inserts into with green wire.
- Set the enable condition on each inserter to be Everything (red star) < 0.
The combinator calculates the average number of items in the chests, and makes it negative. Each inserter gets the amount in the chest it is inserting to and adds the negative average, ie it calculates how many more than the average it has in its chest. Thus if that number is negative, it has less than the average in the chest and it enables.
Due to inserter stack bonus the count is not exact. If a precise count is needed, set the inserter stack size to 1.
Keeping outpost stocked with specified items
- This circuit keeps a storage chest at an outpost stocked with customized levels of different items.
- For example you could keep an outpost stocked with 50 laser turrets and 200 piercing magazine rounds but not have to worry about it being over filled.
- The storage chest is attached to the input of the arithmetic combinator (left side in the picture) with a red wire.
- Another couple of red wires join the output of the arithmetic combinator (right side) to the constant combinator and to the stack filter inserter.
- The arithmetic combinator multiplies each input value (from the storage chest) by -1.
- Finally the filter stack inserter's mode of operation is set to Set filters.
- So the input to the stack filter inserter is <constant combinator> - <storage chest contents> and the filter is set to filter for the first item by inventory order.
Balanced Solar panel / Accumulator Production
- This circuit balances production of solar panels and accumulators to a desired ratio in my case 24:20.
- The first arithmetic combinator takes the number of accumulators in the chest and multiplies it by 24.
- The second arithmetic combinator takes the output of the first combinator and divides it by 20.
- This gives us the number of accumulators that we can directly compare to the number of Solar panels in both inserters.
- If the number of accumulators is greater we enable the Solar panels inserter, if the number of Solar panels is greater we enable the accumulators inserter.
- However, if they are equal, neither machine does anything. So we add a single accumulator to one of the inserters using a constant combinator and a wire of the other color, therefore breaking the deadlock.
Sushi Belts
Reading Belt Design
- Six belts in a row are connected with Red wire and set to Read belts contents and Hold
- This red wire is then connected to the inserters that insert onto the belt.
- Read hand contents is unselected for all inserters.
- Mode of operation is set to Enable/Disable on all inserters.
- The first inserter is enabled when Science pack 1 = 0
- The other inserters are set similarly for the other science packs.
Memory Cell Design
- This circuit counts the number of items of each type on a looping belt by counting the numbers that are added and removed from the belt by inserters.
- Each inserter that takes items off the belt is connected together with Red wire and each of these inserters is set to Mode of operation none, Read hand content selected and Hand read mode pulse.
- These inserters are connected to the input of the left arithmetic combinator.
- The left arithmetic combinator multiples each input by -1 and outputs it to each.
- The right arithmetic combinator is a memory cell as above.
- The memory cell's input is connected to the inserters that are placing items on the belt and the output of the left arithmetic combinator.
- The inserters that place items onto the belt have an enabled condition that is based on the number of items on the belt.
Power
Backup steam power
- The steam engines are not directly connected to the power network. They are connected to the power network through a power switch.
- The power switch is connected to one of the accumulators in the main network.
- The power switch turns on when A < 10. That is when the accumulators are less than 10% full.
Optimal usage of fuel for nuclear power
Unlike the normal steam power that adjusts fuel usage based on power usage, the nuclear reactors spend fuel in fixed units of time. To be exact, the consumption of 1 fuel cell takes exactly 200 seconds.
Combined with the fact that creating the nuclear fuel cells are time consuming and expensive to create, it is therefore beneficial to optimize their use to match the actual consumed power.
First example
The above picture shows a setup with 4 reactors, that spend only 1 fuel cell each whenever steam runs low.
Note: The GUI in the image above has been altered to make sure all important info fits within the image size.
There are a few elements in this setup:
- Storage tank that provides the steam signal. You should only read from one storage tank, and it should have pipe connections to all your other steam storage tanks.
- Chests containing uranium fuel cells for the reactor.
- Output inserters that take empty fuel cells from the reactor. This is connected to the storage tank to listen for the steam signal, and to the chests to listen for the uranium fuel cell signal. If the steam level is low and there are uranium fuel cells available, it removes the empty fuel cells from the reactor and sends an empty fuel cell signal (since "Read hand contents" is checked).
- Input inserters that put uranium fuel cells into the reactor. This is connected to the output inserters and listens for the empty fuel cell signal. The "Override stack size" is set to 1, so that it only inserts 1 fuel cell at a time.
Since this design uses empty fuel cells as a signal to fill the reactor, you need to manually insert 1 uranium fuel cell into the reactor to get it started.
Second example
A simpler setup can be made with inserters that drop a single uranium fuel cell in each reactor when the steam reaches a certain level.
Here, two inserters feeding two reactors are connected to a steam storage tank and are set to be turned on when it reaches 2K.
The only drawback is that two cells are placed in the reactor (one when the steam volume drops to 2K and another when it is back up to that level), but this does not matter, as with only two cells the temperature cannot rise to 1000°C, so no energy is wasted.
Prioritize usage of uranium towards nuclear fuel production
Because a continuous supply of nuclear fuel is critical to maintaining a nuclear reactor, the circuit network can be used to set up a system where uranium-235 and uranium-238 are conserved for the production of nuclear fuel before other uses.
Using a splitter, divert the two types of uranium onto two parallel conveyors, with an inserter positioned to gather uranium from each conveyor (a long handed inserter will be needed for the far belt). Each of these inserters deposits their load into a container, from which two more inserters deliver the contents to an assembly machine making nuclear fuel. An inserter delivers the produced fuel to a third container, from which inserter(s) delivers the fuel to your nuclear reactor. Wire the two inserters gathering from the conveyors to the container each of them is delivering to, and to the tile of conveyor immediately after the tile the inserter is gathering from. Set each inserter's enable condition to "less than or equal to X amount of uranium", using the appropriate type of uranium the inserter is gathering and X being the number of reserve uranium desired (optimally, one uranium-235 and nineteen uranium-238, the amount needed to produce nuclear fuel; the amount may be increased if a greater stockpile is desired). Set each conveyor's enable condition to "greater than or equal to X amount of uranium" in the same manner. Finally, connect the inserters delivering uranium to the assembly machine up to the container the assembly machine is delivering nuclear fuel to, and set each of their enable conditions to "nuclear fuel = 0 (the enable condition can be set to "less than or equal to X amount of nuclear fuel" if a larger stockpile is desired).
This set-up accomplishes the following:
- When there is sufficient nuclear fuel and uranium stockpiled, the inserters will deactivate and the conveyors activate, allowing the uranium to continue down the conveyors to other facilities.
- When the nuclear fuel stockpile hits zero (or decreases below the desired amount), the inserters delivering to the assembly machine will activate and deliver uranium to resume production of nuclear fuel until quota is reached again.
- When there is not enough uranium stockpiled to produce a batch of nuclear fuel, the inserters gathering uranium will activate and and resume gathering uranium until they reach their quota. The conveyors carrying uranium will stop past the inserters, cutting off other facilities from that type of uranium until its respective inserter reaches quota.
- The assembly machine will only be provided with uranium when the stockpile of nuclear fuel hits zero (or decreases below the desired amount), preventing over-production of nuclear fuel and thus over-consumption of uranium.
Railway network
Set train routing
The circuit network can be used to allow deeper micromanagement of trains by disable/enabling train stops. By connecting the stop to the storage container(s) unloading from the train and setting the train stop to be disabled when a desired resource in them is above a certain quantity, any train with this stop on their route will ignore it and continue to their next stop. For example, a train stop where iron ore is delivered can be disabled when the total amount of iron ore in the containers is above 1,000; when the stockpiled ore drops below 1,000, the stop will be enabled and trains will be permitted to stop there. Conversely, train stops where a resource is picked up can be set to be disabled in the same manner, so that trains will ignore the stop until the stop has enough of the specified resource to be delivered.
Together, these can be used to direct multiple trains to the same stops and better optimize their delivery; they will only go to a stop to pick up cargo when there is a certain amount ready, and will only unload at stops which have fallen below a certain amount in their stockpile. Further control over deliveries can be granted by integrating the inserters loading and unloading from the trains and/or the storage containers into the circuit network to enable or disable them depending on the container's contents, so that specific amounts of resources are picked up or unloaded.
This system also means that if no stop on a train's route requires the specified resource, the train will wait until needed. This can be useful for supplies like ammunition being delivered to defensive outposts with turrets; if the turrets have a sufficient stockpile of ammunition their stop will be disabled and the train delivering ammunition will not travel there until more ammunition is needed, preventing rail lines from being clogged and fuel from being consumed.
Player safety
The circuit network can be used to ensure the player's safety when crossing train tracks so they do not get hit. Place gates at designated crossing areas and connect an adjacent wall to rail signals near the gate. Set the gate to "read sensor" and the signal to "close signal" with the condition being the signal the gate sends out being "1". This means that when the gate is closed, the signal will be green and trains can pass freely, but when the player approaches the gate and it opens for them, the train signal will be turned red and trains will be stopped until the player clears the area.
Alternatively, this system can be reversed - by setting the gate to "open gate" and the train signal set to "read signal", the gate will remain open normally and will close when a train is approaching, preventing the player from crossing until it is safe.
In lieu of gates, the player can connect a programmable speaker to the train signals to broadcast a warning siren when a train is approaching the area.
Latches
RS latch - single decider version
This discussion on the Factorio forums starts with the common 2 decider RS latch version, but the thread goes on to explain why this single decider version is better. In the thread, the latch is described as an SR latch. However, when both inputs are true, the latch will reset, so it is an RS latch.
Backup steam example
This example will turn on the steam generator when the Accumulator charge drops to 20%, but will "latch" (remember) the On state until the accumulator is charged to 90%.
Latching is used to introduce hysteresis and avoid the power switch rapidly cycling on and off (as the accumulator falls to 19%, charges to 20%, falls to 19% and so on).
Accumulator outputs the current charge level as % on signal
First decider outputs "Set" ( = 1) if Accumulator is less than 20%.
Second decider outputs "Reset" ( = 1) once Accumulator is more than 90% full.
RS Latch configuration
The central decider and green feedback wire is the actual RS Latch.
It latches the Set signal until the Reset signal is received (and vice-versa).
NB: the latch expects binary inputs ( & must be 0 or 1) - this is why the previous two deciders are required.
When both inputs are true, the reset signal takes priority and the latch resets. This means it is an RS latch instead of an SR latch.
The Power switch isolates the generator from the rest of the factory until = 1
RS latch
- This should be familiar to anyone with any background in electronics.
- The signal is set and reset with the constant combinators on the left by setting an A=1 signal.
- The latch "remembers" which one was last set and the light stays on until another signal is received.
Usage of RS latch
- Here is an example of how you could use an RS latch.
- The two extra decider combinators provide the set and reset conditions.
- Petroleum gas < 50 and petroleum gas > 100.
Belt only latch
- To make it work, 3 pieces of raw wood must be placed on the inside lane of the belt.
- It will have higher latency than the combinator version, but in most situations you will not notice the difference.
Displays
Numerical Display
- Each digit is driven by its own green wire, that wire holds 15 signals, one for each lamp used in the digit.
- constant combinators are used to define which lamp should light up for each value.
Black and White Grid Display
- Each row has its own red wire connection and within that row each light has a numbered signal 0-9.
- We turn each light on by just setting or clearing the relevant signal.
Multicolor Display by DaveMcW
- To understand how this works, you first need to understand how color lights choose which color to light up when there are multiple colored signals.
- The lamp will light up with the colored signal that is greater than zero and earliest in this list: red, green, blue, yellow, pink, cyan, white.
- We have a red wire per column, that wire has each of the colored signals on it at different values and a numbered signal for each row.
- There is a arithmetic combinator for each cell that subtracts the "row" value from each of the colored signals.
- And this enables us to choose the color for each cell.
- Simple!