You are on page 1of 8

Arduino Documentation

Arduino-LabVIEW Interface: Heat Transfer

Hardware

Heat Transfer Apparatus

1. Temperature Sensors: Thermistors


a. The thermistors, model 317-1381-ND procured by Digikey, are mounted at the end of plastic
arms. The resistance in a thermistor is variable (function of temperature) and is measured by
the voltage drop across a 10K ohm resistor.
2. LCD Screen
a. The LCD screen is a LCD-00710 with a number of inputs and outputs as indicated by the table
below.

The LCD operates using the KS0108 Graphics LCD Library, required for modification of
the arduino code.

LCD Screen with Two Sensors Connected

3. LED Light Array


The LED light array is a series of RGB LEDs that changed color based on the
software. These are attached to the arduino to two digital ports for the clock and data, the red to
5V, and yellow to ground.
LED Light Array Wires

Blue

Clock

Green

Data

Red

VCC

Yellow

Ground

LEDs Example

4. Pressure Sensor
The pressure sensors mounted in the apparatus is a 100 lb Flexiforce pressure
sensor, model SEN-08685. The resistance within the sensor is variable based on the pressure
applied.

Flexiforce Pressure Sensor (100 lbs)

Software

1.
2.
3.
4.
5.
6.

Software Architecture
LabVIEW Sampling, Read in Resistances to LabVIEW
Sensor Reading
Converting Sensor Reading (Resistance) to Temperature
Displaying Temperature Reading on LCD Screen
Convert Temperature Readings to HSV
Convert HSV to RGB to Int32 Color Function to LED Strip

The majority of the code below is commented. This can be viewed easier in an editor such as
notepad++ under C (language).
/*********************************************************************************
**
** Includes.
**
********************************************************************************/
// Standard includes. These should always be included.
#include <Wire.h>
#include <SPI.h>
#include <Servo.h>
#include "LabVIEWInterface.h"
#include <WS2801.h>
#include <glcd.h>
// include the Fonts
#include <fonts/allFonts.h>

// Constants
float RINF = 0.0881613489;
int B = 3950; //
int dataPin = 2;
int clockPin = 3;
int MAXHDEG = 240;
unsigned long timeReset =0;

// HSV to RGB Converter


void HSV_to_RGB(float h, float s, float v, byte *r, byte *g, byte *b)
{
float f,p,q,t;
int i;
h = max(0.0, min(240.0, h));
s = max(0.0, min(100.0, s));
v = max(0.0, min(100.0, v));
s /= 100;
v /= 100;
if(s == 0) {
// Achromatic (grey)
*r = *g = *b = round(v*255);
return;
}
h /= 60; // sector 0 to 5
i = floor(h);
f = h - i; // factorial part of h
p = v * (1 - s);
q = v * (1 - s * f);
t = v * (1 - s * (1 - f));
switch(i) {
case 0:
*r = byte(round(255*v));
*g = byte(round(255*t));
*b = byte(round(255*p));

break;
case 1:
*r = byte(round(255*q));
*g = byte(round(255*v));
*b = byte(round(255*p));
break;
case 2:
*r = byte(round(255*p));
*g = byte(round(255*v));
*b = byte(round(255*t));
break;
case 3:
*r = byte(round(255*p));
*g = byte(round(255*q));
*b = byte(round(255*v));
break;
case 4:
*r = byte(round(255*t));
*g = byte(round(255*p));
*b = byte(round(255*v));
break;
default: // case 5:
*r = byte(round(255*v));
*g = byte(round(255*p));
*b = byte(round(255*q));
}
}
// Set the first variable to the NUMBER of pixels. 25 = 25 pixels in a row
WS2801 strip = WS2801(18, dataPin, clockPin);

// Thermistor Function , Returns Temp in F


