# Analog Data (Analog Watcher)

In this example, you will learn how to use the ANALOG DATA Control Panel to watch analog sensor values that have been pre-processed inside your code, for instance for unit conversion purpose.

In our case, we will use a TMP36 temperature sensor on pin A1 which outputs raw data values between 0 and 1023. Then we will convert these values into voltage and degrees and finally, we will write them in Analog Data so that we can watch them in HITIPanel.

It is not a requirement to use a temperature sensor. You can use any analog sensor you want and performs the necessary unit conversion in place of those presented in this example.

## 1) Wiring diagram

Connect a TMP36 temperature sensor on pin A1. ## 2) Sketch: 1_Basics \ 7_AnalogData

Inside the loop(), we start by reading sensor values on Analog Input 1 using analogRead(analog pin). These raw values range from 0 to 1023.

We then convert them in volt assuming the temperature sensor is powered with +5V. If you are using a different power supply value, please adapt the code accordingly.

Following this first conversion, we perform a second conversion in degrees Celsius based on the values in volt. The formula uses parameter values for a TMP36 sensor : this sensor provides a voltage of 750mV at 25°C which varies by 10mV/°C. If you are using a different temperature sensor, please have a look at its datasheet to find the equivalent parameters.

Finally, we write the values in Analog Data using HC_analogDataWrite(data, values) so that we can watch them in the ANALOG DATA Control Panel.

``````#include <HITIComm.h>

// Pins assignment
const int pin_TemperatureSensor = A1;

// Analog Data assignment:
const int ad_Temperature_voltage = 0; // sensor values in V
const int ad_Temperature_celsius = 1; // sensor values in °C

// run once at power on
void setup()
{
// initialize library
HC_begin();
}

// run repeatedly after setup()
void loop()
{
// communicate with HITIPanel
HC_communicate();

// convert to voltage V    (using 5V power supply)
float voltage = ((float) rawData / 1024.0) * 5.0;

// convert to degrees °C   (TMP36 sensor => +10mV/°C, 750mV at 25°C)
float celsius = (voltage - 0.5) * 100;

// send values to HITIPanel
}
``````

## 3) Control Panels

2. The raw analog value read from the temperature sensor is displayed in the Command Panel of pin A1. 3. Display the ANALOG DATA Control Panel (“DATA” button).
4. The converted sensor values are displayed in the Command Panels of Analog Data 0 and 1. For instance, a raw value of 160 is converted into 0.781V and 28.125°C. ## 4) Chart

1. Open the Chart window (CTRL+T or Tools\Chart).
2. Start data acquisition. 3. See the temperature in degrees Celsius being plotted. A new value is added every second and all values are displayed during the acquisition. Try to heat your sensor by putting your fingers on it, and check that the temperature does increase accordingly. In our example, we start heating our sensor at 18s. Then stop data acquisition. 