Module 03

Building Circuits

You draw each circuit in KiCad, build and test it on a breadboard with your multimeter, then put a Raspberry Pi in control: switching a load, driving a relay, reading a sensor, running on a battery.

01 Why it matters
In 1942, held in a Japanese camp in Borneo, Lieutenant Colonel R.G. Wells and fellow prisoners built a working radio receiver almost entirely from what they could scrounge.45 They made the resistors from string soaked in burnt cinnamon bark, the capacitors from the foil lining of a tea chest, and the wire insulation from flour caked into palm oil, and they ran it off a battery of pharmacy chemicals and zinc trouser buttons. The only parts they could not improvise were the vacuum tube and the headset, and the headset had to be smuggled in.4 They built a working device because they understood how circuits work.
02 What you build
You set up a Raspberry Pi Zero 2 W as the controller and build four circuits for it: a MOSFET switch, a battery supply (9 V regulated down to 5 volts, and 3.7 V boosted up to 5), a relay driven by the Pi, and a motion sensor read by the Pi.
03 Overview
Eight units: drawing and prototyping first, batteries second, then the four builds, with the Pi coming online in Build 3. A field exercise and a test close it out. You need the multimeter and schematic reading from Module 02; radio and cellular come later.
On this page
01

Draw it, then prototype it

Tools to get
Wire strippers and flush cutters for stripping and trimming wire endsAny brand
Safety glasses clipped leads flyAny brand
Breadboard and jumper wires the prototype stageAny brand
Multimeter the one from Module 02Reused
KiCad on your laptop the drawing stage, on the laptop you hardened in Module 00Free
Parts, by build
Raspberry Pi Zero 2 WH, microSD the controller board, 40-pin header pre-fitted; Builds 2 through 4Specific
FQP30N06L power MOSFET or a logic-level substitute proven at your bench; Build 1Specific
10k trimmer potentiometer Build 1Any brand
9V batteries and snap clips Builds 1 and 2Any brand
L7805 regulator with 0.33 and 0.1 µF capacitors Build 2Any brand
3.7V LiPo cell, 450 mAh, JST plug Build 2Any brand
TP4056 charger board Build 2; buy it with the pin headers fittedAny brand
Mini slide switch, rated 0.5 A or better Build 2; on the cell's positive lineAny brand
SX1308 boost module Build 2; buy it with the pin headers fittedAny brand
1-channel relay module, SRD-05VDC-SL-C high/low trigger; Build 3Specific
9V siren Builds 1 and 3 and the field exerciseAny brand
HC-SR501 PIR motion sensor Build 4Specific

Draw it. Every build starts as a KiCad schematic, drawn on the laptop you hardened in Module 00, with the same symbols you learned to read in Module 02. The drawing is itself the first test: KiCad's electrical rules check automatically detects incorrect and missing connections, flagging an unconnected pin or a power input that no output pin drives, before you've picked up a single part.7 KiCad can go further and lay out a printed circuit board for fabrication, but that is beyond this course. Here, the schematic is the map you build from.

Prototype it. A solderless breadboard lets you assemble a circuit with no soldering at all, so you can try your designs before committing them to solder.1 Beneath its holes sit short metal rows called terminal strips: any two wires or leads plugged into the same strip are electrically connected.6 A gap called the bridge runs down the middle and splits the board in two, so a chip can straddle it with each leg landing on its own terminal strip.6 Along each edge run the power rails, one marked with a red line and the other with a blue line, carrying the supply the length of the board.6

To build the circuit on a breadboard, place the real parts so their connections match the schematic, node for node. Give each leg of a part its own strip, because putting both legs into one strip shorts the part out.6 Then prove the build with the multimeter in two passes:

  1. Before power, continuity. Set your multimeter to continuity mode. Touch the probes to any two points the schematic shows as connected, and the meter should beep. Touch two points from different parts of the circuit that the schematic does not connect, and the meter should stay silent.
  2. Under power, voltage. Set your multimeter to DC volts. Put the black probe on ground, then touch the red probe to each point the schematic labels with a voltage, and check that the meter reads that value.

Make it permanent. A breadboard is temporary, since its wires tend to fall out after a while.1 Once a circuit works, transfer it to perfboard or stripboard, a perforated board you cut to size and solder the parts onto: stripboard carries conductive strips underneath, while perfboard has an isolated pad at each hole.1 Positions don't need to match the schematic, only the connections do.

Check on learning
You plug both legs of a resistor into the same five-hole terminal strip. What happens?
You move a working circuit onto perfboard, but the parts end up in different positions than the schematic. Is that a problem?
02

