LM35 Temperature Sensor
by innovativetom in Circuits > Sensors
100583 Views, 73 Favorites, 0 Comments
LM35 Temperature Sensor
“Arduino can sense the environment by receiving input from a variety of sensors and can affect its surroundings by controlling lights, motors, and other actuators. The microcontroller on the board is programmed using the Arduino programming language”. Using the Arduino I will show you how to get the analog input from the LM35 temperature sensor and display the information in the serial window as raw data, celsius and fahrenheit.
For the purpose of the post I will assume that you already know how to download and install the Arduino software and load a sketch onto it.
What You Need
What you will need:
Arduino UNO, Leonardo or equivalent
Breadboard
Jumper Wires
USB Cord
LM35 temperature sensor Data Sheet
Wiring:
Wire up the breadboard as depicted in this picture.
Code
The code can be downloaded here.
or Copy and paste this into the arduino sketch.
/*<br>Simple Temperature uses the lm35 in the basic centigrade temperature configuration */ float temp; int tempPin = 2; // analog input pin int sampleTime = 1000; // 1 second dafault
void setup() { Serial.begin(9600); }
void loop() { //gets and prints the raw data from the lm35 temp = analogRead(tempPin); Serial.print("RAW DATA: "); Serial.print (temp); Serial.println(" "); //converts raw data into degrees celsius and prints it out // 500mV/1024=.48828125 temp = temp * 0.48828125; Serial.print("CELSIUS: "); Serial.print(temp); Serial.println("*C "); //converts celsius into fahrenheit temp = temp *9 / 5; temp = temp + 32; Serial.print("FAHRENHEIT: "); Serial.print(temp); Serial.println("*F"); delay(sampleTime); }
Load the code into to your board and open the serial monitor you should see both fahrenheit and celsius.