Phidget Plant Kit

Use the Water Pump

In this step, you will learn how to operate the water pump so you can water your plant.

Move Your Water Pump

Remove the tubing from your plant and place it in a second reservoir for testing.

Warning: Things may get wet, so make sure all of your electronics are at a safe distance!

You can continue working from your PhidgetsPlant project in this step. Replace your previous code with the following code.

Write Code (Java)

Not your programming language? Set your preferences so we can display relevant code examples.

  
package phidgetsplant;

//Add Phidgets Library
import com.phidget22.*;

public class PhidgetsPlant {
    public static void main(String[] args) throws Exception {
        //Create
        DigitalOutput pump = new DigitalOutput();
        
        //Address
        pump.setHubPort(1);
        pump.setIsHubPortDevice(true);
        
        //Open
        pump.open(1000);
        
        //Use your Phidgets
        pump.setState(true);
        Thread.sleep(1000);
        pump.setState(false);
    }    
}
  
  
//Add Phidgets Library
import com.phidget22.*;

public class PhidgetsPlant {
    public static void main(String[] args) throws Exception {
        //Create
        DigitalOutput pump = new DigitalOutput();
        
        //Address
        pump.setHubPort(1);
        pump.setIsHubPortDevice(true);
        
        //Open
        pump.open(1000);
        
        //Use your Phidgets
        pump.setState(true);
        Thread.sleep(1000);
        pump.setState(false);
    }    
}
  
  
//Add Phidgets Library 
import com.phidget22.*;

//Define
DigitalOutput pump;

void setup(){
  try{
    
    //Create
    pump = new DigitalOutput();
    
    //Address
    pump.setHubPort(1);
    pump.setIsHubPortDevice(true);
    
    //Open
    pump.open(1000);
    
  }catch(Exception e){
    //Handle Exceptions
    e.printStackTrace();
  }
}

void draw(){
  try{
    
    //Use your Phidgets
    pump.setState(true);
    delay(1000);
    pump.setState(false);
    exit();
    
  }catch(Exception e){
    //Handle Exceptions
    e.printStackTrace();
  }
}
  

Write Code (Python)

Not your programming language? Set your preferences so we can display relevant code examples.

  
#Add Phidget Library
from Phidget22.Phidget import *
from Phidget22.Devices.DigitalOutput import *
#Required for sleep statement
import time

#Create
pump = DigitalOutput()

#Address
pump.setHubPort(1)
pump.setIsHubPortDevice(True)

#Open
pump.openWaitForAttachment(1000)

#Use your Phidgets
pump.setState(True)
time.sleep(1)
pump.setState(False)
  

Write Code (C#)

Not your programming language? Set your preferences so we can display relevant code examples.

  
//Add Phidgets Library
using Phidget22;

namespace PhidgetsPlant
{
    class Program
    {
        static void Main(string[] args)
        {

            //Create
            DigitalOutput pump = new DigitalOutput();

            //Address
            pump.HubPort = 1;
            pump.IsHubPortDevice = true;

            //Open
            pump.Open(1000);

            //Use your Phidgets
            pump.State = true;
            System.Threading.Thread.Sleep(1000);
            pump.State = false;

        }
    }
}
  

Write Code (Swift)

Not your programming language? Set your preferences so we can display relevant code examples.

The code below assumes you've created a single button and linked it to an IBAction named pumpButton.

  
import Cocoa
//Add Phidgets Library
import Phidget22Swift

class ViewController: NSViewController {

    @IBOutlet weak var pumpButton: NSButton!
    
    //Create
    let pump = DigitalOutput()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        do{
            //Address
            try pump.setHubPort(1)
            try pump.setIsHubPortDevice(true)
            
            //Open
            try pump.open()
            
        }catch{
            print(error)
        }
    }
    
    @IBAction func runPump(_ sender: Any) {
        do{
            let currentState = try pump.getState()
            let buttonStr = currentState ? "Start Pump" : "Stop Pump"
            pumpButton.title = buttonStr
            try pump.setState(!currentState)
        }catch{
            print(error)
        }
    }
}
  

Run Your Program

You will see water being pumped for 1 second and then the pump will turn off.

Collect Values

Using your program, determine the following values:

Water Pump ON Time Volume of Water
1 second (default from code above) ?
2 seconds ?
3 seconds ?

You can measure the volume by using a measuring cup, ruler, scale, or just by eye. The goal is to determine how much water you think your plant will need. You will use this value later when designing your system.

Troubleshoot
  1. Make sure everything is plugged in properly and your VINT Hub is connected to your computer.
  2. Stop running other programs that are using your Phidgets before running a program.

If you are still having issues visit Advanced Troubleshooting

What are Phidgets?

Phidgets are programmable USB sensors. Simply plug in your sensor, write code in your favorite language and go!

Phidgets have been used by STEM professionals for over 20 years and are now available to students.

Learn more

Set your preferences

Windows

Mac OS

Raspberry Pi

Java

Python

C#

Swift

NetBeans

Processing

Eclipse

Thonny

PyCharm

PyScripter

Visual Studio

Xcode

Setting your preferred operating system, programming language and environment lets us display relevant code samples for the Getting Started Tutorial, Device Tutorials and Projects

Done