Build a Raspberry Pi‑Powered Electrolysis Kit for DIY Hydrogen Generation
Ever wondered why hydrogen is suddenly everywhere—from fuel‑cell cars to backyard science fairs? The buzz isn’t just hype; hydrogen is a clean energy carrier that can power everything from a tiny LED to a whole bus. The good news? You don’t need a university lab to make a few bubbles of it. With a Raspberry Pi, a couple of cheap parts, and a splash of curiosity, you can build a safe, low‑cost electrolysis kit right on your kitchen bench. At Tech Brew Lab we love mixing code with chemistry, so let’s walk through the whole process step by step.
Why a Pi?
The Raspberry Pi is more than a tiny computer; it’s a flexible controller that can read sensors, switch relays, and log data—all with a few lines of Python. Using a Pi means you can:
- Automate the voltage and timing so you get repeatable results.
- Monitor temperature, voltage, and gas output in real time.
- Log everything to a CSV file for later analysis or to share with fellow makers.
All of this turns a simple chemistry demo into a mini‑lab that you can tinker with again and again.
Parts List (All Under $50)
| Item | Typical Cost | Where to Find |
|---|---|---|
| Raspberry Pi 4 (2 GB) | $45 | Official store or Amazon |
| 5 V 2 A USB power supply | $8 | Any electronics shop |
| 2‑channel 5 V relay board | $6 | eBay or AliExpress |
| 12 V DC power supply (for electrolysis) | $10 | Local hardware store |
| Two stainless‑steel plates (2 cm × 2 cm) | $5 | Kitchen supply or scrap metal |
| 1 L glass or plastic container with lid | $3 | Home goods |
| Distilled water + 1 % NaCl (salt) | $2 | Grocery store |
| Jumper wires, breadboard, heat‑shrink tubing | $5 | Electronics kit |
| Optional: small temperature sensor (DS18B20) | $4 | Online |
Total: roughly $48. Feel free to swap parts you already have—just keep the voltage and safety guidelines in mind.
Safety First (Seriously)
Hydrogen is flammable, and the mixture of hydrogen and oxygen (called “explosive gas”) can ignite with a tiny spark. Follow these rules:
- Work in a well‑ventilated area—preferably outdoors or under a fume hood.
- Never seal the container; always leave a tiny vent for gas to escape.
- Keep flames, sparks, and static away from the setup.
- Use a low voltage (under 12 V) for the electrolysis cell; higher voltages generate more heat and can damage the Pi.
- Wear safety glasses and gloves when handling the electrolyte solution.
Building the Electrolysis Cell
1. Prepare the Electrodes
Cut the stainless‑steel plates to size. Clean them with a bit of sandpaper or steel wool to remove any oil. This gives a better surface for the electric current to flow.
2. Assemble the Cell
Place the two plates parallel to each other inside the container, about 1 cm apart. Use non‑conductive spacers (plastic washers work fine) to keep them steady. Fill the container with distilled water mixed with a pinch of salt—about 1 % by weight. The salt acts as an electrolyte, allowing current to pass more easily.
3. Wire the Electrodes
Connect the positive plate to the normally open (NO) side of one relay channel, and the negative plate to the NO side of the other channel. The common (COM) side of each relay goes to the 12 V supply. This arrangement lets the Pi turn each electrode on or off independently, which is handy for pulsed electrolysis (more on that later).
4. Hook Up the Pi
Plug the relay board into the Pi’s GPIO pins (we’ll use pins 17 and 27). Connect the Pi’s 5 V and ground pins to the relay board’s VCC and GND. If you’re adding a temperature sensor, wire it to GPIO 4 and a 4.7 kΩ pull‑up resistor as the datasheet suggests.
Coding the Controller
Open a terminal on the Pi and install the required Python libraries:
sudo apt-get update
sudo apt-get install python3-gpiozero python3-pandas
Create a file called electrolysis.py:
#!/usr/bin/env python3
from gpiozero import OutputDevice
import time
import pandas as pd
from datetime import datetime
# Define relays
pos = OutputDevice(17) # positive electrode
neg = OutputDevice(27) # negative electrode
# Optional temperature sensor (DS18B20)
# import w1thermsensor
# sensor = w1thermsensor.W1ThermSensor()
log = []
def run_cycle(on_time, off_time, cycles):
for i in range(cycles):
pos.on()
neg.on()
start = datetime.now()
# temp = sensor.get_temperature()
# log.append([start, "ON", temp])
log.append([start, "ON", None])
time.sleep(on_time)
pos.off()
neg.off()
end = datetime.now()
# temp = sensor.get_temperature()
# log.append([end, "OFF", temp])
log.append([end, "OFF", None])
time.sleep(off_time)
if __name__ == "__main__":
run_cycle(on_time=5, off_time=2, cycles=20)
df = pd.DataFrame(log, columns=["timestamp", "state", "temp"])
df.to_csv("electrolysis_log.csv", index=False)
This script turns the electrodes on for five seconds, off for two, and repeats twenty times. You can change the timing to try “pulsed” electrolysis, which often yields more gas for the same energy input.
Run it with:
python3 electrolysis.py
Watch the Pi’s LED blink as the relays click—each click is a burst of current splitting water into hydrogen and oxygen.
Measuring the Gas
A simple way to see the result is to fill a small inverted test tube with water, submerge it in the container, and watch bubbles rise into the tube. The volume you collect over a set time gives you a rough efficiency number. For a more precise measurement, you could attach a cheap flow sensor, but that’s a project for another day.
Tweaking for Better Performance
- Increase Surface Area – Use a mesh or multiple plates to give the current more contact points.
- Adjust Electrolyte – A little baking soda works as well as salt and is less corrosive.
- Pulse Width Modulation (PWM) – Instead of full on/off, use PWM to vary the voltage quickly; the Pi’s
gpiozerolibrary can do this withPWMOutputDevice. - Temperature Control – Warmer water conducts better, but too hot can cause rapid gas release and safety issues. Keep the solution around 30‑40 °C.
What Can You Do With the Hydrogen?
At Tech Brew Lab we love small experiments. Try lighting a tiny LED with a hydrogen‑fuel cell you can buy for under $10. Or, if you’re feeling adventurous, connect the gas line to a small burner and melt a piece of solder—just remember the flame safety rules.
Even if you stop at collecting bubbles, you’ve built a platform that blends software, electronics, and chemistry. That’s the spirit of DIY: learn a little, tinker a lot, and share the fun.
Happy brewing!
- → DIY Wi‑Fi Sprinkler Controller with Raspberry Pi: Step‑by‑Step Guide for a Smarter Garden @sprinklertech
- → How to Build a Smart Home Hub with Raspberry Pi @techandtinker
- → Troubleshooting Common UART Communication Errors on Raspberry Pi: A DIY Checklist @serialcablechronicles
- → A Step‑by‑Step Guide to Low‑Waste Laboratory Techniques for Green Researchers @ecolabinnovations
- → Step-by-step Guide: Building a Low-cost Ultrasonic Distance Sensor for Raspberry Pi @sensorcraft