Example Code for Arduino - Calibrate the Peristaltic Pump
Last revision 2026/10/08
The peristaltic pump supports self-calibration, storing data in the EEPROM for precise liquid delivery. Before calibration, ensure the tube is fully filled with liquid. Use Example Code 1 to prime the tubing. Connect DFRduino UNO+IO Expansion Board and Peristaltic Pump V2 as shown. Download Arduino IDE and DFRobot_PeristalticPump_V2 library. Enter SETCAL in the serial port to start calibration, then input the measured liquid volume (mL) to complete it. It's like setting up a precision liquid dispenser.
The peristaltic pump supports self-calibration, and calibration data will be stored in the EEPROM of the main controller for subsequent precise quantitative liquid delivery. Before calibration, ensure the tube is fully filled with liquid. You may run Example Code 1 for a period of time beforehand.
Hardware Preparation
| Name | SKU | Quantity | Purchase Link | Description |
|---|---|---|---|---|
| DFRduino UNO+IO Expansion Board | DFR0216-2 | 1 | https://www.dfrobot.com/product-2136.html | Controller |
| Gravity: Peristaltic Pump V2 | DFR1261 | 1 | ||
| Gravity Sensor Cable(Comes with Peristaltic Pump V2) | 1 | Cable |
Software Preparation
- Download Arduino IDE: Click to download Arduino IDE
- Download DFRobot_PeristalticPump_V2 library:DFRobot_PeristalticPump_V2
- Arduino IDE V1.8.19 (or below) can extract the .zip library downloaded from GitHub into the “libraries” folder located in the Arduino IDE installation directory.
- Arduino IDE V2.0.0 (or above) can directly search for the "DFRobot_PeristalticPump_V2" library in the Library Manager and install it.
Wiring Diagram

| Device A | Port/Pin | Device B | Port/Pin |
|---|---|---|---|
| DFRduino UNO+IO Expansion Board | D9 | Gravity: Peristaltic Pump V2 | D |
| DFRduino UNO+IO Expansion Board | 5V | Gravity: Peristaltic Pump V2 | + |
| DFRduino UNO+IO Expansion Board | GND | Gravity: Peristaltic Pump V2 | - |
| 12V DC Power Supply | DC2.1 | Gravity: Peristaltic Pump V2 | DC2.1 jack |
Example Code
/*!
* @file calPump.ino
* @brief Calibrate peristaltic pump flowRate and store it in EEPROM
* @copyright Copyright (c) 2026 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author JiaLi(zhixin.liu@dfrobot.com)
* @version V1.0
* @date 2026-02-10
* @url https://github.com/DFRobot/DFRobot_PeristalticPump_V2
*/
#include "DFRobot_PeristalticPump_V2.h"
#if defined(ESP32)
int servoPin = 17;
#else
int servoPin = 9;
#endif
DFRobot_PeristalticPump_V2 pump(servoPin);
void onCalPumpEvent(eCalPumpEvent_t event, float value)
{
switch (event) {
case eCalEventWaitSetCal:
Serial.println(F("Type \"SETCAL\" to start calibration."));
break;
case eCalEventInvalidSetCal:
Serial.println(F("Invalid command. Type \"SETCAL\" to start calibration."));
break;
case eCalEventStart:
Serial.println(F("Calibration started..."));
break;
case eCalEventCountdown:
Serial.print(F("Calibration count down: "));
Serial.print((int)value);
Serial.println(F("s"));
break;
case eCalEventStop:
Serial.println(F("Calibration stop."));
break;
case eCalEventWaitVolume:
Serial.println(F("Input pumped volume (ml):"));
break;
case eCalEventInvalidVolume:
Serial.println(F("Invalid value. Please input a number > 0."));
break;
case eCalEventWriteFailed:
Serial.println(F("Write flowRate to EEPROM failed."));
break;
case eCalEventDone:
Serial.println(String(F("flowRate(ml/s): ")) + String(value, 4));
break;
default:
break;
}
}
void setup()
{
Serial.begin(115200);
pump.begin();
pump.setCalPumpEventCallback(onCalPumpEvent);
Serial.println(F("DFROBOT Peristaltic Pump - Calibration"));
Serial.println(F("Type \"SETCAL\" and send newline to start."));
}
void loop()
{
/**
* note:
* 1. Prime the tubing first: run setPumpRun.ino until the tubing is fully filled with water.
* 2. Skipping priming can lead to inaccurate calibration results.
*/
if (pump.calPump()) {
Serial.println(F("Calibration success, pump flow rate is stored in EEPROM."));
} else {
Serial.println(F("Calibration failed."));
}
while(1);
}
Result
Enter SETCAL in the serial port terminal to start calibration.
The peristaltic pump will run for 15 seconds. Please ensure that the tubing is completely filled with liquid before starting the calibration.
Use the provided graduated cylinder for calibration, or prepare a suitable graduated cylinder yourself.
Then, enter the measured liquid volume (mL) in the serial port terminal and press Enter to complete the calibration.

Was this article helpful?
