wirecraft

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

Mini Map
power
ground
data
signal
analog

Parts

PartRefsQtyEst.
Capacitive soil moisture sensorSoilSensor1$1.80
1-channel relay module (5 V)Relay1$1.20
LED (5 mm) + 220 Ω resistorLED1$0.15
SSD1306 OLED display (128×64, I²C)OLED1$3.20
DHT22 temperature & humidity sensorDHT221$4.50
Photoresistor (LDR) + 10 kΩ dividerLightSensor1$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

src/main.cpp
1// Plant Waterer
2// 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 display
4//
5// Wiring, parts and step-by-step assembly live alongside this file.
6
7#include <Arduino.h>
8#include <Wire.h>
9#include <Adafruit_GFX.h>
10#include <Adafruit_SSD1306.h>
11#include <DHT.h>
12
13#define SOILSENSOR_PIN 26
14#define RELAY_PIN 2
15#define LED_PIN 3
16#define DHT22_PIN 6
17#define LIGHTSENSOR_PIN 27
18
19int soilSensorMoisture = 0;
20Adafruit_SSD1306 oLED(128, 64, &Wire, -1);
21DHT dHT22((uint8_t)DHT22_PIN, DHT22);
22float dHT22TempC = 0, dHT22Humidity = 0;
23int lightSensorLevel = 0;
24
25void 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}
37
38void loop() {
39 // --- Read sensors ---
40 soilSensorMoisture = analogRead(SOILSENSOR_PIN);
41 dHT22TempC = dHT22.readTemperature();
42 dHT22Humidity = dHT22.readHumidity();
43 lightSensorLevel = analogRead(LIGHTSENSOR_PIN);
44
45 // --- 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 }
52
53 // Refresh the display with live readings
54 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();
63
64 delay(2000);
65}
66
platformio.ini
1; PlatformIO project for Plant Waterer
2[env:pico]
3platform = raspberrypi
4board = pico
5framework = arduino
6monitor_speed = 115200
7lib_deps =
8 adafruit/Adafruit SSD1306@^2.5.10
9 adafruit/Adafruit GFX Library@^1.11.9
10 adafruit/DHT sensor library@^1.4.6
11 adafruit/Adafruit Unified Sensor@^1.1.14
12

Assembly

  1. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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.