Skip to content

Electronic Garden with Raspberry Pi

Create a spinning electronic flower garden using Raspberry Pi, an Explorer HAT, and a geared motor.

  • Raspberry Pi
  • Beginner
  • 45–60 minutes
  • 5 steps

Shop this project

Cart

You'll need

Prices from vilros.com. Tax and shipping at checkout.

Before you start, you'll need

  • Raspberry Pi (any model with GPIO)
  • Explorer HAT Pro
  • Wheel (for the motor shaft)
  • Geared motor (12V 80RPM recommended)
  • Jumper leads (male-to-female)
  • Colored construction paper or felt
  • Scissors, markers, adhesive, push pin

Install Explorer HAT software

About 5 minutes

Install the Python library for Explorer HAT.

  1. Power off your Raspberry Pi.
  2. Push the Explorer HAT onto the GPIO pins.
  3. Power on your Raspberry Pi.
  4. Open a Terminal and run the command to install the Explorer HAT library.
  5. Test the installation by running the Python import command.
Type in the Terminal
sudo apt-get install python3-explorerhat

This installs the Explorer HAT library for Python 3.

You should see

The library installs successfully. Running 'python3 -c "import explorerhat"' produces no errors.

Connect the motor

About 10 minutes

Attach the motor and wheel to the Explorer HAT.

  1. Push the motor shaft halfway into the wheel.
  2. Attach the female ends of 2 jumper leads to the motor's prongs.
  3. Connect the male ends to Motor 1+ and Motor 1- on the Explorer HAT.

You should see

The motor is securely connected to the Explorer HAT terminals.

Decorate your garden

About 15 minutes

Create colorful flower decorations for the spinning wheel.

  1. Cut flower shapes out of construction paper or felt.
  2. Optionally, make origami pinwheels or draw bees and butterflies.
  3. Arrange your decorations on the wheel using adhesive.
  4. Secure everything with a push pin through the center of the wheel.
  5. Think about how your design will look when it spins!

You should see

Your wheel is decorated with bright, garden-themed designs.

Write the Python script

About 10 minutes

Program the motor to spin for 10 seconds.

  1. Open Python 3 (IDLE) from the Programming menu.
  2. Create a new file and save it as 'garden.py'.
  3. Import the Explorer HAT library and the sleep function.
  4. Add code to spin the motor forward at full speed for 10 seconds, then stop.
python
import explorerhat
from time import sleep

explorerhat.motor.one.forward(100)
sleep(10)
explorerhat.motor.one.stop()

The motor speed is set to 100 (full power). You can reduce this to slow the spinning.

You should see

The script runs and the motor spins for 10 seconds, then stops.

Add button control

About 5 minutes

Trigger the motor with an Explorer HAT button.

  1. Wrap your motor code in a function called 'run_motor'.
  2. Add a line to trigger the function when button 1 is pressed on the Explorer HAT.
  3. Make sure this line is at the left margin (not indented).
  4. Save and run your script.
  5. Press button 1 on the Explorer HAT to start the motor.
python
import explorerhat
from time import sleep

def run_motor():
    explorerhat.motor.one.forward(100)
    sleep(10)
    explorerhat.motor.one.stop()

explorerhat.touch.one.pressed(run_motor)

The button line must not be indented. Add a signal.pause() at the end if you want the script to wait for button presses.

You should see

Pressing button 1 on the Explorer HAT starts the motor.

It didn't work
  • Motor doesn't spin.

    Check the motor wiring to Motor 1+ and Motor 1-. Verify the Explorer HAT is properly seated on the GPIO pins. Test with a different motor if available.

What to do next

Stuck? Contact Vilros Support with your board model and what you see on screen.