In this Project, we first see how to interface a temperature sensor to an arduino. Later we would send this sensor data to PC via serial and visualise the data in a software called Processing.
Now make your own temperature sensor by Arduino and LM35 Sensor
You require the following parts:
-
1-ARDUINO BOARD ANY VERSION
-
2-LM35 TEMPERATURE SENSOR
-
3-USB CABLE
-
4-COMPUTER WITH ARDUINO SOFTWARE
Few points on LM35
- Calibrated Directly in Celsius (Centigrade)
- Linear + 10-mV/°C Scale Factor
- 0.5°C Ensured Accuracy (at 25°C)
- Rated for Full −55°C to 150°C Range
- Suitable for Remote Application
Connecting LM 35 to Arduino (UNO) :
Sending serial data to Processing :
//import Serial communication library
import processing.serial.*;//init variables
Serial commPort;
float tempC;
float tempF;
int yDist;
float[] tempHistory = new float[100];void setup()
{
//setup fonts for use throughout the application
//set the size of the window
size(360,320);
//init serial communication port
commPort = new Serial(this, "COM10", 9600);
//fill tempHistory with default temps
for(int index = 0; index<100; index++)
tempHistory[index] = 0;
}void draw()
{
//get the temp from the serial port
while (commPort.available() > 0)
{
tempC = commPort.read();
//refresh the background to clear old data
background(123);//draw the temp rectangle
colorMode(RGB, 160); //use color mode sized for fading
stroke (0);
rect (49,19,22,162);
//fade red and blue within the rectangle
for (int colorIndex = 0; colorIndex <= 160; colorIndex++)
{
stroke(160 - colorIndex, 0, colorIndex);
line(50, colorIndex + 20, 70, colorIndex + 20);
}
//draw graph
stroke(0);
fill(255,255,255);
rect(90,80,100,100);
for (int index = 0; index<100; index++)
{
if(index == 99)
tempHistory[index] = tempC;
else
tempHistory[index] = tempHistory[index + 1];
point(90 + index, 180 - tempHistory[index]);
}
//write reference values
fill(0,0,0);
textAlign(RIGHT);
text("212 F", 45, 25);
text("32 F", 45, 187);
//draw triangle pointer
yDist = int(160 - (160 * (tempC * 0.01)));
stroke(0);
triangle(75, yDist + 20, 85, yDist + 15, 85, yDist + 25);
//write the temp in C and F
fill(0,0,0);
textAlign(LEFT);
text(str(int(tempC)) + " C", 115, 37);
tempF = ((tempC*9)/5) + 32;
text(str(int(tempF)) + " F", 115, 65);
}
}
Comments