Batteries and power

The basic unit of a battery is the cell; a battery, strictly speaking, is "a group of two or more connected voltaic cells,"8 though in everyday use the word covers both. A cell you use once and throw away is a primary cell, and one you can recharge is a secondary cell.8

A cell has three ratings that matter here: voltage, capacity, and C-rate. Voltage is how hard the cell pushes current; capacity, in milliamp-hours, is how much charge the cell holds.

A 3000 mAh cell can supply 3000 mA, or equivalently 3 A, for one hour.1 Divide the capacity by the current your circuit draws to estimate the runtime: a circuit drawing only 30 mA should run for about 100 hours on that same cell (3000/30).1 Treat that as an estimate, not a guarantee: the harder you draw, the less of the rated capacity you actually get, so build in margin. Real cells typically deliver only about 25 percent of their theoretical capacity (the capacity computed from the raw materials alone); the mAh rating printed on the label already accounts for this and is the number you plan with.9

The third rating, the C-rate, sets how hard you may pull at all. One C means draining the whole capacity in one hour, so a cell rated at 2 Ah with a maximum continuous discharge of 4 A has a C-rate of 2.10 Pulling past that rating overheats the cell, hot enough in some cases to catch fire.1 The calculator below does the runtime arithmetic for you.

The voltage printed on the label is not what you get under load; the reason is internal resistance. A multimeter across a fresh cell reads its full voltage, but the moment current flows, that resistance drops the terminal voltage the cell delivers.8

A fresh 1.5-volt AA settles near 1.3 V under load and still delivers useful power down to about 1 V, so a four-cell pack can sit anywhere between 4 and 6 volts.1 A 9-volt battery delivers between 7 and 10 volts depending on its chemistry and wear.6 Lithium cells sag under load too, and on an RC LiPo you watch that sag closely: the cell should never drop below 3.0 V while in use.10

Cells combine two ways. Wired in series, positive to negative, the voltages add while the current stays the same, so four 1.5-volt cells in series give a total of 6 volts.8 Capacity does not add in series: four 1.5-volt, 2000 mAh cells in series still hold 2000 mAh, just at 6 volts instead of 1.5.1 Parallel is the reverse: the voltage stays the same and the capacities add.8 Parallel comes with one hard rule: match the cells' voltages before you join them, or the fuller cell will try to dump a large amount of energy at once into the less charged one, and that can end in fire.10

Two 1.5 volt, 2000 mAh cells in series and in parallel: series adds the voltages, and parallel adds the capacities.
Two 1.5 volt cells wired in series give 3.0 volts at the same 2000 mAh; the same cells in parallel give 1.5 volts at 4000 mAh.

Each chemistry is a trade-off. Alkaline cells are the cheapest option: they hold 1.5 volts and keep their charge for years, losing only about 4 percent of it annually, but as primary cells, they must be discarded once dead.9 NiMH rechargeables hold about 75 watt-hours per kilogram, less than an alkaline cell but rechargeable hundreds of times, though they self-discharge faster in storage as temperature and charge level rise.9 Lead-acid stores about 25 Wh/kg, the least of the four, and is heavy for the energy it holds, but it remains the most robust of the technologies, with the least chance of fire or explosion.1 9 That robustness is why lead-acid is still the standard for starter batteries in most cars. Lithium-ion, including its soft-pouch form, stores far more than any of the others, about 150 Wh/kg at 3.6 volts nominal and 4.2 volts full, and survives more than a thousand charge cycles.9

That density is why a lithium cell powers a Raspberry Pi in the field: a Pi requires a steady 5 volts, and a sensor often requires 3.3, so the cell feeds a regulator or a boost converter rather than the board directly.

One term needs a correction before you shop for cells: what the market sells as "LiPo" is not a separate chemistry, but a lithium-ion cell packed in a soft pouch. A true lithium-polymer cell, one with a solid polymer electrolyte, never became a commercial product.10 The high-discharge "RC LiPo" sold for hobby aircraft is a specific cobalt chemistry, and the warning about it is blunt: these cells are dangerous and can catch fire if you don't follow proper charging and discharging procedures.10

Charging a lithium cell takes more than applying voltage. A proper charger runs in two phases, first pushing a steady current until the cell reaches its 4.2 V limit, then holding that voltage while the current tapers off.10 9 In practice that means charging at 4.2 V with the current capped, usually around 0.5 A, and charging slowly, since most lithium cells should not be charged faster than 0.5 C.1 10 The TP4056 board you meet in Build 2 is a single-cell charger that runs this whole sequence for you.

