Let’s explore how you can use a transistor and a motor to generate wind power using a Raspberry Pi Pico.

What Is Required to Get Started?

The following items are included with the Kitronik Inventor’s Kit for Raspberry Pi Pico. They’re fairly common components, though, so can easily be sourced separately.

Fan blade Motor Breadboard terminal connector Breadboard 2. 2kΩ resistor (bands will be red, red, red, gold) 5x male-male jumper wires Transistor—required to supply more current to the motor than Pico’s GPIO pins can supply

Take a look at our overview of the Kitronik Inventor’s Ki for Raspberry Pi Pico in order to expand your technical knowledge for future experimentation. You’ll need a Pico with GPIO pin headers attached for this project; check out how to solder header pins on a Raspberry Pi Pico.

It includes tips on soldering best practices, so you can ensure that your GPIO pin headers are connected well to the Pico board the first time around.

How to Connect the Hardware

The wiring isn’t complex; however, there are a few steps where you’ll need to be certain that your pins are connected correctly With that in mind, let’s break down how the components are being connected between the Raspberry Pi Pico and your breadboard.

The Pico’s GP15 pin will need to be connected to one end of the resistor. A GND pin on the Pico will be routed to the negative rail on the breadboard. Place the transistor in front of the negative side of the motor’s terminal connector and route a wire from the negative side of the transistor to the negative rail of the breadboard. Double-check that the wiring is lined up correctly with the motor’s terminal connector (this is important). The Pico’s VSYS pin will need to connect to the positive rail on the breadboard. This will ensure that 5V of power is being delivered, via the transistor, to the motor (versus other Pico pins with only 3. 3V).

While you’re making your final wiring checks, make sure that a jumper wire is connected from the breadboard’s positive rail to the positive side of the motor’s terminal connector. Additionally, the other end of the resistor will need to be connected to the middle pin of the transistor. If it’s not obvious yet, be sure to connect the negative and positive wires correctly from the terminal connector to the motor as well.

Exploring the Code

First, you’ll need to download the MicroPython code from the MUO GitHub repository. Specifically, you’ll want to retrieve the motor.py file. Follow our guide to getting started with MicroPython for details on using the Thonny IDE with Raspberry Pi Pico.

When run, the code will tell the motor to spin the fan, gradually increasing speed to the maximum and then, after a short pause, reducing the speed until it stops again. This will be repeated continually until you stop the program.

At the top of the code, importing the machine and time modules enables you to make use of them in the program. The machine module is used to assign GP15 as the output pin for the motor, via the transistor, using PWM (pulse-width modulation) to set its speed. The time module is used to create delays in the program operation when we need them.

Try running the code. The fan will take a few seconds to spin up and start rotating. A finite for loop gradually increases the output value to the motor from 0 to 65535 (or rather, just below that) in steps of 100. A very short delay of 5 milliseconds is given (with time.sleep_ms(5)) between each speed change during the loop. Once the loop is complete, a time.sleep delay of one second is set before the next loop starts.

In the second for loop, the step value is set to -100, to gradually reduce the output value to the motor. The motor will slow down gradually from full speed until it stops completely (at 0). After another time.sleep delay of one second, the first for loop is executed again, since they are both within a while True: infinite loop.

That’s really all that’s involved in using a transistor and code to run your fan motor. Keep in mind that this code will loop forever. So, you’ll need to press the stop button in your Thonny IDE in order to stop the motor and fan cycling.

Where Will the Wind Take You Next?

Adding extra elements, such as a 7-segment display, to this experiment will reward you with an understanding of how wind turbines use kinetic energy to convert wind into electrical power.

Another project that you could move toward is to set up a home-based weather station that monitors outdoor conditions. In addition, you’ll find other interesting projects such as a wind and airspeed indicator that you can create with your Raspberry Pi Pico.

Using this foundational knowledge, which experiments will you soar to next? Do you have a project in mind? If you hesitate too long, you may run the risk of your mind (and wind) changing direction.