In this video, we'll be learning how to use a water pump with an Arduino to pump liquids in your maker project. We'll be looking at two different types of pumps, when you would use them, how to wire up a motor driver and pump to the Arduino, as well as how to program it all. Let's get into it.
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 I 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 Popeyes 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'll need a water pump. We'll be using these specific peristaltic and submersible pumps, and you'll find links to everything in the written guide below. You can also use your own different pump, whatever pump you really want, but just be aware that your setup might change depending on what you pick. You'll also need a suitable motor driver. We're using the Makerverse motor driver here, which works with the pumps that we've selected. If you are using a different pump, make sure that the motor driver is suitable for the voltage and maximum current of your pump. You're also going to need an Arduino to control this all and some jumper wires to connect everything together. Finally, you're going to need some sort of a power supply as well. This could be a battery, a benchtop supply, or even a USB wall charger. The submersible pump is actually low enough power to run directly off the Arduino, but the peristaltic is probably going to need an external power supply. We'll look at that when we get to it though.
Alright, let's wire this all up. I've gone ahead and soldered some pin headers onto my motor driver as well as the screw terminals. Both of those should come with your motor driver. There's a good chance you'll also 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 those magnets. So don't hold your soldering iron to them for too long. It's also a smart idea to use some heat shrink or electrical tape to cover those terminals. If you are using a submersible pump though, chances are you've already got a waterproofed wire connected to your motor.
To control the motor driver with the Arduino, you're going to need only two pins. One to control the direction and the other to control the speed. That speed one has to be a PWM pin though. We can really use any combination of pins here that we want. But for this guide, we're going to connect pin two to the direction of motor B and pin three to the PWM speed control of motor B as well. We're also going to need to connect one of the Arduino's ground pins to the ground pin of the motor driver. This is so that they both can agree on what zero volts actually is. Now let's go ahead and screw those motor wires into the B plus and B minus terminal of the motor driver. If you mess up the polarity here, it's no biggie. You can just reverse them later. Also, be careful not to over-tighten your screw terminals here as you can damage them. Just nip them up to the point that they're just tight enough to hold in place.
We're going to start by using the submersible pump here, which can just be powered off the Arduino. In a bit, we'll set up the peristaltic pump, which is going to need an external power source. To get power from the Arduino, I've just gone ahead and stripped the ends of some jumper wires and connected it from the five-volt and ground pin of the Arduino to the power input of the motor driver. Please note that this five-volt power pin on the Arduino has a maximum current output of 500 milliamps, which is not very much in the world of motors. Our submersible pump is only going to pull about 300 milliamps, so we're fine here. And with that, we have everything wired up. So let's head on over to the Arduino IDE and program this.
Alrighty, ensure you have your board plugged into your computer and it's correctly selected in the IDE. We're going to go ahead and paste in the demo code, which you can find on the written guide linked below. This code is actually pretty straightforward. There's not much actually going on here. To start, we're going to assign some constants, just some pin numbers to actual pin names, just to make it easy to actually call and use those pins. Then in our void setup, we're going to go ahead and set up our direction pin, which is just a simple high-low on-off digital output pin. Note here that we don't actually need to set up our PWM pin as an output in our void setup. When we call it, it actually goes through and sets it up for us. You can set it up if you really want to be good-mannered here, but it's not entirely necessary.
Then in our main loop here, we start by setting the direction pin to high, which is going to make the motor go forward. Then we set our PWM pin to 255, which is 100%. Remember that it doesn't go from 0 to 100, it goes from 0 to 255. Then we're going to delay or sleep for 500 milliseconds, and this is just going to turn the motor on to full speed forward for 5 seconds. After that, we're going to set the PWM to 0, which is going to stop the motor. We're going to delay it for 2000 milliseconds, which is going to stop it from running for 2 seconds. Then we're going to do exactly the opposite. We're going to set it to low and 255, which is going to put it full speed in reverse. We're going to make that run for 2 seconds, and then we're going to stop it for another 2 seconds. So we've got a system kind of just going backwards and forwards here to really test what goes on.
Alrighty, to test this, I'm just going to use some cups of water, and obviously be careful with water around electronics. Always be prepared for a spill and minimize your risks. Alright, I'm going to go ahead and dunk that into water and compile and upload that code. We should see we have our water pumping like so. As you can see, quite a decent flow rate for such a small pump. Just be aware that when the motor goes in reverse, it's actually pumping forward, but not as effectively. So ensure you've got that correct. And as you can see, if I dip the tip into it, it's not really going to be able to pump. It needs to be fully submerged for it to be able to do so.
Alrighty, that is enough of that. Let's unplug you. Try not to spill water everywhere. Let's go ahead and unscrew our submersible real quick. I'm just going to go ahead and screw in our peristaltic. Now we are in a bit of a gray area here. That...
Makers love reviews as much as you do, please follow this link to review the products you have purchased.