ARDUINO TEMPERATURE SENSOR LM35

578,746

140

109

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()
{
val = analogRead(tempPin);
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
;)
:)


5 People Made This Project!

Recommendations

  • Make it Glow Contest 2018

    Make it Glow Contest 2018
  • PCB Contest

    PCB Contest
  • Toys Contest

    Toys Contest

109 Discussions

0
None
spradana1

4 years ago on Introduction

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
0
None
conorb1spradana1

Reply 3 years ago

Sorry for asking this but what is the magic number you refer to about? What is the importance of it

0
None
peter.mbiriaconorb1

Reply 2 years ago

I think he meant the calibration value. instead of doing all the computation , just get the value from the sensor and multiply it with that value

0
None
minimadmalcspradana1

Reply 4 years ago on Introduction

Hi Please can you tell me if I was to run this program through a Attiny85 on 4.5 volts what formula would I need to use to get the correct results?

0
None
spradana1minimadmalc

Reply 4 years ago on Introduction

you can substitute the SUPPLY_VOLTAGE part which result in

(SUPPLY_VOLTAGE x 1000 / 1024) / 10 = (4.5 x 1000 / 1024) / 10 =

0.439453125

0
None
sghosh21spradana1

Reply 4 years ago on Introduction

the supply voltage doesn't really matter , i think the analog to digital converter matters though, coz see we can even power the LM35 with a 20 v power supply, if we do that and still read the analog value from arduino, your equation will not hold,

0
None
spradana1sghosh21

Reply 4 years ago on Introduction

Indeed the supply voltage can ranging from +35V to -0.2V. Well, I got the equation from the LM35 datasheet and never done things outside the datasheet.

0
None
INDHRAK

3 months ago

#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)) {

hum1 = dht.readHumidity();

temp1 = dht.readTemperature();

}

}

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

val = analogRead(tempPin);

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

}

}

0
None
TAPAN MOJIDRAMOUNIKA DATTA

Reply 2 years ago

Don't keep the length of sensor pin wire (A0- to lm35) long..
kepp it as short as possible

0
None
gabimal_roTAPAN MOJIDRA

Reply 9 months ago

Hi,

It is short, actually I have inserted the output pin of LM35 directly into the board. Same high readings,+140 degrees. Any idea why?

0
None
TAPAN MOJIDRAMOUNIKA DATTA

Reply 3 years ago

just check the wiring once again ...
see the picture and connect exactly as shown in image

0
None
IanV48

11 months ago

wow

0
None
RamkulovHarDizzeR

Reply 12 months ago

Mine even hotter

TEMPRATURE = 499.02*C

0
None
himan0110

1 year ago

I made it.

I was trying to put date and time next to the temp so that I can do some analytics on the data. Can someone please help me with the code ? Thanks

0
None
TadiT1

1 year ago

the output values are not making ant sense when i kept the sensor in different climatic conditions.they are printing the same values

0
None
blackburdtx

2 years ago

Very easy, I recieved temperature in F on the serial output. Now I want to output the script to a multi digit LED Dispaly.

0
None
HarryA32

2 years ago

instructions are useful but can i connect this project with ni labview?