Treat lithium with respect. A lithium cell holds a lot of energy in a thin package and fails badly. Past about 130 °C, a cell risks thermal runaway, and a runaway cell can pass 500 °C and vent flammable gas.10 Discharge one below about 3 V per cell and you can permanently damage it; a scavenged cell may lack the built-in cut-off that normally prevents this.1 A dead short is just as dangerous: even a small screw or staple across the terminals can cause a short circuit with disastrous results.10 Never trickle-charge a LiPo, never charge one below 0 °C, and never charge cells in series without a balanced charger that watches each one.1 Put an inline fuse on the battery lead so a short blows the fuse, not the cell.
Check on learning
You wire four 1.5 volt, 2000 mAh cells in series. What do you get?
A circuit draws a steady 50 mA from a 2000 mAh cell. Roughly how long does it run?
03

Build 1: power MOSFET switch

This build is the payload switch, the circuit that turns a load on and off from a small control signal. The problem is always the same: a small control signal has to switch a load far heavier than it can drive. A logic pin lives at 3.3 or 5 volts and supplies a few milliamps, while the payload runs on its own supply, at voltages the pin cannot touch and currents up to amps. The answer is a power MOSFET, a transistor used as a switch: it's controlled by voltage rather than current, so the gate turns it on once its voltage passes a threshold, typically around 2 V.1

The part here is the FQP30N06L, a 30 amp N-channel MOSFET with a 2.0 volt gate threshold1 (its datasheet gives the threshold as a 1.0 to 2.5 volt window).3 It is a logic-level MOSFET, meaning its gate threshold is low enough for a microcontroller's digital output pins to drive it directly.1 The FQP30N06L is out of production and listed as obsolete by distributors, with remaining stock thinning.3 If you substitute another logic-level MOSFET, such as the IRLB8721, check the gate threshold on its datasheet, then confirm the swap works with this build's meter checks.

The payload here is the 9 volt siren, which also serves as the relay's load in Build 3 and the alarm in the field exercise. In this build, a knob turns it on. The book's reference circuit runs on a 6 volt (4×AA) pack, and we use a 9 volt block to match the supply standard for these builds. A potentiometer is an adjustable resistor: its two ends span a fixed resistance, and a third terminal, the wiper, taps off a voltage between them that you set by turning the knob. A trimmer is the small board-mounted kind. A 10k trimmer potentiometer sets the gate voltage, the FQP30N06L switches the current, and the siren is the load.

The KiCad schematic: the trimmer's wiper sets the gate voltage on Q1, the siren sits between the positive rail and the drain, and the source returns to ground. It passed the electrical rules check.
Schematic: a 9 volt battery, a 10k trimmer potentiometer feeding the gate of an N-channel MOSFET Q1, a 9 volt siren between the positive rail and the drain, and the source to ground.
The same circuit on a breadboard, hole for hole. Red carries +9 volts, blue and black carry ground, green runs the wiper to the gate, and orange runs the drain to the siren.
Breadboard build of the MOSFET switch: a 9 volt block powers the rails, a 10k trimmer potentiometer feeds the gate of a TO-220 MOSFET, the drain drives a 9 volt piezo siren whose other lead returns to the positive rail, and the source returns to ground.

Build it in this order.

  1. Seat Q1 across three rows. Facing the labeled side, the FQP30N06L's pins are gate, drain, source, left to right.3
  2. Seat RV1, the 10k trimmer. Its two outer legs go to the +9 volt rail and the ground rail; its center wiper runs to Q1's gate.
  3. Wire the siren between the +9 volt rail and Q1's drain: its red lead goes to the rail and its black lead to the drain.3
  4. Run Q1's source to the ground rail.
  5. Connect the 9 volt block last, and match its leads to the rails' polarity marks.

Prove it. Turn the trimmer across its range with your multimeter on the gate: below the threshold the siren is silent, and just past it the sound snaps on at full volume. A datasheet-grounded simulation of the circuit puts numbers on that snap. The siren is a light load, 15 milliamps at most, and it starts sounding once its terminal voltage passes its 3-volt floor. In the simulation, that happens between about 1.8 and 1.9 volts on the gate, and the whole swing from silent to full spans about a tenth of a volt.3 On your actual MOSFET, the snap lands somewhere within the datasheet's 1.0 to 2.5 volt window; wherever it lands, only the narrowness of the snap itself stays constant. Fully on, the drain-to-source drop is a few millivolts, and the light load pulls the 9 volt block down by only a few hundredths of a volt.3

