Arduino Nano ESP32 - Control Pump

This tutorial provides instructions on how to use Arduino Nano ESP32 to control a pump. You can extend this tutorial to build the DIY aquarium, cocktail machine, coffee machine, or irrigation system...

Hardware Preparation

1×Arduino Nano ESP32
1×USB Cable Type-C
1×Relay
1×12V Pump
1×Vinyl Tube
1×12V Power Adapter
1×Breadboard
1×Jumper Wires
1×(Optional) DC Power Jack
1×(Recommended) Screw Terminal Adapter for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. We appreciate your support.

Overview of 12V Pump

Pump Pinout

Arduino Nano ESP32 Pump Pinout
image source: diyables.io

A 12V Pump has two wires:

  • Negative (-) wire (black): connect this wire to the negative wire of 12V DC power supply
  • Positive (+) wire (red): connect this wire to the Positive wire of 12V DC power supply

How to Control Pump using Arduino Nano ESP32

If we connect a 12V power supply to a pump, the pump will work. We can programmatically control a pump by using Arduino Nano ESP32. To do so, we need a relay in between the pump Arduino Nano ESP32 board. We have a specific tutorial about relay, which contains detailed information and step-by-step instructions about hardware pinout, working principle, wiring connection to ESP32, Arduino Nano ESP32 code... Learn about relay in the Arduino Nano ESP32 - Relay tutorial

Wiring Diagram between ESP32, Relay and Pump

The wiring diagram between Arduino Nano ESP32 and Pump

This image is created using Fritzing. Click to enlarge image

Arduino Nano ESP32 - Pump Code

The below code periodically turns the pump ON/OFF in every 4 seconds.

/* * This Arduino Nano ESP32 code was developed by newbiely.com * * This Arduino Nano ESP32 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-esp32/arduino-nano-esp32-controls-pump */ #define RELAY_PIN D2 // The Arduino Nano ESP32 pin connected to the pump the via the relay // The setup function runs once on reset or power-up void setup() { // initialize digital pin as an output. pinMode(RELAY_PIN, OUTPUT); } // The loop function repeats indefinitely void loop() { digitalWrite(RELAY_PIN, HIGH); // turn on pump 4 seconds delay(4000); digitalWrite(RELAY_PIN, LOW); // turn off pump 4 seconds delay(4000); }

Detailed Instructions

To get started with Arduino Nano ESP32, follow these steps:

  • If you are new to Arduino Nano ESP32, refer to the tutorial on how to set up the environment for Arduino Nano ESP32 in the Arduino IDE.
  • Wire the components according to the provided diagram.
  • Connect the Arduino Nano ESP32 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the Arduino Nano ESP32) board and its corresponding COM port.* Copy the above code and paste it to Arduino IDE.
  • Compile and upload code to Arduino Nano ESP32 board by clicking Upload button on Arduino IDE
  • See the pump's state

Line-by-line Code Explanation

The above Arduino Nano ESP32 code contains line-by-line explanation. Please read the comments in the code!

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!