Skip to content

Instantly share code, notes, and snippets.

@decagondev
Last active December 3, 2025 19:25
Show Gist options
  • Select an option

  • Save decagondev/f861ef8e7b08cc12399cb525ec06f2cc to your computer and use it in GitHub Desktop.

Select an option

Save decagondev/f861ef8e7b08cc12399cb525ec06f2cc to your computer and use it in GitHub Desktop.

Nice — fun project. I’ll plan this so the Pi Zero measures whether parts inside the washing machine are working (pump, motor, heater, valves, door switch) without asking you to directly wire high-voltage mains into the Pi. Safety first: do not connect Raspberry Pi GPIO directly to mains or to non-isolated circuits. For anything that touches mains, use galvanic isolation (opto-isolators, isolated sensors, or external AC→DC isolated modules), or test components removed from the appliance on a bench with safe low-voltage signals.

Below I give:

  • A high-level plan (hardware + software)
  • BOM (parts & why)
  • Schematics and wiring diagrams (Mermaid block & GPIO maps)
  • Example circuits for safe low-voltage continuity/voltage-detection, LEDs, and an ADC
  • Example Python code for the Pi
  • Safety checklist + testing procedure

1) High-level plan (summary)

  1. Use Raspberry Pi Zero (3.3V GPIO).

  2. Inputs: probes that test continuity / low-voltage presence. Design so the probes never present mains to the Pi:

    • For continuity/resistance checks use an isolated low-voltage source (e.g., 5–12 V battery or isolated bench supply) and current-limited probe with series resistor, or use an isolation** optocoupler **wired as a sense path.
    • For detecting mains-powered parts are powered use optocouplers or current sensors (non-contact clamp CT or Hall-effect sensor) — these give an isolated, safe low-voltage signal to the Pi.
    • For voltage measurement use an external isolated ADC or an isolation stage (do not measure mains directly).
  3. If you need analog measurement, add an ADC (MCP3008 or ADS1115) that the Pi talks to over SPI or I²C. Ensure signals are limited to 0–3.3V.

  4. Outputs: LEDs (with series resistors) driven directly from GPIO (max 16 mA typical per pin). For driving multiple LEDs or larger loads, use transistor drivers or a small MOSFET / ULN2003 driver.

  5. Software: Python service that polls inputs, debounces, and sets outputs. Provide logging + web UI or simple status LEDs.

  6. Enclosures & labels: keep wiring tidy, isolation barriers, fuses and TVS for surge protection.


2) BOM (suggested)

  • Raspberry Pi Zero W (or Zero 2 W) with header
  • micro SD card, power supply for Pi (5V)
  • MCP3008 (SPI ADC) or ADS1115 (I²C) — pick one if you need analog readings
  • Opto-isolators (e.g., 4N25, PC817) — one per mains-sensed channel
  • Small isolated DC supply / battery pack (for probe source) — e.g., isolated 9 V module or battery
  • Current sensors (non-contact clamp) or Hall-effect sensors (e.g., ACS712 family) for sensing pump/motor current — preferred for detecting motor/pump activity without connecting to mains
  • Resistors: 220Ω, 1k, 10k, and resistor pairs for voltage dividers (values given below)
  • NPN transistors (2N2222) or N-channel MOSFETs for driving larger LEDs/relays
  • LEDs (status)
  • Opto-isolated SSRs or mechanical relays if you want to drive test signals (be careful)
  • Breadboard / perfboard, jumper wires, insulated probe leads
  • Multimeter, clamp meter, isolation transformer (for safe bench work)
  • Enclosure, heat shrink, terminal blocks

3) Safety & rules (must read)

  • Never connect Pi GPIO to mains or any voltage >3.3 V without proper level shifting & galvanic isolation.
  • Use optocouplers or current sensors to sense mains activity. Do not measure mains with voltage dividers into the Pi.
  • When testing a component's coil/resistance, remove it from mains before measuring resistance (better: test on bench with isolated low-voltage).
  • Use a series resistor to limit current from any test source to safe levels.
  • If you’re not comfortable with mains wiring, have a qualified electrician perform mains connections and isolation steps.

4) Block diagram (Mermaid)

This is a top-level block diagram showing isolation and flow.

graph LR
  A["Raspberry Pi Zero (GPIO, SPI/I2C)"] ---|3.3V logic| B(MCP3008 ADC or ADS1115)
  A ---|GPIO out| G[LEDs / Driver transistors]
  B ---|analog in| C[Voltage divider / sensor conditioning]
  C ---|isolated signal| D[Opto-coupler / Current Sensor]
  D ---|isolated detection| E["Washing Machine Component (pump/motor/valve)"]
  E --- F[Main Mains Supply] 
  subgraph SafetyLayer
    S[Isolated probe source / battery or isolated DC supply] 
    S --- C
  end

  click D "https://en.wikipedia.org/wiki/Opto-isolator" "Optocoupler (info)"
