ESP8266 - Pump

This tutorial instructs you how to use ESP8266 to control a pump. By adapting this tutorial, you can construct an irrigation system, an aquarium, a water refilling system, and more.

Hardware Preparation

1×ESP8266 NodeMCU
1×USB Cable Type-C
1×Relay
1×12V Pump
1×Vinyl Tube
1×12V Power Adapter
1×DC Power Jack
1×Jumper Wires
1×Breadboard
1×(Recommended) Screw Terminal Expansion Board for ESP8266
1×(Recommended) Power Splitter For ESP8266 Type-C

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.
Additionally, some of these links are for products from our own brand, DIYables.

Overview of 12V Pump

The Pump Pinout

ESP8266 NodeMCU Pump pinout
image source: diyables.io

The 12V Pump typically has two pins:

  • The Negative (-) pin (black) should be connected to the GND of the DC power supply
  • The Positive (+) pin (red) should be connected to the 12V of the DC power supply

How to Control Pump using ESP8266

If a 12V pump is supplied with a 12V power source, it will function. In order to control the pump, a relay must be used between the ESP8266 and the pump. The ESP8266 can then control the pump via the relay.

If you are unfamiliar with relays (pinout, operation, programming, etc.), please refer to the ESP8266 - Relay tutorial for more information.

Wiring Diagram

The wiring diagram between ESP8266 NodeMCU and Pump

This image is created using Fritzing. Click to enlarge image

See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.

ESP8266 Code for controlling Pump

The code below will keep the pump toggling between ON and OFF every five seconds.

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-pump */ #define RELAY_PIN D8 // The ESP8266 pin connected to the IN pin of relay // The setup function runs once on reset or power-up void setup() { // initialize digital pin D8 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 ESP8266 on Arduino IDE, follow these steps:

  • Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
  • Wire the components as shown in the diagram.
  • Connect the ESP8266 board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
  • Connect your ESP8266 to your computer using a USB cable.
  • Launch the Arduino IDE, select the appropriate board and port.
  • Copy the code above and open it in the Arduino IDE.
  • Click the Upload button in the Arduino IDE to send the code to the ESP8266.
  • Check out the state of the pump changing.

Code Explanation

Check out the line-by-line explanation contained in the comments of the source code!

Check out this tutorial on ESP8266 - if button pressed, turn pump on in 10 seconds.

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!