08 Electronics

08 Electronics

📸 Wiring photos coming. The three diagrams below cover the geometry; the GPIO-to-relay table tells you what each pin does.

The plumbing works; now the electronics. This page covers the relay-to-Pi jumpers (six wires), the 12V power distribution through the float switch (the hardware safety net for runaway pumps), and the moisture-sensor wiring (three sensors via the ADS1115 ADC). The diagrams below are the canonical reference; the procedures lift from the v1 build guide. Plan on about ninety minutes if everything is laid out, longer if this is your first time pushing jumpers onto a Pi header.

Disconnect the 12V power before wiring anything. Bare 12V wires touching a Pi pin will fry the SoC. The Pi can stay powered for the relay-jumper wiring (steps 1–2 below); only plug in the 12V adapter AFTER the pre-flight checklist passes.

GPIO pinout

The Pi’s 40-pin GPIO header carries the relay control signals (4 pins), the I2C bus to the ADS1115 (2 pins), the 5V relay power (1 pin), the 3.3V sensor power (1 pin), and ground (shared, at least 1 pin used). Twelve pins total — highlighted in the diagram below.

Raspberry Pi 40-pin GPIO header showing the 12 pins used for irrigation control: pin 1 (3.3V) for sensor power, pin 2 (5V) for relay power, pins 3 (SDA) and 5 (SCL) for the I2C bus to the ADS1115, pins 6 and 9 for ground, and pins 11, 13, 15, 16 (GPIO 17, 27, 22, 23) for the four relay control lines.
The Pi’s 40-pin GPIO header. The 12 highlighted pins are everything this build uses; the rest stay unconnected. Pin numbering is “physical” (the header position 1–40), separate from “BCM” GPIO numbers (the chip’s internal labels). Both are shown.

Pin 1 sits at the corner with the square solder pad on the underside. Most Pi cases include a header label you can read off; if yours doesn’t, count from the corner with the square pad and you can’t go wrong.

Pi → relay jumper map

Pi GPIO (BCM) Pi physical pin Relay module pin Controls
GPIO 17 Pin 11 IN1 Pump
GPIO 27 Pin 13 IN2 Valve 1 (lettuce)
GPIO 22 Pin 15 IN3 Valve 2 (tomatoes)
GPIO 23 Pin 16 IN4 Valve 3 (raised bed)
5V Pin 2 VCC Relay power
GND Pin 6 GND Relay ground

Female-to-female jumper wires are the right cable for this — they push onto both the Pi header and the relay screw terminals. Six jumpers total. The SVG above shows where each pin physically sits on the header; the table tells you what role each pin plays — GPIO 17 → IN1 controls the pump, and so on.

Why does the relay “click”? Each relay channel has a tiny electromagnet that pulls a metal contact against another metal contact when the GPIO line goes LOW (yes, LOW — most opto-isolated relay modules are active-low). The “click” is that physical contact closing. Click means current is now flowing from COM to NO; no click means COM is connected to NC instead.

What does COM / NO / NC mean? A relay is a switch with three terminals: COM (common, the always-connected wire), NO (normally open — disconnected from COM until the relay clicks), and NC (normally closed — connected to COM until the relay clicks; when it does click, NC disconnects and NO connects). For irrigation: 12V adapter (+) → COM; pump or valve red wire → NO. Relay clicks → 12V flows. Relay doesn’t click (or the Pi loses power) → no 12V flows. Fail-safe geometry.

Relay-to-Pi wiring

Block diagram showing the Raspberry Pi connected to a 4-channel relay module via 6 jumper wires (4 control lines from GPIO 17/27/22/23 to relay IN1-IN4, plus 5V and GND for relay power), with the relay's switched outputs going to the pump and three solenoid valves; an active-low note indicates that GPIO LOW closes the relay contact.
The relay-to-Pi block diagram. Six jumper wires from the Pi header to the relay’s IN1–IN4, VCC, and GND terminals. Active-low: a GPIO output set to LOW (0V) energizes the relay; HIGH (3.3V) lets it open. The Python script handles the inversion automatically.

With the Pi powered off:

  1. Slide each female-to-female jumper onto the Pi header pin per the table above. Push straight down — the pins are 0.1” pitch and bend if you angle the jumper.
  2. Push the other end onto the matching relay module pin (IN1, IN2, IN3, IN4, VCC, GND). The relay module’s pin block is the same 0.1” pitch as the Pi header, so the same jumpers fit both ends.
  3. Tug-test each jumper. A loose pin under vibration is the most common intermittent-failure cause on this build — five seconds of tugging now saves an afternoon of debugging in August.

