Parts
Aside from the items below, you will also need the following:
- AA Battery
 - Wire Stripper
 - Alligator Clips (optonal)
 
Setup
Step 1
Cut a spare sensor cable in half.
Note: if you do not have alligator clips, make sure to leave enough wire to connect to both sides of a AA battery.
Step 2
Remove about 1 inch (2.5cm) of insulation from the black wire and the white wire. Remove the red wire.Cut a spare sensor cable in half.
Step 4
Connect one end of your alligator clips to the bare wires and the other end to the battery.
Note: the white wire should be connected to the positive terminal on the battery.
Write code (Java)
Copy the code below into a new Java project. If you need a reminder of how to do this, revisit the Getting Started Course.
Not your programming language? Set your preferences so we can display relevant code examples
  
//Add Phidgets Library
import com.phidget22.*;
public class BatteryTester {
    public static void main(String[] args) throws Exception {
        //Create
        VoltageInput batteryVoltage = new VoltageInput();
        //Address
        batteryVoltage.setHubPort(0);
        batteryVoltage.setIsHubPortDevice(true);
        
        //Open
        batteryVoltage.open(1000);
        
        //Use Your Phidgets
        while(true){
            System.out.println("Battery Voltage: "  + batteryVoltage.getVoltage() + "V");
            Thread.sleep(250);            
        }        
    }
}  
  
  
package batterytester;
//Add Phidgets Library
import com.phidget22.*;
public class BatteryTester {
    public static void main(String[] args) throws Exception {
        //Create
        VoltageInput batteryVoltage = new VoltageInput();
        //Address
        batteryVoltage.setHubPort(0);
        batteryVoltage.setIsHubPortDevice(true);
        
        //Open
        batteryVoltage.open(1000);
        
        //Use Your Phidgets
        while(true){
            System.out.println("Battery Voltage: "  + batteryVoltage.getVoltage() + "V");
            Thread.sleep(250);            
        }        
    }
}  
  
  
Code is not available for this project.
  
Write code (Python)
Copy the code below into a new Python project. If you need a reminder of how to do this, revisit the Getting Started Course.
Not your programming language? Set your preferences so we can display relevant code examples
  
#Add Phidgets Library
from Phidget22.Phidget import *
from Phidget22.Devices.VoltageInput import *
#Required for sleep statement
import time
 
#Create
battery_voltage = VoltageInput()
#Address
battery_voltage.setHubPort(0)
battery_voltage.setIsHubPortDevice(True)
#Open
battery_voltage.openWaitForAttachment(1000)
#Use your Phidgets
while(True):
    print("Battery Voltage: " + str(battery_voltage.getVoltage()) + "V")
    time.sleep(0.25)  
  
Write code (C#)
Copy the code below into a new C# project. If you need a reminder of how to do this, revisit the Getting Started Course.
Not your programming language? Set your preferences so we can display relevant code examples
  
using System;
using System.Collections.Generic;
using Phidget22;
namespace BatteryTester
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create
            VoltageInput batteryVoltage = new VoltageInput();
            //Address
            batteryVoltage.HubPort = 0;
            batteryVoltage.IsHubPortDevice = true;
            //Open
            batteryVoltage.Open(1000);
            //Use your Phidgets
            while (true)
            {
                System.Console.WriteLine("Battery Voltage: " + batteryVoltage.Voltage + "V");
                System.Threading.Thread.Sleep(250);
            }            
        }
    }
}
  
Write code (Swift)
Copy the code below into a new Swift project. If you need a reminder of how to do this, revisit the Getting Started Course.
Not your programming language? Set your preferences so we can display relevant code examples
  
Code not available.
  
Run Your Program
Your program will output the battery voltage.
Practice
- Try using the LEDs from your Getting Started Kit to create a battery testing device. Turn on the green LED if the battery is new, and the red LED if the battery needs replacing!
 

  
  
  


