In this video, we'll be learning how to use a water pump with a Raspberry Pi Pico to pump liquids in your maker project. We'll be looking at two different types of pumps and when you should use each one, how to wire up a motor driver, pump, and Pico, as well as how to code it all up. Let's get into it.
There are a lot of different types of pumps out there, but in this video, we'll be looking at two which will cover a lot of use cases for your maker projects: the peristaltic and the submersible.
This is a submersible pump, and as the name suggests, it's placed inside the liquid you want to pump. You power it, and it starts pumping. They are cheap, simple to use, and can pump lots of liquids in a short amount of time. They have a high flow rate. The one we're using in this video is not crazy high, but you can get much bigger ones that are more powerful. If you've ever taken a look at an aquarium filter or a water fountain pump, chances are it's going to be something like this. It's just an impeller inside that spins and pushes water through the pump.
They do have some downsides, though. First of all, they need to be submerged. Even if I put the inlet hose here into water and turn it on, it's not able to suck anything up. It has to be in the liquid to pump it. And if any air gets into the pump, you may need to jiggle it because it kind of clogs the pump. They are also designed to be cooled by the water around them, so if you run it in air for too long, you may burn out the motor.
The other pump we're using is a peristaltic pump, which is a pretty cool design. Inside is a bunch of rollers that spin around and squeeze the liquid through a tube, almost like how you would squeeze out a freeze pop or Popsicle, or whatever you call this thing. We call them Zoopa Doopas here in Australia. That's not a lie. Funny name.
Let's start with the downsides of this. First of all, it has a much lower flow rate. This pump here runs at about one liter a minute, and the peristaltic at about 50 milliliters a minute. They're also a bit more expensive, and they typically aren't waterproof, as you can see, unlike the submersible one. However, they are accurate and precise. If you run this for 10 seconds and then you run it again for another 10 seconds, chances are you're going to get about the same amount of liquid. It's also non-contact, which means that the motor doesn't really touch the liquid you're pumping. The liquid is just being squeezed through the tube that comes in here and goes out there. There's no metal blades or unknown plastic parts touching the liquid. It's also self-priming, which means that we can hang it out of water, and even if there's air in the line, it will suck up the water to the pump. And the little cherry on top is that the flow is reversible. The submersible and a lot of other pumps can only move water in one direction. A peristaltic, though, drive it backwards, and the water goes in the opposite direction.
So if you're looking for a cheaper pump that has a higher flow rate, maybe look at something like the submersible. But if your project needs something that can pump a more accurate amount of liquid or you need something that might be food safe or pump in both directions, maybe look at a peristaltic. But beware, lower flow rate.
And now that you know which one your project needs, let's go and learn to use them. To follow along, you will need a water pump. We will be using these specific peristaltic and submersible pumps. You'll find links to everything in the written guide below, but you can also source your own. Just be aware that your setup might need to change a bit depending on what you use. You also need a suitable motor driver. We're using the Makerverse motor driver here, which works with the pumps we have selected. If you're using a different pump, though, make sure that your motor driver is suitable for the voltage and maximum current of your pump. You're also going to need a Pico to control this all and jumper wires to connect everything as well. On top of this, you're also going to need some sort of power supply. We're just going to be powering it off the Pico, but you could run it off a battery or external power supply, whatever really. Just ensure that it is suitable to power your motor.
Alright, let's wire it up. We're going to be using the peristaltic as our example, but wiring up the submersible, basically any DC motor pump, is going to be pretty much the same process. To start with, I've gone ahead and soldered some pin headers onto my motor driver, as well as some screw terminals. Both of these should come with your motor driver. Now to control our motor driver with the Pico, we're going to need two pins: one to control the direction and the other one to control the speed of the motor. On the Pico, we can use pretty much any GPIO pins for this, but in this guide, we'll connect pin zero to the direction of motor B pin and pin one to the PWM speed control of motor B pin. And then with most modules, we're going to go ahead and connect the ground pin of the Pico to the ground pin of our motor driver.
Now let's go ahead and connect the motor. There is a good chance that you might need to solder some wires onto the motor before using it. An important note here is that motors have magnets in them, and excessive heat can damage them and stop your motor from functioning. So don't hold your soldering iron to them for too long. You just want to avoid them from getting too hot for too long. And it's also a smart idea to use some heat shrink or electrical tape to cover up those terminals. If you're using a submersible pump, though, chances are it's already got a waterproofed wire connected to the motor. Go ahead and screw the motor wires into the B plus and B negative terminals of your motor driver. If you messed up the polarity here, that's no biggie, though. You can always just reverse them later.
Finally, we'll connect our power supply. Ensure that you don't mix up the polarity here. I've just gone ahead and stripped some of the ends of some jumper wires and connected it to VBUS and a ground pin of the Pico. VBUS uses the power coming from the USB, which will be five volts and up to two amps, depending on what you plug it into. These are just some thicker jumper wires that I'm using here that support up to two amps, which is more than enough for our motors. And that is all we need. Let's head on over to Thonny and code this up.
Alright, we are in Thonny, which is what we're going to be using to code up our Pico. We're going to go ahead and paste in the demo code that you can find on the written guide linked below. If you've never used the Pico with Thonny or you just need a quick refresher, we'll have a short guide linked below, which is part of a comprehensive Pico course if you want to check that out.
The code to operate this is actually pretty straightforward as we're only controlling two pins here. We start by importing pin PWM and time, which are the libraries we'll be using. Then we're going to go ahead and set up a digital on/off pin and a PWM pin, which is just zero and one, which we used here. Whatever you're using, you should set it up for your pins. Now, when working with PWMs, we can't just specify a percentage. We need to specify 65,535, which is the maximum PWM value that's going to give us 100%. We're just assigning it here to a variable so we can call upon it more easily.
Then in our while true loop, we'll set pin zero, which is the on/off pin, to one. This is what sets our direction. Then we're going to set the duty cycle on our PWM to 100%. Then we'll sleep for five seconds, so we'll run the motor for five seconds, and then we'll set the PWM to zero, which will turn the motor off. After a couple more seconds of sleep, we'll set pin zero to zero instead of one, which reverses the direction on the motor driver. We'll set the PWM back to maximum, and we'll just keep looping this over and over just as a nice little example to see what happens.
Alright, I'm just going to go ahead and put on some of our tubing as well. Just cut it to random length just so we can try it out like so. I've also got two cups of water down here just to test with. Of course, be very careful with water, electronics in your studio, don't spill it. Just be very vigilant.
Alrighty, so I am going to put one cup there and just put our tubes in like so. I forgot which one's the inlet and the outlet, so we're just going to see what happens. I'm going to go ahead and select our COM port and then click run. If we take a look at that, we are now pumping water. If I put that back in here, the motor's about to reverse. As you can see, our peristaltic is able to pump in both directions just by reversing the direction of the motor.
Alrighty, I'm just going to go ahead and unplug our Pico for a second. We'll let that drip a bit. I'm going to swap out our peristaltic for our submersible pump. I should be able to just swap them over as well because they run on the same voltage and the motor driver and power.
Makers love reviews as much as you do, please follow this link to review the products you have purchased.