That’s the entire Pi-to-relay wiring. The relay-to-loads wiring (pump + valves) uses the COM and NO terminals on the relay’s output side; that’s the next section.

12V power distribution

Single-column 12V flow diagram: 12V adapter (+) feeds into the float switch (in series), then to a distribution point that fans out to the 4 relay COM terminals (one per channel), then from each relay's NO terminal to the corresponding load (pump on CH1, valves 1-3 on CH2-CH4); all load grounds tie back to a shared ground bus and to the 12V adapter (-).
12V flow on a single column. The float switch sits in series on the positive line — when the bucket runs dry, the float drops and breaks the circuit, killing power to the pump and valves regardless of what the Pi is trying to do. Hardware safety net.

With the 12V adapter still UNPLUGGED:

  1. Plug the 12V adapter into the barrel-jack pigtail. The pigtail’s screw terminals give you + and to work from.
  2. Wire the float switch in series on the positive line: 12V (+) → float switch wire A; float switch wire B → distribution point. Polarity doesn’t matter for the float switch itself (it’s just a contact), but consistency in wire colour will save you a multimeter session next year when you’ve forgotten which wire is which.
  3. From the distribution point, run 12V positive to FOUR destinations using a terminal strip or twist-and-solder:
    • Relay CH1 COM (pump)
    • Relay CH2 COM (valve 1)
    • Relay CH3 COM (valve 2)
    • Relay CH4 COM (valve 3)
  4. From each relay’s NO terminal, run a wire to the device it controls:
    • CH1 NO → Pump red wire (+)
    • CH2 NO → Valve 1 red wire (+)
    • CH3 NO → Valve 2 red wire (+)
    • CH4 NO → Valve 3 red wire (+)
  5. Connect ALL ground (−) wires together and back to the 12V adapter (−): pump, all three valves, and the 12V adapter return. A second terminal strip is the cleanest way to do this; a single twist-and-solder bundle works too if you cover it in heat-shrink afterwards.
  6. Tug-test every screw terminal. Vibration plus loose copper plus 12V is how you start a fire on a balcony in July.

If the bucket runs dry, the float drops, the switch opens, and the 12V line breaks. The pump physically can’t run dry because there’s no power available to it. This is hardware redundancy on top of the Pi-driven cron schedule — the software might command the pump on, but the float says no, and the float wins.

Moisture sensors and the ADS1115

The capacitive moisture sensors output an analog voltage that the Pi can’t read directly (the Pi has no analog inputs of its own). The ADS1115 ADC bridges them — three sensors plug into channels A0, A1, and A2; the Pi reads the digital values via I2C at address 0x48.

ADS1115 → Pi

ADS1115 pin Pi destination
VDD Pi 3.3V (Pin 1)
GND Pi GND (Pin 9 or any GND)
SCL Pi GPIO 3 / SCL (Pin 5)
SDA Pi GPIO 2 / SDA (Pin 3)
ADDR Pi GND (sets I2C address to 0x48)

Sensor → ADS1115

Sensor VCC GND AOUT → ADS1115
Sensor 1 (lettuce pot) Pi 3.3V Pi GND A0
Sensor 2 (tomato pot) Pi 3.3V Pi GND A1
Sensor 3 (raised bed) Pi 3.3V Pi GND A2

Use the breadboard to create shared 3.3V and GND rails for all three sensors; only the AOUT line needs to be unique per sensor.

Cable runs. Each sensor needs to reach from the Pi enclosure to its pot. That’s three sets of three-wire cables running across the balcony (about 2–4 ft for a lettuce pot, 3–6 ft for tomatoes, 5–8 ft for the raised bed). Solder or crimp extensions onto the sensor’s short factory leads — 22 AWG stranded works well; refer back to page 07 for the soldering technique. Run the sensor cables SEPARATELY from the 12V pump and valve lines: parallel high-current wires induce noise on the analog signal, and a noisy moisture reading produces phantom watering events. Zip-tie sensor cables along the railing, under the drip tubing, on the opposite side of the railing from the 12V bundle. Protect every exposed solder joint with heat-shrink tubing.

