Background
Submersible pumps are useful for controlling water flow. Paired with an Arduino microcontroller, these pumps can automate the flow distribution process, which can be useful for applications such as aquariums, fountains, and systems for irrigation, refilling and aeration. This tutorial shows how to use an Arduino Uno to control a submersible pump. The first case shows how to control flow based on simple timed intervals. The second case shows how to control flow based on feedback from a sensor.
Figure 1 shows a diagram of a common submersible pump. The mini pump used in this tutorial is a low voltage, low power pump. However, like most motors, pumps draw larger currents than the 40mA the Arduino output pins can supply. An external power supply will therefore be required to power the pump. A transistor, or digital switch, will be needed to control the pump from the low-current signals of the Arduino’s digital pins. An additional concern when powering a pump or motor is back-voltage (also known as counter-electromotive force). When a motor stops receiving current it can continue spinning, generating a voltage in the opposite direction. This reverse voltage can damage circuit components like the transistor. A diode that only allows current in one direction will be added in parallel with the motor to protect the circuit.
Note: use caution when experimenting with electronics around water. Make sure the area near the computer and circuit remains dry. Do not handle electronics with wet hands and be careful handling the pump when it is connected to the circuit
Components
Below is a list of the required components:
- Arduino Uno microcontroller (or equivalent board) (x1)
- DC 3V 5V Micro Submersible Mini Water Pump (or equivalent) (x1)
- Mosfet transistor IRF520 (or equivalent) (x1)
- Rectifier diode 1N4007 (or equivalent) (x1)
- Photoresistor – ambient light detector HW5P-1 (or equivalent) (x1)
- 10 kΩ (kiloohm) resistor (x1)
- Breadboard (x1)
- 9V battery + snap connector (x1)
- M-M jumper wires (x8)
- M-F jumper wires (x2)
- A container with water to submerge the pump
Note: be careful since the pump can move and spray water out of the container. Use the hose supplied with the pump to direct water
Case 1 – timed intervals
A good starting point for experimenting with controlling the pump is setting specific time intervals for its operation. The illustration in Figure 2 shows how to build the circuit.
Circuit
- Connect the 9V battery to the breadboard’s external rails
- Connect the two negative (-) external rails with a jumper wire
- Connect the negative rail on the opposite side of the batteryt to the Arduino’s GND pin
- Place the transistor on the breadboard with the metal tab facing away from the Arduino
- Connect digital pin 9 to the left pin of the transistor
- Connect the right pin of the transistor to the external ground rail
- Use a jumper wire to connect the middle pin of the transistor to the pump’s ground wire
- Connect the pump’s power to the positive (+) external rail
- Place the diode so that the striped end (cathode) is connected to the pump’s power (using an additional jumper wire)
- The non-striped end (anode) is connected to the pump’s ground
- This is important since the diode is polarized and can go only one way in the circuit
Code
The simple code below is used to turn the pump on and off for 2 second intervals. The code initializes a variable for a pin and assigns the value 9. The setup initializes pin 9 as an output. The loop then sends and stops voltage from pin 9 with 2 second breaks before repeating.
Connect the Arduino and upload the code to see the pump operating at 2 second burst.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
const int pumpPin = 9; // initialize digital pin 9 for pump control void setup() { // initialize the pump pin as an output: pinMode(pumpPin, OUTPUT); } void loop() { digitalWrite(pumpPin, HIGH); // send signal from pin 9 to circuit delay(2000); // wait for 2 seconds digitalWrite(pumpPin, LOW); // end signal delay(2000); // wait for 2 seconds before repeating loop } |
Link to video showing how the system works:
https://youtube.com/shorts/FjJaga7ns-Q
Case 2 – sensor feedback control
Once the first case is complete, and simple pump operation has been successful, we can move on to a more complicated case. Here we will use an ambient light sensor (photoresistor) to trigger pump operation. The photoresistor will first be calibrated to ambient lighting. A threshhold is set in the code for when to send a signal to the pump. Figure 3 shows how to build the circuit.
This sensor can be replaced by a variety of sensors based on the desired control input – temperature, soil moisture, proximity, oxygen, manual activation (button).
Circuit
This circuit directly builds on Case 1:
- Place the photoresistor on the breadboard
- Connect the input side of the photoresistor to the Arduino’s 5V pin using a jumper wire
- Connect the output side of the photoresistor to the Arduino’s analog A0 pin using a jumper wire
- Place the 10 kΩ resistor on the breadboard with one leg connected to the external ground rail and one leg to the photoresistor’s output
Code
The code similarly builds on the code of Case 1. The code initializes a variable for a pin and assigns the value 9. It then initializes variables for sensor value and two bounds, low and high.
The setup initializes the pump pin as an output. A while loop assigns 5 seconds for sensor calibration:
- If the value from the sensor is higher than what was assigned to the sensorHigh variable (0), the variable is assigned the new value high
- If the value from the sensor is lower than what was assigned to the sensorLow variable (1023), the variable is assigned the new low value
The main loop section sets the sensorValue variable to the value read from the sensor. It then initiates the same timed pump interval only when the sensor reading is lower than a certain threshold (there’s less light).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
const int pumpPin = 9; // the number of the pump pin int sensorValue; int sensorLow = 1023; int sensorHigh = 0; void setup() { // initialize the pump pin as an output: pinMode(pumpPin, OUTPUT); while (millis() < 5000) { sensorValue = analogRead(A0); if (sensorValue > sensorHigh) { sensorHigh = sensorValue; } if (sensorValue < sensorLow) { sensorLow = sensorValue; } } } void loop() { sensorValue = analogRead(A0); if (sensorValue < 500) { digitalWrite(pumpPin, HIGH); delay(2000); digitalWrite(pumpPin, LOW); delay(2000); } if (sensorValue > 500) { digitalWrite(pumpPin, LOW); } } |
Once you connect the Arduino and upload the coed, you will have 5 seconds to calibrate the sensor. First, allow it to experience the normal lighting of the space – this will set the upper limit. Then, partially cover it with your hands to reduce the amount of light exposure – this will set the lower limit. After 5 seconds the loop will start to run. The pump should operate at the assigned intervals when covered, and stop operating when not covered. Change the parameters in the code to see how the system responds…
Link to video showing how the system works:
https://www.youtube.com/watch?v=OLI6UqPugBI
Bonus: ever wonder what’s inside a mini submersible pump? Here’s a video of someone cutting one open
4 replies on “Controlling submersible pump with Arduino”
Hello Itay,
Thank you for the informative tutorial. I was wondering if there is a way to directly connect the water pump to the Arduino without using an external power supply. Can we rely solely on the 5V pin on the Arduino Uno board?
Thank you.
I have the same question.
I read this article fully concerning the resemblance of the newest and previous technologies, it’s an awesome article.
Like!! Great article post. Really thank you!