float TemperatureReturn(int sensorValue){
//float T0 = 298.15; // K
float voltage= sensorValue * (5.0 / 1024.0);
float resistance = ((5.0/voltage) - 1)*10000;
float divs = resistance/RINF;
float logval = log(divs);
float t1 = B/ logval;
return (( t1 - 273.15) * 9.0)/ 5.0 + 32.0; // Deg F
}
// Thermistor Function , Returns Temp in F
float ResistanceReturn(int sensorValue){
//float T0 = 298.15; // K
float voltage= sensorValue * (5.0 / 1024.0);
return ((5.0/voltage) - 1)*10000;
}

/* Helper functions */
// Create a 24 bit color value from R,G,B
uint32_t Color(byte r, byte g, byte b)
{
uint32_t c;
c = r;
c <<= 8;
c |= g;
c <<= 8;
c |= b;

return c;
}

/*********************************************************************************
** setup()
**
** Initialize the Arduino and setup serial communication.
**
** Input: None
** Output: None
*********************************************************************************/
void setup()
{
// Initialize Serial Port With The Default Baud Rate
syncLV();
GLCD.Init();
Serial.begin(9600);
// Select the font for the default text area
GLCD.SelectFont(System5x7);
// Place your custom setup code here
strip.begin();
// Update LED contents, to start they are all 'off'
strip.show();
}

/*********************************************************************************
** loop()
**
** The main loop. This loop runs continuously on the Arduino. It
** receives and processes serial commands from LabVIEW.
**
** Input: None
** Output: None
*********************************************************************************/

void loop()
{
// Check for commands from LabVIEW and process them.
checkForCommand();
// Place your custom loop code here (this may slow down communication with LabVIEW)
int sensorValue[5];
float Temp[9];
float Res[9];
byte r,g,b;
float SATURAION = 100.0;
float VALUE = 100.0;
if (millis() >= (timeReset+2000)) {
// Read Sensor Values
sensorValue[0] = analogRead(A0);
sensorValue[1] = analogRead(A1);
sensorValue[2] = analogRead(A2);
sensorValue[3] = analogRead(A3);
sensorValue[4] = analogRead(A4);

sensorValue[5] = analogRead(A5);
sensorValue[6] = analogRead(A6);
sensorValue[7] = analogRead(A7);
sensorValue[8] = analogRead(A8);
sensorValue[9] = analogRead(A9);
sensorValue[10] = analogRead(A10);
sensorValue[11] = analogRead(A11);

// GLCD Stuff
GLCD.ClearScreen();
GLCD.CursorTo(0, 1);
GLCD.print("#|Temp (F)|# |Temp(F)\n");
for(int i = 0; i < 6; i++){
GLCD.print((i+1), DEC);
GLCD.print("| ");
Temp[i] = TemperatureReturn(sensorValue[i]);
if ( (Temp[i]) > 0){
GLCD.print(Temp[i], 2);
GLCD.print(" |");
}
else {
GLCD.print("-------");
GLCD.print("|");
}
// Returning Resistance
//Temp[2*i+1] = TemperatureReturn(sensorValue[2*i+1]);
if (i < 5){
GLCD.print((i+7), DEC);
GLCD.print("| ");

if ( (Temp[i+7]) > 0){


Temp[i+7] = TemperatureReturn(sensorValue[i+7]);
GLCD.print(Temp[i+7], 2);
}
else {
GLCD.print("-----");
}
}
GLCD.print("\n");

//
//

//Temp[2*i+2] = TemperatureReturn(sensorValue[2*i+1]);
//Set the Pixel Color For each of the 18
//H = 240*Temp/212 (0 to 240 deg) of (0 to 212 deg)
//There are 18
for(int ii = 0; ii < 4; ii++){
HSV_to_RGB((240*Temp[i]/212), SATURAION, VALUE,&r,&g,&b);
strip.setPixelColor(i*4+ii,Color(r,g,b));
}
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
}
timeReset = millis(); //Reset time since last reading
strip.show(); // Write out pixels

}
// Some example procedures showing how to display to the pixels
//colorWipe(Color(TemperatureReturn(sensorValue[0])/250, 0, 0), 50);

if(acqMode==1)
{
sampleContinously();
}
}

You might also like