Part I · Chapter 2

Switches & Chains

A flashlight is just a battery, a bulb, and a thumb switch. Arrange a few switches cleverly, and a simple loop of wire starts making decisions all by itself.

If you unscrew a flashlight and look inside, the magic turns out to be wonderfully plain. A battery pushes electrical energy out of one end, along a thin metal path, through a tiny glowing wire inside the bulb, and back into the other end of the battery. The moment the loop is complete, the lamp lights up. Break the loop anywhere, and the room goes dark.

A switch is nothing more than a tiny drawbridge in that wire. Lower the bridge, and electricity crosses. Lift the bridge, and the road is broken. On its own, one switch just obeys your thumb. The surprise begins the moment you add a second switch.

Three Ways to Wire a Decision

First, try placing two switches in a single line, one right after the other along the same wire. Now electricity has to cross the first drawbridge and the second drawbridge to reach the lamp. If either bridge is lifted, the journey stops. Without a brain or a single instruction written down, this simple loop enforces a strict rule: both switches must be closed.

Next, try splitting the wire into two side-by-side lanes, placing one switch on the upper lane and the other on the lower lane, before joining them back together near the lamp. Now electricity has a choice of roads. Close the top switch and the lamp glows. Close the bottom switch instead, and the lamp still glows. Close both, and it glows just the same. This arrangement enforces a generous rule: either switch is enough.

There is a third trick, and it is the cleverest of all. Imagine a spring-loaded switch that naturally rests closed—so when you leave it alone, the lamp shines brightly. The moment you press it down, you push the bridge open, snapping the lamp off. We can call this the flipper: whatever you do to it, the lamp gives you the exact opposite.

Test all three wiring setups below. Click the switches directly on the diagram (or use the buttons underneath) and watch how the glowing path changes.

Interactive Lab 1 The Decision Switchboard

Choose a wiring layout, then flip switches A and B to see when electricity reaches the lamp.

Lamp: Dark
Both switches are open, so the road to the lamp is broken. Try closing Switch A, then Switch B.
Quiet footnote: You just built the three fundamental building blocks of every computer chip! Putting switches in a line makes an AND gate, placing them side by side makes an OR gate, and the spring-loaded opposite-maker is a NOT gate.

Dominoes Made of Wire

So far, your own finger has been flipping every switch. That is fine for a bedside lamp, but a real thinking machine needs switches that can flip other switches all by themselves.

Luckily, electricity has a handy side effect: when it flows through a tiny coil of wire, that coil turns into a temporary magnet. Place a metal switch lever right next to the coil, and the moment power arrives in the first wire, the magnet tugs the second switch closed from a distance—no finger required.

Think of it like a line of standing dominoes. The output of one decision can become the input to the next. An “either” circuit can feed straight into a “both” circuit, which can also listen to a “flipper” circuit. Suddenly, a handful of humble switches can enforce surprisingly thoughtful everyday rules.

Suppose you want an automatic cat door that keeps your pet safe. You only want it to unlock when it is daytime, AND when either your cat is waiting at the door or you press the manual override button, AND when it is not raining outside. Flip the four real-world sensors below and watch the signals cascade through the chain of switches to unlock—or latch—the cat door.

Interactive Lab 2 The Automated Cat-Door Decision

Watch simple yes-or-no sensors flow through chained switches to decide whether the cat door unlocks.

Door Rule: Open only if Daytime AND (Cat at Door OR Override) AND NOT Raining.
The cat door is UNLOCKED! It is daytime, your cat is waiting, and the weather is dry.
Quiet footnote: A switch pulled by a tiny electromagnet is called a relay. Early room-sized computers clacked loudly with thousands of them. Modern machines shrink that same idea down to microscopic silent switches called transistors—billions of them packed onto a fingernail-sized chip.

Pause and admire what just happened. Without a single word of English inside the wires, a chain of simple yes-or-no switches evaluated four real-world conditions and made the exact right decision every time. Next, we will discover how rows of these simple on-and-off lamps can count, store numbers, and even paint pictures.

What You Just Built