/r42_Gardensensor_MicroPython

MicroPython based MQTT-Sensor on Raspberry Pi Pico W

Primary LanguagePythonMIT LicenseMIT

reset42 Logo

reset42 Gardensensor

Plug & Play Wi-Fi garden sensor for makers, tinkerers & automation fans โ€“ powered by Raspberry Pi Pico W, BME280, VEML7700 and MQTT.
Runs on MicroPython โ€“ local, modular, no cloud required.


๐ŸŒฑ Features

  • ๐Ÿ“ถ WiFi capable โ€“ including fallback network and optional static IP
  • ๐ŸŒก๏ธ Real-time data: temperature, humidity, pressure, light (Lux)
  • ๐Ÿ”„ Test & demo mode: simulate sensor values and MQTT publishing via config.py (ideal for dev & unit tests)
  • ๐Ÿ” Synchronous main loop for maximum stability and easy debugging
  • ๐Ÿงฉ Flexible MQTT payload format: fields & order configurable
  • ๐Ÿ“ก MQTT support for logging, smart home & automation
  • ๐Ÿ’ก Status LED for error indication
  • ๐Ÿ› ๏ธ Fully modular, open source & easily extendable (MIT license)

๐Ÿ“˜ Deutsche Version

๐Ÿ‘‰ For the German version, see: README_DE.md


๐Ÿ”ง Hardware

  • Raspberry Pi Pico W (MicroPython compatible)
  • BME280 (I2C โ€“ temperature, humidity, pressure)
  • VEML7700 (I2C โ€“ light intensity in Lux)
  • Status LED (controllable, optional)
  • Optional additional I2C sensors

โš™๏ธ Installation

  1. Flash MicroPython
    Download the matching .uf2 image for Pico W from
    ๐Ÿ‘‰ micropython.org/download/rp2-pico-w

  2. Upload files

    • Copy everything from src/lib/ to the root directory of the Pico W
      (e.g., via Thonny, rshell, ampy, or WebREPL)
    • Also copy main.py to the root directory
  3. Edit config.py

    • Wi-Fi credentials, MQTT broker settings, sensor GPIOs etc.
    • Configure sensor modes ("active", "dummy", "inactive") and MQTT fields
  4. Go!

    • Reboot โ†’ main.py starts automatically
    • Status LED blinks on error (see Troubleshooting)

๐Ÿงพ Sample config.py

See src/lib/config.py in the repo for details:

SSID = "MyWiFi"
PASSWORD = "supersecret"
STATIC_IP = ""  # leave empty for DHCP

MQTT_BROKER = "192.168.1.50"
MQTT_PORT = 1883
MQTT_CLIENT_ID = "sensor_indoor"

# Sensor & MQTT test modes
VEML_MODE = "dummy"      # "active", "dummy", "inactive"
BME_MODE  = "inactive"   # "active", "dummy", "inactive"
MQTT_MODE = "active"     # "active", "dummy", "inactive"

# MQTT Payload Fields
MQTT_PAYLOAD_FIELDS = [
    "date",
    "time",
    "temp",
    "pressure",
    "humidity",
    "lux",
]

๐Ÿ“Œ Default Pinout

Component SDA SCL PWR (Power)
VEML7700 GP0 GP1 GP15
BME280 GP2 GP3 GP14
Function Pin
Onboard LED "LED"
VEML Reset GPIO GP15

๐Ÿง  Architecture Overview

  • main.py: Main loop control (WiFi, MQTT, sensors, LED)
  • lib/:
    • wifi.py: Connects to primary or fallback WiFi
    • mqtt.py: Handles broker connection, JSON publishing, dummy mode
    • sensors.py: Reads BME280 & VEML7700 (real or dummy mode)
    • leds.py: Status LED control (blinking patterns)
    • config.py: Full configuration (WiFi, MQTT, sensors, payload fields)
    • state.py: Return codes (SUCCESS, FATAL_ERROR, ...)

๐Ÿšจ Troubleshooting

Problem LED Blinks Description
WiFi Error 1ร— slow No connection to WiFi
MQTT Error 2ร— medium Broker not reachable
Sensor Error 3ร— fast Sensor not responding

๐Ÿ–ผ๏ธ Case, STL & Assembly

  • Case files (STL) and full assembly instructions coming soon!
  • This is a "maker" project โ€“ feel free to contribute mechanical ideas via issue or PR.

๐Ÿ”’ License

reset42 Gardensensor is open source and licensed under the MIT license.
Private & commercial use allowed โ€“ see LICENSE.


Project status: actively maintained โ€“ more sensors, web interface & sleep mode planned.
STL files and assembly guide will follow soon.

Questions, ideas or feedback? โ†’ reset42.de