Select Page

# Analyze Data

Analyze data! Calculate minimum, maximum and average temperature values using your Humidity Phidget.

## Prerequisites

This project assumes you are familiar with the following

## Setup

All you need for this project is the Getting Started Kit.

## 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

```  ```
import com.phidget22.*;

public class Analyze {

public static void main(String[] args) throws Exception {
//Define
double[] temperatureList = new double[10];

//Create
TemperatureSensor temperatureSensor = new TemperatureSensor();

//Open
temperatureSensor.open(1000);

//Set data interval to minimum | This will increase the data rate from the sensor.
temperatureSensor.setDataInterval(temperatureSensor.getMinDataInterval());

for (int i = 0; i < 10; i++) {
temperatureList[i] = temperatureSensor.getTemperature();
System.out.println(temperatureList[i]);
//Sleep until new data is available
}

double minVal = temperatureList[0];
for (int i = 0; i < temperatureList.length; i++) {
if (temperatureList[i] < minVal) {
minVal = temperatureList[i];
}
}
System.out.println("Minimum Value " + minVal + " degrees Celsius");
}
}
```
```
```  ```
package analyze;

import com.phidget22.*;

public class Analyze {

public static void main(String[] args) throws Exception {
//Define
double[] temperatureList = new double[10];

//Create
TemperatureSensor temperatureSensor = new TemperatureSensor();

//Open
temperatureSensor.open(1000);

//Set data interval to minimum | This will increase the data rate from the sensor.
temperatureSensor.setDataInterval(temperatureSensor.getMinDataInterval());

for (int i = 0; i < 10; i++) {
temperatureList[i] = temperatureSensor.getTemperature();
System.out.println(temperatureList[i]);
//Sleep until new data is available
}

double minVal = temperatureList[0];
for (int i = 0; i < temperatureList.length; i++) {
if (temperatureList[i] < minVal) {
minVal = temperatureList[i];
}
}
System.out.println("Minimum Value " + minVal + " degrees Celsius");
}
}
```
```
```  ```
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

```  ```
from Phidget22.Phidget import *
from Phidget22.Devices.TemperatureSensor import *
#Required for sleep statement
import time

#Create
temperatureList = []
temperatureSensor = TemperatureSensor()

#Open
temperatureSensor.openWaitForAttachment(1000)

#Set data interval to minimum | This will increase the data rate from the sensor.
temperatureSensor.setDataInterval(temperatureSensor.getMinDataInterval())

for i in range(10):
temperatureList.append(temperatureSensor.getTemperature())
print(str(temperatureList[i]))
#Sleep until new data is available. Divide by 1000 to convert from ms to seconds.
time.sleep(temperatureSensor.getDataInterval()/1000)

minVal = temperatureList[0]
for i in range(len(temperatureList)):
if(temperatureList[i] < minVal):
minVal = temperatureList[i]

print("Minimum Value: " + str(minVal) + " degrees Celsius")
```
```

## 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.Collections.Generic;
using Phidget22;

namespace Analyze
{
internal class Program
{
static void Main(string[] args)
{
//Define
double[] temperatureList = new double[10];

//Create
TemperatureSensor temperatureSensor = new TemperatureSensor();

//Open
temperatureSensor.Open(1000);

//Set data interval to minimum | This will increase the data rate from the sensor.
temperatureSensor.DataInterval = temperatureSensor.MinDataInterval;

for (int i = 0; i < 10; i++)
{
temperatureList[i] = temperatureSensor.Temperature;
System.Console.WriteLine(temperatureList[i]);
//Sleep until new data is available
}

double minVal = temperatureList[0];
for (int i = 0; i < temperatureList.Length; i++)
{
if (temperatureList[i] < minVal)
{
minVal = temperatureList[i];
}
}

System.Console.WriteLine("Minimum Value: " + minVal.ToString() + " degrees Celsius");
}
}
}
```
```

## 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.
```
```

Your program will capture 10 temperature samples and report the minimum value.

## Practice

1. Using the code above, calculate the maximum value and report it to the user.
2. Using the code above, calculate the average value and report it to the user.
Designed by Julius Popa

### 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.

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