Loading

Note: D represents opto-isolators or current sensors — those provide galvanic isolation between mains and Pi.


5) GPIO mapping (Mermaid)

Example mapping using GPIO numbers (BCM). Adjust if you use a different Pi.

flowchart TB
  Pi[Pi Zero GPIO Header] 
  Pi -->|SPI MOSI| MOSI(MOSI - SPI)
  Pi -->|SPI MISO| MISO(MISO - SPI)
  Pi -->|SPI SCLK| SCLK(SCLK - SPI)
  Pi -->|SPI CE0| CE0(CE0 - SPI)
  Pi -->|I2C SDA| SDA(I2C SDA)
  Pi -->|I2C SCL| SCL(I2C SCL)
  Pi -->|GPIO 17| IN_PUMP(Probe Input - Pump)
  Pi -->|GPIO 27| IN_MOTOR(Probe Input - Motor)
  Pi -->|GPIO 22| IN_HEATER(Probe Input - Heater)
  Pi -->|GPIO 23| IN_DOOR(Probe Input - Door switch)
  Pi -->|GPIO 24| OUT_LED_PUMP(LED Pump OK)
  Pi -->|GPIO 25| OUT_LED_MOTOR(LED Motor OK)
Loading

6) Example circuits (safe approaches)

A — Continuity / component-resistance test (safe)

Do not use mains. Instead, use an isolated low-voltage source (battery or isolated bench PSU), a series resistor, and an input that senses if current flows.

Circuit idea (textual):

  • Isolated supply (+V isolated) → series resistor Rseries (e.g., 4.7 kΩ) → Probe A → component under test → Probe B → pull-down resistor to ground of isolated supply and opto input or comparator input → through optocoupler LED to ground → optocoupler transistor side to Pi (safe 3.3V signal).

This way the Pi sees only the optocoupler transistor output (open-collector style) referenced to Pi GND — galvanically isolated from mains/component.

Mermaid simplified diagram:

flowchart LR
  ISO_BATT[Isolated battery / isolated PSU] --> R[Series resistor]
  R --> ProbeA[Probe A]
  ProbeA --> Component[Component under test]
  Component --> ProbeB[Probe B]
  ProbeB --> LEDin[Opto LED side] --> ISO_GND
  OptoOut["Opto transistor (isolated)"] --> PiGPIO[Pi GPIO input]
Loading

B — Detecting mains-powered component is powered (preferred: non-contact)

  • Use a clamp-style current sensor (ACS712 type) or non-contact CT on the pump/motor power conductor. These produce a small isolated analog voltage proportional to current. Feed that to ADC (after offset/conditioning) — the ADC must be referenced to Pi ground but the sensor provides isolation, or use an isolated ADC.

Mermaid:

flowchart LR
  MainsConductor ---|clamp| CT[Current Transformer / Hall sensor]
  CT --> Cond[Conditioning + low-pass]
  Cond --> ADC[MCP3008 ADC]
  ADC --> PiGPIO[Pi SPI]
Loading

C — LED outputs

  • GPIO -> series resistor (330Ω typical) -> LED -> GND. For multiple LEDs or higher current, drive via transistor.

Mermaid:

flowchart LR
  GPIO --> R330[330Ω]
  R330 --> LED(LED)
  LED --> GND
Loading

7) Voltage divider guidance (only for low-voltage/isolated sources)

If you have an isolated DC signal up to e.g. 12 V you want to read with ADC that expects 0–3.3 V, use a divider. Example: scale 12 V → 3.3 V:

Let R1 (top) and R2 (bottom). Vout = Vin * R2/(R1+R2). To scale 12V to 3.3V, ratio = 3.3/12 = 0.275. Choose R2 = 10 kΩ → R1 = ( (1/0.275) - 1 ) * R2 ≈ 26.36kΩ → use 27 kΩ.

So: R1 = 27k, R2 = 10k → Vout ≈ 12 * (10/(27+10)) ≈ 3.07 V (safe for ADC). Adjust values and include protection zener or clamp diodes if you expect spikes. Only do this for isolated, low-voltage sources, not mains.


8) Example software (Python/Pseudocode)

Below is a minimal Python example to read digital inputs and an SPI ADC (MCP3008). This is meant to run on the Pi directly.

# Example: read digital inputs and ADC using spidev and RPi.GPIO
import time
import spidev
import RPi.GPIO as GPIO

