Analog Data (Metric)

Modified on Wed, 04 Jan 2023 at 10:13 PM

This example shows how to use an ANALOG DATA Command Panel as a Metric to monitor analog values inside your running Arduino program. A Metric is typically used to display parameters or calculated values (e.g. for monitoring sensors values converted to specific units).


To illustrate this, let’s use a TMP36 temperature sensor on pin A1 which outputs raw values between 0 and 1023. We will convert these values into voltage and degrees and display them in Command Panel 0 and 1 used as Metrics.


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.   



Wiring diagram

Connect a TMP36 temperature sensor on pin A1.


 


 

Sketch

Upload this program : 1_Basics \ 8_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 depends on the sensor. A TMP36 sensor provides a voltage of 750mV at 25°C, which varies by 10mV/°C. If you are using a different temperature sensor, have a look at its datasheet to find the equivalent parameters).


Finally, we display the converted values in Command Panels 0 and 1 using HC_analogDataWrite(data, values).


#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

void setup()
{
    // initialize library
    HC_begin();
}

void loop()
{
    // communicate with HITIPanel
    HC_communicate();

    // read sensor raw values
    int rawData = analogRead(pin_TemperatureSensor);

    // 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;

    // display converted values in HITIPanel (Command Panel 0 and 1)
    HC_analogDataWrite(ad_Temperature_voltage, voltage);
    HC_analogDataWrite(ad_Temperature_celsius, celsius);
}

 


Control Panels 

1) Open the I/O Control Panels (“IO” button).

2) The raw value read from the temperature sensor is displayed in the Command Panel of pin A1. 



3) Display the DATA Control Panels (“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.




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.








Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article