H2O Helper: A Simple Water Sensor for Your Christmas Tree

MicroCenterMaker
edited January 2 in Maker

H2O Helper: A Simple Water Sensor for Your Christmas Tree

In this guide, we undertake a technical exploration of the Raspberry Pi Pico, utilizing the MicroPython Programmer Starter Kit. This project is a tutorial for those looking to understand microcontroller applications and circuit design.

We will cover three core aspects:

  1. Thonny IDE Setup: Initial steps include setting up Thonny, a robust IDE for Pico programming. This section details installation, configuration, and a basic LED blink test to verify the setup.
  2. Breadboard Circuit Prototyping: Focus shifts to constructing a water-level sensor circuit using a breadboard. This part emphasizes the practical application of circuit theory and component functionality.
  3. MicroPython Scripting: The final segment dives into writing and uploading a MicroPython script to the Pico. It encompasses code creation for sensor data interpretation and auto-execution of the script on device boot.

Setting Up Thonny for the Raspberry Pi Pico

The Raspberry Pi Pico is a versatile microcontroller that offers a perfect blend of power and simplicity for beginners and seasoned enthusiasts in the world of microcontrollers. One needs a reliable and user-friendly Integrated Development Environment (IDE) to harness its potential, and Thonny stands out as an ideal choice.

Downloading and Installing Thonny

The journey begins with downloading and installing Thonny. You can find a comprehensive guide on the Raspberry Pi Projects website (https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico), which offers a step-by-step tutorial tailored for the Pico platform. This resource simplifies the process, ensuring a smooth setup for users of all skill levels.

Introduction to Breadboarding

A breadboard is an essential tool for prototyping electronic circuits. It allows you to create and test circuit designs without soldering, making it easy to modify and troubleshoot. Breadboards feature rows of interconnected holes where you can insert components like wires, resistors, LEDs, and microcontrollers.

(https://erc-bpgc.github.io/handbook/electronics/Basic_Electronic_Components/breadboard/)]

Understanding the Water Level Sensor Circuit

The circuit uses two LEDs to indicate the water level: green for an adequate level and red for a low level. This circuit utilizes the Raspberry Pi Pico and a set of components to detect water levels through a simple probe.

Components of the Circuit

  • Raspberry Pi Pico
  • Breadboard
  • Jumper wires
  • 2 LEDs (one green, one red)
  • 3 Resistors (220 Ω for each LED, 10k Ω for the sensor)
  • Two pieces of exposed wire (for the probe)

Circuit Assembly Instructions

  • Raspberry Pi Pico Setup:
  1. Place the Raspberry Pi Pico on the breadboard, ensuring the micro USB port is accessible. 
  • LED Connections:
  1. Green LED (Good Water Level Indicator):
  2. Connect the anode (longer leg) to a GPIO pin (e.g., GP15) on the Pico.
  3. Connect the cathode (shorter leg) to one end of a 220 Ω resistor.
  4. Connect the other end of the resistor to a ground (GND) pin on the Pico.


  1. Red LED (Low Water Level Indicator):
  2. Follow the same steps for the red LED using a different GPIO pin (e.g., GP14). 


  • Water Sensor Probe:
  1. Connect one wire (Probe 1) to a GPIO pin (e.g., GP28) on the Pico and add a 10k Ω pull-up resistor between this GPIO pin and the 3.3V pin.
  2. Connect the other wire (Probe 2) directly to a ground (GND) pin.


Functioning of the Circuit

When the water level is sufficient, the circuit completes through the water, allowing current to flow and illuminating the green LED. The circuit breaks when the level is low, triggering the red LED to light up, indicating a low water level.

Writing and Uploading the Code onto the Raspberry Pi Pico

Creating a New Script in Thonny

To begin programming your Pico, open Thonny and start a new script:

  1. Launch Thonny on your computer.
  2. Click 'File' in the menu, then select 'New'. This opens a new script window.

The MicroPython Script for the Water Level Sensor

Copy the following MicroPython script into your new script window in Thonny. This script controls the LEDs based on the water level detected by the sensor probe.

Saving and Running the Script on the Pico

To save the script to your Pico:

  1. Ensure your Pico is connected to your computer via USB.
  2. In Thonny, click 'File,' then 'Save As.'
  3. In the dialog box, choose your Pico from the list of locations.
  4. Name your file (e.g., 'watersensor.py') and click 'Save.'

To make the script run automatically when the Pico is powered on:

  1. Name the script to 'main.py' before saving it onto the Pico. The Pico looks for a file named 'main.py' to run on boot.

Final Steps and Testing

After saving the script as 'main.py' on your Pico, disconnect and reconnect the Pico to power. The script should now automatically run, controlling the LEDs based on the water level detected by your sensor.

Advancing Your Skills with the Raspberry Pi Pico and MicroPython

As we continue to explore the expansive capabilities of the Raspberry Pi Pico, we invite you to join us in this ongoing series of technically challenging and rewarding projects. Each upcoming project is an opportunity to refine your hardware assembly and MicroPython programming skills.

Take this step towards mastering microcontroller technology with the Raspberry Pi Pico. Engage with us in future projects to expand your knowledge and contribute to the evolving landscape of microcontroller-based solutions.

We love seeing what our customers build

Submit photos and a description of your PC to our build showcase

Submit Now
Looking for a little inspiration?

See other custom PC builds and get some ideas for what can be done

View Build Showcase

SAME DAY CUSTOM BUILD SERVICE

If You Can Dream it, We Can Build it.

Services starting at $149.99