# GPIO pin setup (BCM)
IN_PUMP = 17
IN_MOTOR = 27
IN_HEATER = 22
OUT_LED_PUMP = 24
OUT_LED_MOTOR = 25

GPIO.setmode(GPIO.BCM)
for pin in (IN_PUMP, IN_MOTOR, IN_HEATER):
    GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
for pin in (OUT_LED_PUMP, OUT_LED_MOTOR):
    GPIO.setup(pin, GPIO.OUT)
    GPIO.output(pin, GPIO.LOW)

# SPI for MCP3008
spi = spidev.SpiDev()
spi.open(0,0)  # bus 0, CE0
spi.max_speed_hz = 1350000

def read_mcp3008(channel):
    # channel 0-7
    cmd = 0b11 << 6                  # start + single-ended
    cmd |= (channel & 0x07) << 3
    resp = spi.xfer2([cmd, 0, 0])
    value = ((resp[0] & 0x01) << 9) | (resp[1] << 1) | (resp[2] >> 7)
    return value  # 10-bit value 0-1023

try:
    while True:
        pump = GPIO.input(IN_PUMP)
        motor = GPIO.input(IN_MOTOR)
        heater = GPIO.input(IN_HEATER)

        # Example ADC read on channel 0 (e.g., current sensor)
        adc_val = read_mcp3008(0)
        adc_voltage = adc_val * 3.3 / 1023

        GPIO.output(OUT_LED_PUMP, GPIO.HIGH if pump else GPIO.LOW)
        GPIO.output(OUT_LED_MOTOR, GPIO.HIGH if motor else GPIO.LOW)

        print(f"pump:{pump} motor:{motor} heater:{heater} adc_v:{adc_voltage:.2f}V")
        time.sleep(0.5)

except KeyboardInterrupt:
    spi.close()
    GPIO.cleanup()

Notes:

  • Use proper debouncing and software filtering (moving average) on ADC.
  • If you use opto-isolators, wire the opto transistor as an open-collector to Pi with a pull-up (e.g., 10k).

9) Testing checklist (safe incremental tests)

  1. Build and test LED outputs on bench (GPIO -> resistor -> LED -> GND). Confirm safe operation.
  2. Test ADC reading with a known isolated source (battery, pot). Confirm calibration.
  3. Test optocoupler with the isolated source (drive opto LED, measure transistor output with Pi).
  4. Test clamp/non-contact current sensor on a powered conductor using the sensor datasheet recommended setup—do not alter wiring while powered.
  5. For continuity checks, test with a known resistor/component on bench before probing the washing machine.
  6. Only after isolation confirmed, test sensors on the appliance when it’s safe and supervised. Use full PPE and ensure mains wiring is done by a professional if you’re not certain.

10) Example Mermeid wiring diagram (simplified mapping showing opto path + ADC)

flowchart LR
  subgraph Pi
    P1["GPIO IN: Pump (GPIO17)"]
    SPI["MCP3008 (SPI)"]
    P_out1["GPIO OUT: LED Pump (GPIO24)"]
  end

  subgraph IsolatedProbe
    BATT[Isolated 9V]
    Sres[Rseries 4.7kΩ]
    ProbeA --> Comp["Component under test (pump coil) — disconnected from mains for bench test"]
    ProbeB --> OptoLED["(Opto LED)"]
    OptoLED --> ISO_GND
  end

  BATT --> Sres --> ProbeA
  ProbeB --> OptoLED
  OptoLED -.-> OptoTrans[Opto transistor]
  OptoTrans -->|isolated| P1

  CurrentSensor[Clamp CT / Hall sensor] --> ADCinput[Signal conditioning] --> SPI
  SPI -->|digital| P1
  P_out1 --> LED_Pump
Loading

11) Extras / optional features

  • Web UI/dashboard: use Flask or FastAPI on Pi to show real-time status and history.
  • Logging to CSV or InfluxDB (if you want time-series).
  • Add push notifications (if part failure detected).
  • Add automatic test routines: e.g., energize valve via isolated relay and detect current flow (only if you have safe and isolated relay & know what you’re doing).

12) Final notes & next steps

If you’d like, I can:

  • Produce a detailed wiring diagram for a specific subset (e.g., “pump continuity probe with optocoupler + Pi input” OR “pump activity detection using ACS712 + MCP3008 + Pi”) — tell me which sensor(s) you prefer and whether you plan to work on the appliance while powered or prefer bench tests only.
  • Generate a PCB-style schematic or breadboard layout.
  • Produce ready-to-run Python code including web UI.

Tell me which channel(s) you want me to expand (opto-isolator path, ADC wiring + exact resistor values for a given measurement range, or clamp sensor wiring). I’ll proceed with a full wiring diagram and parts list for that specific path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment