Example Code for Arduino-Basic Control

Last revision 2026/01/05

Hardware Preparation

Software Preparation

Development Tool: Arduino IDE (version unspecified). Download link: Arduino IDE

Wiring Diagram

Gravity: Digital Peristaltic Pump Wiring Diagram

Other Preparation Work

Since the motor power consumption (about 5W) is a little large, it’s better to add an external power supply on your microcontroller, USB port can only provide 2.5W power supply.

The motor driver board uses the PPM signal to control the pump. The corresponding relationship is as follows:

PPM Signal Peristaltic Pump Status (Top View)
500 ~ 1400us (0~81°) Clockwise maximum speed rotation
1400 ~ 1600us (81~99°) Stop
1600 ~ 2500us (99~180°) Counterclockwise maximum speed rotation

In addition, the closer to 500us(0°) or 2500us(180°), the faster the flow rate speed is; when the value is closer to 90°, the slower the motor speed. Therefore, according to the requirement, you can set the appropriate angle value to adjust the motor speed, to achieve the purpose of controlling the flow rate.

Sample Code

/***************************************************
 DFRobot Gravity: Peristaltic Pump
 <https://www.dfrobot.com/wiki/index.php/Gravitry: Peristaltic Pump SKU:DFR0523>

 ***************************************************
 This sample code shows 3 states: clockwise maximum speed rotation; stop; counterclockwise maximum speed rotation

 Created 2017-12-25
 By Jason <[email protected]@dfrobot.com>

 GNU Lesser General Public License.
 See <http://www.gnu.org/licenses/> for details.
 All above must be included in any redistribution
 ****************************************************/

 /***********Notice and Trouble shooting***************
0   -> clockwise maximum speed rotation
90  -> stop
180 -> counterclockwise maximum speed rotation
 ****************************************************/

#include <Servo.h>

Servo myservo;

#define PUMPPIN 9    //peristaltic pump control pin, connect to arduino digital pin 9
#define waitTime 2000 //interval time(ms) between every state

void setup()
{
  myservo.attach(PUMPPIN);
}

void loop()
{
    myservo.write(0);   //Clockwise maximum speed rotation
    delay(waitTime);
    myservo.write(90);  //Stop
    delay(waitTime);
    myservo.write(180); //Counterclockwise maximum speed rotation
    delay(waitTime);
    myservo.write(90);  //Stop
    delay(waitTime);
}

Result

After uploading the sample code, you can see that the peristaltic pump starts to work and continuously switches between the three states of clockwise maximum speed rotation, stop and maximum counterclockwise rotation speed every 2 seconds.

Was this article helpful?

TOP