How to connect Temperature Sensor to Arduino Uno?
The LM35 IC has 3 pins-2 for the power supply and one for the analog output.It is a low voltage IC which uses approximately +5VDC of power.The output pin provides an analog voltage output that is linearly proportional to the Celsius (centigrade) temperature. Pin 2 gives an output of 1 millivolt per 0.1°C (10mV per degree).So to get the degree value in Celsius, all that must be done is to take the voltage output and divide it by 10-this give out the value degrees in Celsius.
The circuit connections are made as follows:
- Pin 1 of the LM35 goes into +5V of the arduino
- Pin 2 of the LM35 goes into analog pin A0 of the arduino
- Pin 3 of the LM35 goes into ground (GND) of the arduino
Program for Temperature Sensor Circuit
Before getting a Celsius reading of the temperature,the analog output voltage must first be read. This will be the raw value divided by 1024 times 5000. It is divided by 1024 because a span of 1024 occupies 5V. Here we get the ratio of the raw value to the full span of 1024 and then multiply it by 5000 to get the millivolt value. Since the output pin can give out a maximum of 5 volts (1024), 1024 represents the possible range it can give out. The raw voltage over this 1024 (value) therefore represents the ratio of how much power the output pin is outputting against this full range.Once we have this ratio, we then multiply it by 5000 to give the millivolt value. This is because there is 5000 millivolts in 5 volts.Refer here for more about analog voltage calculations. Once this analog voltage in millivolts is calculated, we then can find the temperature in Fahrenheit by the equation: ((Celsius * 9)/5 + 32).At the end of this program,a delay of 5000ms is included to take the temperature reading every 5 seconds.
//initializes/defines the output pin of the LM35 temperature sensor int outputpin= A0; //this sets the ground pin to LOW and the input voltage pin to high void setup() { Serial.begin(9600); } //main loop 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); }