B4R Arduino LM35 temperature sensor example

In this example we will connect an LM35 temperature sensor to our Arduino

The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The LM35 does not require any external calibration or trimming to provide typical accuracies of ±1/4°C at room temperature and ±3/4°C over a full -55 to +150°C  temperature range

Here is a picture of the pins, its important to get these correct or you can damage the sensor

I purchased a small module, which looks like this. This was clearly labelled and helps avoid any mistakes with wiring, I also prefer using cables to modules rather than breadboards


Schematics and Parts

You will need

Arduino Uno
LM35 sensor or module
Hook up wire (dupont cables)

Very simple to connect Vcc is 5v, Gnd is any Gnd and out goes to Arduino A1, you can see this below




Sub Process_Globals
Public Serial1 As Serial
Private SensorPin As Pin 'Output pin connected from the TMP36 sensor
Private SensorPinNumber As Byte = 0x01 'Pin number used is A1 (Analog)
Private MeasureTimer As Timer 'Timer for the sensor measurement
Private MeasureTimerInterval As ULong = 2 'Timerinterval in seconds
End Sub
Private Sub AppStart
Log("AppStart - Pin ", SensorPinNumber, " read every ", MeasureTimerInterval, " seconds")
'Init the pin with LM35 connected
SensorPin.Initialize(SensorPinNumber, SensorPin.MODE_OUTPUT)
'Init the timer
MeasureTimer.Initialize("MeasureTimer_Tick", MeasureTimerInterval * 1000)
'Start the timer
MeasureTimer.Enabled = True
End Sub
'Handle the timer ticks
Private Sub MeasureTimer_Tick
'Read the current state of the pin
Dim rawvoltage As UInt = SensorPin.AnalogRead
Log("Raw voltage: ", rawvoltage)
'Convert rawvoltage
'Voltage = (RawValue / 1023.0) * 5000; // 5000 To get millivots.
'tempC = Voltage * 0.1;
'tempF = (tempC * 1.8) + 32; // conver To F
Dim Voltage As Double = (rawvoltage/1023.0) * 5000
Dim tempC As Double = Voltage * 0.1
Log("Temperate (c) = ", tempC)
Dim tempF As Double = (tempC * 1.8) + 32
Log("Temperate (f) = ", tempF)
End Sub



You should see the following

AppStart – Pin 1 read every 2 seconds
Temperate (c) = 21.5054
Temperate (f) = 70.7097
Raw voltage: 44
Temperate (c) = 21.5054
Temperate (f) = 70.7097
Raw voltage: 44
Temperate (c) = 21.5054
Temperate (f) = 70.7097
Raw voltage: 48
Temperate (c) = 23.4604
Temperate (f) = 74.2287
Raw voltage: 51
Temperate (c) = 24.9267
Temperate (f) = 76.8680
Raw voltage: 53
Temperate (c) = 25.9042
Temperate (f) = 78.6276
Raw voltage: 54
Temperate (c) = 26.3930
Temperate (f) = 79.5073



LM35 datasheet

5PCS LM35D Temperature Sensor TO92 Packing