Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
👉 Ready to explore and create with us? Click [here] and join today!
Lesson 31: Centrifugal Pump
In this lesson, you will learn how to operate a centrifugal pump using the Raspberry Pi Pico W and an L9110 motor control board. We’ll guide you through the process of configuring two PWM (Pulse Width Modulation) pins to control the motor. You’ll set up the pump to run for 5 seconds and then turn off. This practical exercise offers a valuable opportunity to delve into motor control mechanisms and PWM signals, crucial in microcontroller programming.
Required Components
In this project, we need the following components.
It’s definitely convenient to buy a whole kit, here’s the link:
Name |
ITEMS IN THIS KIT |
LINK |
|---|---|---|
Universal Maker Sensor Kit |
94 |
You can also buy them separately from the links below.
Component Introduction |
Purchase Link |
|---|---|
Raspberry Pi Pico W |
|
- |
|
- |
|
Wiring
Code
from machine import Pin, PWM
import time
pump_a = PWM(Pin(26), freq=1000)
pump_b = PWM(Pin(27), freq=1000)
# turn on pump
pump_a.duty_u16(0)
pump_b.duty_u16(65535) # speed(0-65535)
time.sleep(5)
# turn off pump
pump_a.duty_u16(0)
pump_b.duty_u16(0)
Code Analysis
Importing Libraries
The
machinemodule is imported to interact with the GPIO pins and PWM functionalities of the Raspberry Pi Pico W.The
timemodule is used for creating delays in the code.
from machine import Pin, PWM import time
Initializing PWM Objects
Two PWM objects,
pump_aandpump_b, are created. They correspond to GPIO pins 26 and 27, respectively.The frequency for PWM is set to 1000 Hz, a common frequency for motor control.
pump_a = PWM(Pin(26), freq=1000) pump_b = PWM(Pin(27), freq=1000)
Turning on the Pump
pump_a.duty_u16(0)sets the duty cycle ofpump_apin to 0, whilepump_b.duty_u16(65535)sets the duty cycle ofpump_bpin to 65535, running the motor at full speed. For more details, please refer to the working principle of L9110.The pump runs for 5 seconds, controlled by
time.sleep(5).
# turn on pump pump_a.duty_u16(0) pump_b.duty_u16(65535) # speed(0-65535) time.sleep(5)
Turning off the Pump
Both
pump_aandpump_bare set to a duty cycle of 0, stopping the motor.# turn off pump pump_a.duty_u16(0) pump_b.duty_u16(0)