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
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of 12V Pump
The Pump Pinout
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
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.
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.