If it fails. Siren silent at every knob position: measure the wiper to ground. If the reading never rises past the 1.0 to 2.5 volt threshold window, the wiper isn't reaching the gate.3 Siren quiet or ragged with the knob unresponsive: the gate voltage is sitting right at the threshold, where the MOSFET is only partly conducting; turn the knob further past it.3 Siren silent with the gate voltage high: check the siren's polarity, since the red lead belongs on the +9 volt side.3

Check on learning
Why can a 5 volt logic pin drive the FQP30N06L directly?
As you sweep the knob, the siren goes from silent to full volume over a tiny turn. Why?
04

Build 2: regulate and boost a battery

This build is field power: a steady 5 volts, whether the battery sits above it or below it, because raw battery voltage is never the steady rail a circuit needs. There are two moves, and you build both. To regulate is to hold a higher, sagging voltage steady at a lower value. To boost is to step a voltage that is too low up to the one you need.

First, regulate 9 volts down to 5. The 7805 is a three-pin linear regulator: voltage in, ground, a steady 5 volts out. Any input between 7 V and 25 V can be regulated down to a constant 5 V.1 The 7 volt floor matters: the input must sit about 2 volts above the output, so a single 3.7 volt cell can never feed a 7805. The two capacitors act as small reservoirs of charge that keep the regulator stable, and they matter even more when the load varies, as a Pi's does.1 One reference build omits both capacitors, since its supply is steady and its load is a fixed resistor. Ours is neither, so we keep the datasheet's specified 0.33 µF in and 0.1 µF out.3

The regulator schematic shows 9 volts in, a 0.33 µF input capacitor, the 7805, a 0.1 µF output capacitor, and the load on a steady 5 volts.
Schematic: a 9 volt battery, input capacitor, 7805 regulator, output capacitor, and a load, giving a steady 5 volt output.
The regulator on a breadboard, wired to match. Measure the output: a steady 5.0 volts while the input sits at 9. Red carries 9 volts in, orange the regulated 5 volts out, black ground.
Breadboard build: a 9 volt block into a 7805 regulator with input and output capacitors, giving a steady 5 volt rail to a load.

Build it in this order.

  1. Seat the 7805 across three rows. Facing the labeled side, its pins are input, ground, output, left to right.3
  2. Place C1, 0.33 µF, between the input pin's column and the ground rail, and C2, 0.1 µF, between the output pin's column and the ground rail.3
  3. Run the ground pin to the ground rail, and the output pin to the +5 volt bus that feeds the load.
  4. Connect the 9 volt block last, positive to the input side, and match the rails' polarity marks.

Regulating this way wastes the difference as heat. The 78 series is fine for low-power circuits of a few hundred milliamps, but above that it starts to get hot and may need a heatsink.1 A datasheet-grounded simulation confirms the behavior: a steady 5.0 volts out for inputs of 9 V, 7 V, or anything just above the 7 V floor, with regulation collapsing once the input drops below it.3 So the meter check is two readings: the input should sit near 9 volts, and the output at 5.0. If the output is low, measure the input first; below the 7 volt floor the regulator has nothing to regulate with.1

Then boost 3.7 volts up to 5. To run a Pi from one small lithium cell you need the opposite move. A boost converter uses an IC and a small inductor, pulsing current through the coil to step a lower voltage up to a higher one.1 Inexpensive adjustable boost modules are widely available, and a combined board charges the LiPo over USB while boosting its output.1 We build that combination from parts on hand: a 3.7 volt LiPo, a TP4056 charger, and an SX1308 boost module set to 5 volts. It does the same job as a commercial PiSugar supply. One rating matters here: the mini slide switch on the cell line is a 0.5 amp part, and a hard-working Pi Zero 2 W can pull more than that from a 3.7 volt cell. The switch is fine for light loads like a microcontroller and a servo; for the Pi, use a switch rated higher than 0.5 A.

The portable power chain. The slide switch cuts the cell's positive line, the cell and the SX1308 input share the TP4056's B+ and B− pads, and the SX1308 output, set to 5 volts, feeds the Pi. Red is the positive rail, black the negative.
Wiring diagram: a 3.7 volt 450 milliamp hour pouch cell through a slide switch on the positive line into a junction feeding both the TP4056 Type-C charger B plus pad and the SX1308 step-up input; the SX1308 output set to 5 volts powers a Raspberry Pi Zero 2 W; charging is over the Type-C port.

