Académique Documents
Professionnel Documents
Culture Documents
{
tempC = analogRead(tempPin);
tempC = (5.0 * tempC * 100.0)/1024.0;
ure
Serial.print((byte)tempC);
delay(1000);
ew data
}
Ce capteur est trs facile utiliser puisqu il suffit de l alimenter avec les pattes VC
C et GND et la patte centrale une entre analogique d Arduino.
La conversion elle aussi est simple puisqu un volt correspond 100 degrs Celsius.
La lecture analogique d u signal de 0 5V tant code de 0 1023, on a la formule
Temp = Volt * 5./1023*100 ;
void loop()
{
int rawvoltage= analogRead(outputpin);
float millivolts= (rawvoltage/1024.0) * 5000;
float celsius= millivolts/10;
Serial.print(celsius);
Serial.print(" degrees Celsius, ");
Serial.print((celsius * 9)/5 + 32);
Serial.println(" degrees Fahrenheit");
delay(1000);
}
void loop()
{ delay(2000); // calls a 2 second delay
t=t+2;
// increments the time by 2 every two seconds
temp=analogRead(sensor); // reads the LM35 output
tempc=(temp*5)/10;
// converts the digital value into temperature degree
C
tempf=(tempc*1.8)+32;
// converts degree C to degree F
Serial.println("...............");
Serial.println("Temperature logger");
Serial.print("Time in sec = "); // prints the time on serial monitor window
Serial.println(t);
Serial.print("Temperature in deg C = "); // prints the temperature in degreeC
Serial.println(tempc);
Serial.print("Temperature in deg F = "); // prints the temperature in degreeF
Serial.println(tempf);
}
void setup()
{
void loop()
{
temp = analogRead(tempPin);
temp = temp * 0.48828125;
Serial.print("TEMPRATURE = ");
Serial.print(temp);
Serial.print("*C");
Serial.println();
delay(1000);
}
void loop()
{
for(i = 0;i< =7;i++){ // gets 8 samples of temperature
samples[i] = ( 5.0 * analogRead(pin) * 100.0) / 1024.0;
tempc = tempc + samples[i];
delay(1000);
}
The LM35 is a common TO-92 temperature sensor. It is often used with the equatio
n
temp = (5.0 * analogRead(tempPin) * 100.0) / 1024;
[Get Code]
However, this does not yield high resolution. This can easily be avoided, howeve
r. The LM35 only produces voltages from 0 to +1V. The ADC uses 5V as the highest
possible value. This is wasting 80% of the possible range. If you change aRef t
o 1.1V, you will get almost the highest resolution possible.
The original equation came from taking the reading, finding what percentage of t
he range (1024) it is, multiplying that by the range itself(aRef, or 5000 mV), a
nd dividing by ten (10 mV per degree Celcius, according to the datasheet: http:/
/www.ti.com/lit/ds/symlink/lm35.pdf
However, if you use 1.1V as aRef, the equation changes entirely. If you divide 1
.1V over 1024, each step up in the analog reading is equal to approximately 0.00
1074V = 1.0742 mV. If 10mV is equal to 1 degree Celcius, 10 / 1.0742 = ~9.31. So
, for every change of 9.31 in the analog reading, there is one degree of tempera
ture change.
To change aRef to 1.1V, you use the command "analogReference(INTERNAL);"
Here's an example sketch using 1.1 as aRef:
void setup()
{
analogReference(INTERNAL);
Serial.begin(9600);
}
void loop()
{
reading = analogRead(tempPin);
tempC = reading / 9.31;
Serial.println(tempC);
delay(1000);
}