Arduino UNO R4 - Control Pump
In this guide, we will learn how to connect an 12V pump to Arduino UNO R4 and how to program an Arduino UNO R4 to control the pump. This tutorial will help you build systems like irrigation for plants, aquariums, or water refilling stations.
You can put a relay or a MOSFET module between the Arduino UNO R4 and the pump. A relay only starts and stops the pump. A MOSFET module does the same, and it can also set the pump speed, so you get a strong flow or a gentle one. Both ways are covered below.

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables STEM V4 IoT Starter Kit (Arduino included) | |
| 1 | × | DIYables STEM V4B IoT Starter Kit (Arduino included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of 12V Pump
Pinout

A 12V pump typically has two pins.
- Connect the negative (-) pin (black) to the GND of the DC power supply.
- Connect the positive (+) pin (red) to the 12V of the DC power supply.
How to Control Pump
If you use a 12V power supply for a 12V pump, it will works. To control the pump using Arduino UNO R4, a relay should be placed between the Arduino UNO R4 and the pump. The Arduino UNO R4 can control the pump through the relay. If you're unfamiliar with relays (their pinout, operation, programming, etc.), you should study them in the Arduino UNO R4 - Relay tutorial.
New to the MOSFET module? The Arduino UNO R4 - MOSFET Module tutorial explains what it is and how it works.
Relay vs MOSFET Module for a 12V Pump
| Relay | MOSFET Module | |
|---|---|---|
| Pump control | start and stop only | start, stop, and change the flow (PWM) |
| Switching sound | clicks | none |
| Switching time | slow (milliseconds) | very fast |
| Wear | the contacts get old with use | no moving parts to wear |
| Works with | AC and DC pumps | DC pumps only |
| Pump supply voltage | what the relay is rated for | 6V or higher |
| Isolation | yes | yes, with a PC817 optocoupler |
| Choose it for | AC pumps or plain ON/OFF | DC pumps where you want to set the flow |
If you only need to fill a tank, the relay is enough. If you want to water plants slowly or fill a glass without splashing, the MOSFET module gives you better control. AC pumps need the relay.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
Arduino UNO R4 Code
The code below repeatedly switches the pump ON for five seconds and then OFF for five regimes.
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Connect the pump to Arduino UNO R4 via a relay according to the provided diagram.
- Connect the Arduino Uno R4 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Copy and paste the provided code into the Arduino IDE.
- Press the Upload button in the Arduino IDE to send the code to the Arduino UNO R4.
- Check the state of the pump.
Code Explanation
The explanation is in the comments of the Arduino code above.
How to Control Pump Flow with MOSFET Module
This time the pump is driven by a MOSFET module. Besides ON and OFF, the Arduino UNO R4 can now make the pump push more water or less water.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Uno R4 and other components.
| Arduino UNO R4 / Power | MOSFET Module |
|---|---|
| Pin 9 | PWM |
| GND | GND |
| 12V adapter + and pump + (red) | + (both wires share it) |
| Pump − (black) | LOAD |
| 12V adapter − | − |
The pump has a motor inside. Add a 1N4007 or 1N5819 diode across the pump to protect the module: stripe (cathode) on the pump + wire, the other end on the pump − wire.
Arduino UNO R4 Code
The pump runs at full flow for 2 seconds and stops for 2 seconds. Then the flow grows from 10% to 100%, one step every half second, and goes back down to 0%.
Detailed Instructions
- Prepare the Arduino IDE in the same way as the relay Quick Steps above.
- Connect the pump, the MOSFET module and the Arduino UNO R4 as in the diagram. Put the pump in water before you power it.
- Upload the code to the Arduino UNO R4, then plug in the 12V adapter.
- Open the Serial Monitor (9600 baud).
- Look at the water coming out of the tube. It gets stronger, then weaker. At a very low power, the pump may not move water at all.
Remember: the MOSFET module only switches DC, and the pump supply must be at least about 6V. Keep the relay for AC pumps.
Video Tutorial
Challenge Yourself
- Create an automated watering system with Arduino UNO R4, a soil moisture sensor, and a pump.
- Build an automatic refill system for water using Arduino UNO R4, a water level sensor, and a pump.