Build the chain in this order.

  1. Wire the cell's positive lead through the slide switch to the TP4056's B+ pad, and the cell's negative lead to B−. These are the battery pads; the Type-C port is where charge comes in.
  2. Wire the SX1308's input from the same B+ and B− points, positive to IN+, negative to IN−.
  3. Before the Pi touches anything, power the chain and set the SX1308's trimmer until its output reads 5.0 volts on your meter. The module adjusts across a wide range, so it is set first and loaded second.3
  4. Leave the output unconnected; the Pi connects to it in Build 3, positive and negative checked against the meter, not the wire colors.

Prove it, and read the runtime. The output is already set to 5.0 volts from the last step; the load test comes in Build 3, when the Pi is online. Runtime follows the capacity rule from Unit 02, but with two corrections: the boost loses some of the cell's energy as heat, and the Pi's draw varies with load. A 450 mAh cell at 3.7 volts holds a little over 1.6 watt-hours; after the boost's losses, that leaves roughly 1.4 to 1.5 usable watt-hours at 5 volts. A Pi Zero 2 W draws about 120 milliamps at 5 volts sitting idle, and more with Wi-Fi active, so expect one to two hours of light use, and well under an hour when the CPU or Wi-Fi works hard.11 A plain capacity-over-load estimate comes out high; the boost's losses and the Pi's load spikes are why you get less.

Check on learning
Why can't you power a Pi from a single 3.7 volt LiPo through a 7805?
Why does the SX1308's output get set to 5.0 volts before the Pi is connected?
05

Build 3: relay from a Pi

This build brings the Pi online: you set it up here, and the relay is the first thing it drives. The board is a Pi Zero 2 W, the pocket-sized sibling of the Pi 5 that runs your Module 01 node, and its 40-pin header is the same. A relay is essentially an electromagnet that closes switch contacts; because the coil and the contacts are electrically isolated from each other, relays are well suited to switching home-powered devices on and off.1 Where the MOSFET in Build 1 switched a load sharing its ground, a relay gives full isolation: the switched circuit shares nothing with the Pi.

Meet the board before you wire it: the explorer below is the same tour Module 01 gave the Pi 5.

The header comes fitted. This module specifies the Zero 2 WH, the same board with the 40-pin header already on it, so every connection here is a jumper onto a pin. The header is what the future field hardware stacks onto; keep it unobstructed.

Set up the board first. The Zero 2 W arrives blank, and you prepare it exactly the way you prepared the Module 01 node: from the hardened laptop, with no monitor ever attached.

  1. In Raspberry Pi Imager, choose Raspberry Pi OS Lite (64-bit).2
  2. In the Imager's settings, give the board its own hostname, enable SSH with the same public key your laptop already uses for the node, and enter your Wi-Fi credentials for the 2.4 GHz network; the Zero 2 W has a 2.4 GHz radio only.2 Ours is named dolos, after Dolos, the remotely deployed device this series builds toward: this board serves as its controller and keeps the name from here on.
  3. Boot it and reach it from the laptop:

The board is now a node on the LAN you built in Module 01, and every command in the rest of this module is typed into that SSH session. It stays a local device for now; it does not join the private VPN your node runs on. That enrollment happens in a later module, when the board takes a cellular link and leaves the building. Two tools do the GPIO work on current Raspberry Pi OS: pinctrl, which ships with the OS and drives a pin from the shell, and gpiozero, the Python library.2 OS Lite may not include the library, so install it once:

dolos $ sudo apt update && sudo apt install -y python3-gpiozero

A Pi cannot drive a relay coil directly. A GPIO pin can source about 16 mA at most,2 while the SRD-05VDC-SL-C's 70 Ω coil pulls about 72 mA at 5 volts,3 several times what the pin can safely give. So a small transistor does the driving. A standard relay driver combines a 2N3904 transistor (the near-twin of Module 02's 2N2222), a 1 kΩ base resistor, a 1N4001 diode, and a 5-volt relay.1 You met the transistor and the diode as symbols and packages in Module 02. The 1-channel relay board used here (high/low level trigger), carrying a SONGLE SRD-05VDC-SL-C relay, already has those parts built in.

