ARDUINO TEMPERATURE SENSOR LM35

633,346

143

110

Now make your own temperature sensor by Arduino and LM35 Sensor
You required following parts
1-ARDUINO BOARD ANY VERSION
2-LM35 TEMPERATURE SENSOR
3-USB CABLE
4-COMPUTER WITH ARDUINO SOFTWERE

MAKE THE CONNECTION AS SHOWN IN IMAGE AND UPLOAD THE FOLLOWING CODE ON ARDUINO BOARD.

int val;
int tempPin = 1;

void setup()
{
Serial.begin(9600);
}
void loop()
{
float mv = ( val/1024.0)*5000;
float cel = mv/10;
float farh = (cel*9)/5 + 32;

Serial.print("TEMPRATURE = ");
Serial.print(cel);
Serial.print("*C");
Serial.println();
delay(1000);

/* uncomment this to get temperature in farenhite
Serial.print("TEMPRATURE = ");
Serial.print(farh);
Serial.print("*F");
Serial.println();

*/
}

NOW SEE THE SERIAL MONITOR IN THE ARDUINO SOFTWERE ,
ITS DONE.

VISIT https://www.facebook.com/SparkingElectronics FOR MORE PROJECTS
;)
:)

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson. Participated in the
Weekend Projects Contest

5 People Made This Project!

• • • • • • See 1 More

110 Discussions

We can get value magic number 0.48828125 from following expression:

(SUPPLY_VOLTAGE x 1000 / 1024) / 10 where SUPPLY_VOLTAGE is 5.0V (the voltage used to power LM35)

1024 is 2^10, value where the analog value can be represented by ATmega (cmiiw) or the maximum value it can be represented is 1023. The actual voltage obtained by VOLTAGE_GET / 1024.

1000 is used to change the unit from V to mV

10 is constant. Each 10 mV is directly proportional to 1 Celcius.

By doing simple math: (5.0 * 1000 / 1024) / 10 = 0.48828125

6 replies

#include "DHT.h"

#define DHTPIN 2 // what digital pin we're connected to

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

int val;

int tempPin = 1;

void setup() {

Serial.begin(9600);

Serial.println("Reading DHT11 data! ");

dht.begin();

pinMode(12, OUTPUT); // Green

pinMode(11, OUTPUT); // Red

}

void loop() {

// Reading temperature or humidity takes about 250 milliseconds!

// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

float hum1 = dht.readHumidity();

// Read temperature as Celsius

float temp1 = dht.readTemperature();

// Check if any reads failed and exit early (to try again).

if (isnan(hum1) || isnan(temp1)) {

digitalWrite(11, HIGH);

digitalWrite(12, LOW);

Serial.println("Error in reading sensor data!");

while (isnan(hum1) || isnan(temp1)) {

}

}

else {

digitalWrite(11, LOW);

digitalWrite(12, HIGH);

}

// Wait a few seconds between measurements.

delay(1000);

float hum2 = dht.readHumidity();

float temp2 = dht.readTemperature();

// Compute heat index in Celsius (isFahreheit = false)

float hic = dht.computeHeatIndex(temp1, hum1, false);

Serial.print("Humidity: ");

Serial.print(round((hum1 + hum2) / 2));

Serial.print(" %,");

Serial.print("Temperature: ");

Serial.print((temp1 + temp2) / 2);

Serial.print(" *C ");

//Serial.print("Heat index: ");

//Serial.print(round(hic));

//Serial.println(" *C ");

//lm35 code

float mv = ( val/1024.0)*5000;

float cel = mv/10;

float farh = (cel*9)/5 + 32;

Serial.println("");

Serial.println("Analog sensor Reading !");

Serial.print("TEMPRATURE = ");

Serial.print(cel);

Serial.print("*C");

Serial.println();

Serial.print("Error = ");

Serial.print( ((((temp1 + temp2) / 2)-(cel))/ (cel))*100);

Serial.println(" % ");

Serial.print("Corrected output:");

// Serial.print(( (temp1 + temp2) / 2)+(( (temp1 + temp2) / 2)-(cel)));

Serial.print(cel);

Serial.print("*c");

Serial.println("");

Serial.print("-------------");

Serial.println("");

delay(1000);

if ((round((hum1 + hum2) / 2))>40)

{

//Serial.println("NEW VALUES");

digitalWrite(9, HIGH); // if high humidity on indication

digitalWrite(8, LOW);

}

else //if ((dht.readHumidity()) < 1050)

{

digitalWrite(8, HIGH); // if low humidity another indication i.e. motor on

digitalWrite(9, LOW);

}

}

Hello

const int temp = 0;
void setup()
{
Serial.begin (9600);
pinMode (temp, INPUT);
}
void loop()
{
float Real_Voltage = analogRead(temp)* 0.004882814;
float Temp_C = Real_Voltage * 100.0;
float Temp_F = Temp_C * (9.0/5.0) + 32.0;
Serial.print("Voltage: ");
Serial.print(Real_Voltage);
Serial.print("Deg C: ");
Serial.print(Temp_C);
Serial.print("Deg F: ");
Serial.print(Temp_F);

if ( Temp_C >= 135.0)
{
Serial.println("Warning: The system is hot");
delay(1000);
}
else if (Temp_C
{
Serial.println("Warning: The system is cold");
delay(10000);
}
else
{
Serial.println("The system is functioning well ");
delay(10000);
}
}

But it's output generat without connect lm35 to Arduino Uno r3
In range of -12 to 460