Power shutoff automation in Factorio
How to automate the shutoff of your coal power plants in Factorio.
This post is part of the Factorio series.
Our goal
In Factorio, when you start building solar panels, you will quickly start to resent the coal power plants constantly burning fuel when they shouldn’t be. Let’s assume you have accumulators to store the power your solar panels provide, and that you have enough to get you through the night. Most of the time, at least.
The accumulators provide the current charge percentage as a signal, so like the good Factorio engineer you are, you connect your accumulator to your offshore pump and set it to enable only when the accumulators are below some charge level. Luckily all accumulators in a power network always have the same amount of charge.
This works, but this results in the power level hovering around 30%, with the steam engines flickering on and off as the accumulators charge and discharge.
We can do better. We can have the offshore pump turn on, and then have it run until it reaches a certain percentage—say 80%. We can already turn the offshore pump on, but how do we decide when to shut it off again?
Factorio offers several combinators to work with basic
signal logic. So what we could do is turn the pump on and then use an AND
gate to turn the pump
off when the pump is on and the accumulator charge is over 80%.
Unfortunately, neither the offshore pump, the boiler nor the steam turbines provide us with a signal1 to tell us whether they’re on or off.
Flip-flops
Enter flip-flops. Flip-flops, also
known as latches, are electronic circuits with two possible stable states, 1
or 0
, on or off.
Being stable means they ‘remember’ their state, which is why these are building blocks of computer
memory. This is, in effect, a 1-bit memory cell.
Please note that I do not have any electrical engineering background, and as such I will be talking about these from a programming perspective, not an electrical one. With that out of the way:
Flip-flops have two inputs, and one output. The inputs are called ‘set’ and ‘reset’. When a signal is sent to the set input, the input turns on if it wasn’t already. If you then send a signal to the reset input, it turns off again.
For a visual explanation by one of my favourite YouTubers Sebastian Lague, please watch this timestamped section of the video called How Do Computers Remember?.
Implementing a flip-flop in Factorio
With Factorio’s combinators, we have all the tools to build our own flip-flop. We’re setting out to remember whether the offshore pump is providing water to our coal generator, to be able to determine when to shut it off again.
The accumulator is sending a signal to two arithmetic combinators.
The accumulator signal is sent to a decider combinator that outputs 1 when that signal is
<
30%. This is ourset
signal.The accumulator signal is also sent to a decider combinator that outputs 1 when the signal is
>=
80%. This is ourreset
signal.This arithmetic combinator performs a boolean
OR
(|
) on theset
signal and the output of this flip-flop. This combination is what causes the steady state, as you will see.This decider combinator takes the reset signal and performs a boolean
NOT
(!=
) on the signal. This way, if no signal is sent to thereset
input, we send a1
and vice versa.This final decider combinator performs a boolean
AND
on the output of theset
and the (NOT
ed)reset
signal. As long as the signal isset
andNOT reset
, we output1
.This
1
is also sent back to theOR
combinator3
, which will keep the flip-flop in the1
state.
The final step is to send the output of that final decider combinator—the output of our flip-flop—to our offshore pump, and voilà! We have successfully buffered our signal!
Update (2024-05-10):
When reading through the Circuit network cookbook, I found out that you can make a flip-flop using just one decider combinator. By running a signal wire from the output back to the input, you can create a flip-flop that remembers its state.
The only downside of this approach is that the output signal (in this case S
) is always the same
as the input signal, rather than allowing you to choose any signal you want.
Factorio series
- Power shutoff automation in Factorio
- Advanced Kovarex enrichment process