Inside the module, GPIO18 feeds a 1 kΩ resistor into the base of a 2N3904 transistor, which energizes the relay coil; a 1N4001 diode sits across the coil; the contacts switch the isolated load.
Schematic: Pi GPIO18 through a 1k resistor to the base of a 2N3904 transistor, the collector driving a relay coil with a 1N4001 diode across it, the contacts switching an isolated load.
The diode across the coil has one job. When you turn the relay off, the coil's collapsing magnetic field creates a voltage spike; the diode absorbs it before it can damage anything.1 Our simulation shows the shape of that spike. With no diode, it climbs into the thousands of volts; a real coil arcs and leaks before it gets that far, but the spike still lands far past what the transistor survives. With the 1N4001 in place, the same switch-off clamps to under 6 volts.3
Three jumpers from the Pi header to the module: ground to ground, VCC to 5 volts (pin 2), IN to GPIO18 (pin 12). The COM and NO contacts switch a separate siren on its own 9 volt supply. Red is 5 volts, orange the GPIO18 signal, black ground.
Wiring diagram: a Raspberry Pi Zero 2 W with three jumpers to a 1-channel relay module, 5V to DC plus, GPIO18 to IN, ground to DC minus; the relay contacts switch an isolated siren on its own 9 volt supply.

Prove it. Drive GPIO18 high and low from the SSH session:

dolos $ pinctrl set 18 op dh   # output, drive high: relay closes
dolos $ pinctrl set 18 op dl   # drive low: relay releases

The test is the sound: if the build is working, the relay module clicks on and off.1 The indicator LED lights and the isolated siren follows. Confirm the isolation with the meter set to continuity: put one probe on the Pi's ground and the other on the siren's negative terminal. The meter reads OL and never beeps, because the two circuits share nothing. If the pin goes high and nothing clicks, check two things: the trigger jumper's high/low setting, and whether 5 volts is actually present between the module's DC+ and DC− on your meter.

Close Build 2's loop. Shut the board down, connect the pack's output (5 volts to pin 2, ground to pin 6), and boot from the battery. The pack's output holds 5.0 volts on the meter under the running board.

Check your module's trigger logic. Some relay modules invert the input, switching the coil with a PNP transistor that turns the relay on when the input is 0 V instead of high.1 This board has a jumper to select high or low trigger; set it to match your code before you wire anything to the load.
Check on learning
Why does a Pi drive the relay through a transistor instead of straight from GPIO18?
The relay's contacts switch a siren on its own 9 volt battery. What do the Pi's circuit and the siren's circuit share?
06

Build 4: motion sensor and a Pi

This build reads a sensor: a PIR (passive infrared) detects a moving source of infrared radiation, such as a person's body heat, crossing its field of view. Supply it with power, and its output goes high when it detects movement, then drops back low a second or two later.1

In this build you wire an HC-SR501 PIR module to a Pi Zero 2 W with three wires. The mapping is ground to ground, VCC to 5 volts, and OUT to GPIO18.1

The three wires: 5 volts (pin 2) to VCC, the sensor's OUT to GPIO18 (pin 12), and ground (pin 6) to GND. The two trimmers set sensitivity and how long OUT stays high after a trigger. Red is 5 volts, green the OUT signal, black ground.
Wiring diagram: a Raspberry Pi Zero 2 W reading an HC-SR501 PIR motion sensor on three wires, 5V to VCC, GPIO18 to OUT, ground to GND.
Why is there no level shifter? A Pi's GPIO pins are 3.3 volt logic and are damaged by 5 volts.2 The HC-SR501 runs on 5 volts, but most low-cost PIR sensors like this one output only 3.3 volts, which is why OUT can connect directly to a Raspberry Pi's digital input, as long as you confirm it with a multimeter first.1 One board note: OUT is the center pin of the three; VCC and GND are the outer two, and which is which varies by board, so read the silkscreen, the printed labels on the board itself.

Build it in this order.

  1. Read the sensor's silkscreen. OUT is the center pin; find which outer pin is VCC and which is GND on your board.
  2. Prove the output level first: power the sensor alone, put the meter on OUT, and confirm it swings to about 3.3 volts on motion, not 5.1
  3. With the Pi shut down, run the three jumpers: 5 volts (pin 2) to VCC, GND (pin 6) to ground, OUT to GPIO18 (pin 12).1

Prove it. Power the Pi, set your multimeter to DC volts on the OUT line, and walk in front of the sensor. The line snaps from 0 volts to about 3.3, holds for the delay you set, then drops. If OUT holds high far longer than you want after each pass, that is the delay trimmer, not a fault; it sets how long OUT stays high after a trigger. Then read the same line in software:

dolos $ pinctrl set 18 ip; pinctrl get 18   # input; reads lo idle, hi on motion
Check on learning
The PIR runs on 5 volts. Why is it safe to wire its OUT straight to a 3.3 volt GPIO pin?
After every pass, the PIR's OUT stays high far longer than you want. Is the sensor faulty?
Next module You can take a circuit from schematic to a verified breadboard build, and the Pi you set up now switches and senses through it. 04 · Salvage covers the parts supply: pulling components and connectors, and locating the cells, from dead electronics.
07

