Garden · Raspberry Pi Pico
Window Farm Monitor
A Raspberry Pi Pico build with 6 components. Reads: Soil sensor, DHT22, Light sensor. Drives: Relay, LED, OLED. When the soil reads dry, switch the pump relay on until it recovers.
6 parts · 18 connections · 11 steps
Wiring
Parts
| Part | Refs | Qty | Est. |
|---|---|---|---|
| Capacitive soil moisture sensor | SoilSensor | 1 | $1.80 |
| 1-channel relay module (5 V) | Relay | 1 | $1.20 |
| LED (5 mm) + 220 Ω resistor | LED | 1 | $0.15 |
| SSD1306 OLED display (128×64, I²C) | OLED | 1 | $3.20 |
| DHT22 temperature & humidity sensor | DHT22 | 1 | $4.50 |
| Photoresistor (LDR) + 10 kΩ divider | LightSensor | 1 | $0.40 |
| Plus: breadboard, jumper wires, USB cable | ≈ $11.25 | ||
Prices are rough hobby-market estimates. Click a part for wiring notes and specs.
Firmware
1// Plant Waterer2// Generated by Wirecraft for the Raspberry Pi Pico (RP2040)3// Prompt: A window herb garden monitor with soil moisture, light sensor and temperature on an OLED display4//5// Wiring, parts and step-by-step assembly live alongside this file.67#include <Arduino.h>8#include <Wire.h>9#include <Adafruit_GFX.h>10#include <Adafruit_SSD1306.h>11#include <DHT.h>1213#define SOILSENSOR_PIN 2614#define RELAY_PIN 215#define LED_PIN 316#define DHT22_PIN 617#define LIGHTSENSOR_PIN 271819int soilSensorMoisture = 0;20Adafruit_SSD1306 oLED(128, 64, &Wire, -1);21DHT dHT22((uint8_t)DHT22_PIN, DHT22);22float dHT22TempC = 0, dHT22Humidity = 0;23int lightSensorLevel = 0;2425void setup() {26 Serial.begin(115200);27 pinMode(RELAY_PIN, OUTPUT);28 digitalWrite(RELAY_PIN, LOW);29 pinMode(LED_PIN, OUTPUT);30 if (!oLED.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("OLED not found")); }31 oLED.clearDisplay();32 oLED.setTextColor(SSD1306_WHITE);33 oLED.setTextSize(1);34 dHT22.begin();35 Serial.println(F("Plant Waterer ready."));36}3738void loop() {39 // --- Read sensors ---40 soilSensorMoisture = analogRead(SOILSENSOR_PIN);41 dHT22TempC = dHT22.readTemperature();42 dHT22Humidity = dHT22.readHumidity();43 lightSensorLevel = analogRead(LIGHTSENSOR_PIN);4445 // --- React ---46 // When the soil reads dry, switch the pump relay on until it recovers.47 if (soilSensorMoisture < 1400) {48 digitalWrite(RELAY_PIN, HIGH);49 } else {50 digitalWrite(RELAY_PIN, LOW);51 }5253 // Refresh the display with live readings54 oLED.clearDisplay();55 oLED.setCursor(0, 0);56 oLED.setCursor(0, 0);57 oLED.print("Soil sensor: "); oLED.println(soilSensorMoisture);58 oLED.setCursor(0, 12);59 oLED.print("DHT22: "); oLED.println(dHT22TempC);60 oLED.setCursor(0, 24);61 oLED.print("Light sensor: "); oLED.println(lightSensorLevel);62 oLED.display();6364 delay(2000);65}661; PlatformIO project for Plant Waterer2[env:pico]3platform = raspberrypi4board = pico5framework = arduino6monitor_speed = 1152007lib_deps =8 adafruit/Adafruit SSD1306@^2.5.109 adafruit/Adafruit GFX Library@^1.11.910 adafruit/DHT sensor library@^1.4.611 adafruit/Adafruit Unified Sensor@^1.1.1412Assembly
- 1
Lay out your workbench
Gather the Raspberry Pi Pico, a half-size breadboard, and a bundle of male-to-male jumper wires. Keep the parts list open — every component below gets its own spot on the breadboard. Don't plug in USB power until the last wire is placed.
- 2
Seat the board and power rails
Run a red jumper from the Raspberry Pi Pico's 3V3 pin to the breadboard's + rail, and a black jumper from GND to the − rail. Every component's power and ground will tap these rails.
- 3
Wire the Soil sensor
Place the Capacitive soil moisture sensor on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: AOUT → GP26. Tip: Calibrate: note the reading in dry air and in a glass of water — your range lives between them.
- 4
Wire the Relay
Place the 1-channel relay module (5 V) on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: IN → GP2. Tip: Most cheap modules are active-LOW — if yours clicks backwards, swap HIGH/LOW in the code.
- 5
Wire the LED
Place the LED (5 mm) + 220 Ω resistor on the breadboard. Power first: CATHODE → − rail. Then signals: ANODE → GP3. Tip: The longer leg is the anode (+). The resistor can go on either leg.
- 6
Wire the OLED
Place the SSD1306 OLED display (128×64, I²C) on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: SDA → GP4, SCL → GP5. Tip: If nothing shows up, try I²C address 0x3D — some modules ship with it.
- 7
Wire the DHT22
Place the DHT22 temperature & humidity sensor on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: DATA → GP6. Tip: Give it 2 seconds between reads — the DHT22 is slow but steady.
- 8
Wire the Light sensor
Place the Photoresistor (LDR) + 10 kΩ divider on the breadboard. Power first: VCC → + rail, GND → − rail. Then signals: SIG → GP27. Tip: LDR to VCC, 10 kΩ to GND, read the midpoint. Brighter light = higher reading.
- 9
Double-check before power
Trace every wire against the diagram once more — 18 connections in total. The classic mistakes: swapped power and ground, and off-by-one rows on the breadboard. Thirty seconds of checking saves a component.
- 10
Flash the firmware
Open the exported folder in VS Code with the PlatformIO extension (free), plug in the Raspberry Pi Pico over USB, and hit Upload. PlatformIO fetches the libraries listed in platformio.ini automatically. Prefer the Arduino IDE? Copy src/main.cpp into a new sketch and install the same libraries from the Library Manager.
- 11
Bring it to life
Open the Serial Monitor at 115200 baud to watch live readings. When the soil reads dry, switch the pump relay on until it recovers. Adjust the thresholds at the top of the sketch to match your environment.
Heads-up from the engine
- Relay prefers 5 V but Raspberry Pi Pico tops out at 3.3 V — most modules still work, but check yours.