Categories
TUTORIALS

Controlling submersible pump with Arduino

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.

Fig. 1 – Submersible pump diagram

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:

  1. Arduino Uno microcontroller (or equivalent board) (x1)
  2. DC 3V 5V Micro Submersible Mini Water Pump (or equivalent) (x1)
  3. Mosfet transistor IRF520 (or equivalent) (x1)
  4. Rectifier diode 1N4007 (or equivalent) (x1)
  5. Photoresistor – ambient light detector HW5P-1 (or equivalent) (x1)
  6. 10 kΩ (kiloohm) resistor (x1)
  7. Breadboard (x1)
  8. 9V battery + snap connector (x1)
  9. M-M jumper wires (x8)
  10. M-F jumper wires (x2)
  11. 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
Fig. 2 – Case 1 circuit illustration

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.

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
Fig. 3 – Case 2 circuit diagram

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).

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

https://www.youtube.com/watch?v=swFkjOk-_ic

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.

Leave a Reply

Your email address will not be published. Required fields are marked *