Field exercise

Builds 3 and 4 both use GPIO18, one to drive the relay and one to read the PIR, so combining them means moving one. Keep the PIR on GPIO18 and jumper the relay to GPIO17 instead; you write a short gpiozero bridge script that reads GPIO18 and copies its state to GPIO17, so motion on the sensor closes the relay in real time.

Task: Build a motion-triggered switch that runs on its own power: the PIR feeds the Pi, the Pi drives the relay, the relay sounds an isolated siren, and the Build 2 pack powers the Pi.
Condition: Given your four proven builds, the hardened laptop you reach the Pi from, a Pi Zero 2 W, a breadboard and jumper wires, the siren with its own 9 volt supply, and a multimeter.
Standard: The Pi runs from the Build 2 pack, its boost output confirmed at 5.0 volts before it touches the Pi; motion in front of the sensor closes the relay and sounds the siren; the siren releases after the set delay; every connection matches your drawings, in KiCad or on paper; and the finished breadboard is photographed next to its drawing for your build log.

Download the field exercise worksheet (PDF)

08

Module test

Task: Complete the Module 03 test.
Condition: Given ten questions covering units one through seven, without reference to the module units or notes.
Standard: Answer at least eight of ten questions correctly. For each question missed, reread the unit named in the feedback and retake the test until the standard is met.

Module test — 10 questions
A sensor circuit draws a steady 30 mA from a 3000 mAh cell. Roughly how long does it run?
You want more capacity, so you reach for two lithium cells. One reads 4.1 volts, the other 3.5. Can you wire them in parallel?
Your schematic passes KiCad's electrical rules check with zero errors. Is the circuit proven?
Your breadboard build matches the photo and looks right. What proves it?
You flash the microSD, boot the board, and dolos.local never answers. Which limit does this module tell you to check first?
The FQP30N06L is obsolete, so you order an IRLB8721 to replace it. What does this module require before you trust the swap?
Your Build 2 pack reads 5.0 volts unloaded, but the Pi browns out when the CPU works hard. Which part does this module name as the weak link?
You breadboard Build 3's driver around a bare relay instead of the module and leave out the diode across the coil. What happens the first time the coil switches off?
Your meter sits on the PIR's OUT line. It reads 0 volts while the room is still, snaps to about 3.3 when you walk past, holds a few seconds, then drops. What is the verdict?
In the field exercise, you walk past the sensor, and your meter shows GPIO18 snapping high, but the relay never clicks. Where is the fault?

Glossary

boost converter
A part that steps a voltage up, so a 3.7 volt cell can supply 5 volts; the SX1308 module is the example here.
capacity (mAh)
How much charge a battery holds; capacity divided by the current drawn gives the runtime.
Dolos
The remotely deployed device this series builds toward, more than any one sensor or alarm. The Pi Zero 2 W set up in Build 3 serves as its controller and keeps the hostname; the device itself takes shape in later modules, radio and cellular link included.
flyback diode
A diode across an inductive load, such as a relay coil, that absorbs the voltage spike when the current is switched off.
logic-level MOSFET
A MOSFET with a low enough gate threshold to be driven directly by a microcontroller pin.
MOSFET
A transistor switched fully on or off by a voltage on its gate; used to switch a heavy load from a light signal.
perfboard
A board of holes with copper pads to solder to, where a breadboarded circuit becomes permanent.
PIR sensor
A passive infrared sensor; its output goes high when it detects a moving source of infrared radiation, such as a person's body heat.
regulator
A part that holds its output at a fixed voltage below its input (step down). The 7805 gives a steady 5 volts and needs about 2 volts of headroom.
relay
An electrically operated mechanical switch; its coil, energized, closes contacts that switch a separate, isolated circuit.
voltage sag
The drop in a battery's voltage under load and as it discharges. It's the reason raw battery voltage needs conditioning.