Sensor positioning. Push each sensor vertically into the soil to the line marked on the sensor’s PCB (about two-thirds of the way up the sensing area). The electronic components at the top of the sensor must stay ABOVE the soil surface — bury them and water creeps in along the conformal coating, the readings drift, and the sensor dies in a month. Pick a representative pot for each zone (the middle of the row, not the driest corner, not directly under an emitter). For the raised bed, position the sensor in the peas section since that’s the majority of the bed and the thirstiest section.

Enclosure and mounting

Use the Otdorpatio IP65 weatherproof enclosure (or any IP65-rated equivalent — the rating matters more than the brand). Drill cable entries on the bottom face only — water can’t drip into a hole that points downward. Glue around each cable with RTV silicone for outdoor sealing; let it cure for at least four hours before the first rain. Route everything in from below: Pi USB-C, 12V barrel jack, three sensor cables, three valve cables, two pump wires. Position the enclosure under the roof overhang, on a shelf or wall mount, never anywhere water can pool around it.

Pre-flight checklist

Before plugging in the 12V adapter, verify all of these:

  1. No 12V wire touches any 3.3V or 5V Pi pin.
  2. The relay module’s VCC goes to the Pi’s 5V (Pin 2), not to 12V.
  3. All ground connections are tied together and shared across both supplies (Pi GND ↔︎ relay GND ↔︎ 12V adapter return).
  4. Every screw terminal has been tug-tested — no loose wires.
  5. Each solenoid has a 1N4001 flyback diode across its coil (cathode = stripe = +12V side).
  6. Nothing is under tension; cables route through the strain reliefs.

If any item fails, stop and re-check. The most common mistake on first builds is shorting 12V to 3.3V — that fries the SoC and ends the build. The pre-flight is two minutes; a new Pi is forty pounds and a week of waiting.

First power-on test

The test runs in two phases: relay-only (Pi powered, 12V still off) so you can confirm the GPIO wiring without risking the loads, then per-zone (12V on) once the relays click on command.

  1. Plug in the Pi power supply. Wait for it to boot (~30 seconds).
  2. Plug in the 12V adapter.
  3. Listen — nothing should happen. All four relays should be open (pump off, valves closed). If you hear a relay click on power-on with no GPIO command, that’s a wiring issue: probably ground continuity through an unintended path.
  4. From the Pi terminal (ssh [email protected] or a directly attached keyboard), test each relay manually. The pump relay (GPIO 17) is the loudest:
# Toggle the pump relay (GPIO 17) on for 2 seconds
python3 -c "
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, GPIO.LOW)   # Active-low: LOW closes the relay
time.sleep(2)
GPIO.output(17, GPIO.HIGH)
GPIO.cleanup()
print('Pump toggled on for 2 seconds.')
"

You should hear the relay click and the pump hum for two seconds. No water should flow because all the valves are still closed.

  1. Repeat the test with pin 27, then 22, then 23 — confirm each relay clicks and the corresponding valve opens audibly (solenoid valves give a soft thunk when they energize).
  2. Full-zone test. Open valve 1 (GPIO 27) AND the pump (GPIO 17) simultaneously. Water should flow through the lettuce zone for five seconds:
python3 -c "
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
for pin in [17, 27]:
    GPIO.setup(pin, GPIO.OUT)
GPIO.output(27, GPIO.LOW)   # Open valve 1 first
time.sleep(0.5)
GPIO.output(17, GPIO.LOW)   # Then start the pump
time.sleep(5)               # Water flows for 5 seconds
GPIO.output(17, GPIO.HIGH)  # Stop pump
time.sleep(0.5)
GPIO.output(27, GPIO.HIGH)  # Close valve 1
GPIO.cleanup()
print('Zone 1 test complete.')
"

Confirm water flows to the lettuce pots ONLY. If water comes out of the wrong zone, you have valve wiring swapped — see Stuck? below.

Verify the I2C bus

sudo i2cdetect -y 1

You should see 48 highlighted in the grid (the ADS1115’s I2C address). If you see nothing, check SDA and SCL wiring and confirm I2C is enabled on the Pi (page 09 covers raspi-config — but the setup-pi.sh script enables I2C automatically the first time it runs).

With the electronics wired and the relays passing manual tests, page 09 walks the Pi setup: flashing Pi OS Lite, SSH, and the one-shot setup-pi.sh script.