Sources

  1. Simon Monk, Hacking Electronics, 2nd ed., McGraw-Hill, 2017. Primary source for the builds. MOSFETs as voltage-controlled switches and the logic-level FQP30N06L (Ch. 3, pp. 45–48); batteries, capacity, discharge rate, series and parallel, and LiPo safety (Ch. 5, pp. 79–93); the 7805 regulator and its 7–25 V input range and capacitors (pp. 93–95); boost converters (pp. 95–96); driving a relay from a transistor and the coil diode (Ch. 6, pp. 113–116); wiring a relay module to a Raspberry Pi (Ch. 7, p. 157); and the PIR sensor with a Pi and its 3.3 V output (Ch. 8, pp. 162–166).
  2. Raspberry Pi documentation: GPIO and the 40-pin header (pads control). The 40-pin header used here (pin 2 = 5 V, pin 6 = ground, pin 12 = GPIO18) and the 3.3 V logic level of the GPIO pins; the Imager's OS customization for headless setup (hostname, SSH key, Wi-Fi); and the pinctrl shell tool and gpiozero Python library used to drive and read the pins.
  3. Manufacturer datasheets: FQP30N06L, L7805, SRD-05VDC-SL-C, 1N4001, SX1308, TP4056, HC-SR501, and the SFM-27-class 9 V piezo siren (DC 3 to 24 V, 15 mA maximum, red lead positive). Part ratings, pinouts, and the values used to validate each build in simulation (the MOSFET switching the siren across its gate threshold, the 7805 output and dropout, and the relay coil spike with and without the diode). FQP30N06L lifecycle: listed as obsolete by onsemi in distributor catalogs (verified 2026-07-04).
  4. “Hacking When It Counts: POW Canteen Radios,” Hackaday, 2016. Lt. Col. R.G. Wells and fellow prisoners in a Japanese camp in Borneo (1942) built a radio receiver from improvised parts: resistors from string impregnated with burnt cinnamon bark, capacitors from tea-chest foil, wire insulation from flour and palm oil, and a chromic-acid wet cell from potassium dichromate and zinc trouser buttons; only the vacuum tube and headset could not be improvised, and the headset was smuggled in.
  5. “Foxhole radio,” Wikipedia. Improvised WWII receivers built from a razor-blade-and-pencil-lead detector; corroborates the practice of prisoners of war building improvised radio receivers in WWII, though the article does not itself name R.G. Wells or Borneo.
  6. Jonathan Bartlett, Electronics for Beginners, Apress, 2020. The schematic as an abstraction where only the connections matter; the solderless breadboard's five-hole terminal strips, the center gap that straddles a chip, and the power rails; and translating a schematic to a breadboard layout (Ch. 5–6).
  7. KiCad Eeschema documentation: the Electrical Rules Check. KiCad's ERC performs “automatic detection of incorrect and missing connections,” including unconnected pins and an input power pin “not driven by any Output Power pins.”
  8. Electrical Science, Module 4: Batteries (DOE-HDBK-1011/2-92), US Department of Energy. Cell fundamentals: the battery as connected voltaic cells; primary versus secondary cells; series and parallel wiring (four 1.5 V cells give 6 V in series, and parallel adds current capacity); ampere-hour capacity; and internal resistance dropping the terminal voltage under load (VL = VB − ILRi).
  9. David Linden and Thomas B. Reddy, Handbook of Batteries, 3rd ed., McGraw-Hill, 2002. Authoritative comparison figures (Tables 1.2, 7.3, 22.3): nominal cell voltage, specific energy, self-discharge rate, and cycle life for alkaline (1.5 V), lead-acid (2.0 V), NiMH (1.2 V), and lithium-ion and lithium-polymer (3.6 V nominal, 4.2 V full); and the practical capacity being only about 25 percent of theoretical under real load.
  10. Micah Toll, DIY Lithium Batteries: How to Build Your Own Battery Packs. The lithium-ion and LiPo voltage window and the correction that most “LiPo” cells are lithium-ion pouch cells; the C-rate; series (S-count) and parallel pack math and the rule to match cell voltages before joining them in parallel; voltage sag; constant-current, constant-voltage charging; thermal-runaway thresholds; and using salvaged cells conservatively.
  11. CNX Software: “Raspberry Pi Zero 2 W power consumption” (2021). Bench measurements: about 120 mA at 5 V idle headless on Raspberry Pi OS Lite, roughly 75 mA with HDMI and services disabled, peaks near 600 mA under CPU stress and up to about 1.4 A under combined load (verified 2026-07-04).
You’re viewing one module. ▸ Open the full interactive course in TG//OS
Light Fighter Manifesto
// Series · Module 03
Building Circuits

You draw each circuit in KiCad, build and test it on a breadboard with your multimeter, then put a Raspberry Pi in control: switching a load, driving a relay, reading a sensor, running on a battery.

In this module_×
01Draw it, then prototype it
02Batteries and power
03Build 1: power MOSFET switch
04Build 2: regulate and boost a battery
05Build 3: relay from a Pi
06Build 4: motion sensor and a Pi
07Field exercise
08Module test
Open on a desktop_×

This module lives in TG//OS — the interactive course with its tools, terminal, and tests. It’s built for a desktop or laptop screen.

▸ Open this site on a computer to start.