Saturday, 11 October 2014

Temperature sensor LM35


We need:

Sensor LM35:



Connections schema:


We can connect LM35 to 5V or 3.3V, it doesn't matter.


Photo from my LM35 connections:



Example python app lm35_test.py:
from pyfirmata import ArduinoMega
from pyfirmata.util import Iterator
import time

board = ArduinoMega('/dev/ttyUSB0') # connect to arduino usb port

iterator = Iterator(board) # start reading analog input
iterator.start()

pinTemp = board.get_pin('a:0:i') # set valid in analog pin

while True:
    voltage = pinTemp.read() # read voltage input
    if voltage is not None: # first read after startup is somtimes None
        temp = 5.0*100*voltage # convert voltage to temperature
        print "{0} Celsius".format(temp)
        time.sleep(1) # 1 second waiting 


Run python environment (see Firmata - Raspberry Pi (part 2)), for example:
# cd robot/python_firmata_test/
# source bin/activate
and run app:
# python2.7 lm35_test.py
Screenshoot form app:


LM35 is theoretically appropriately calibrated but in my opinion, given the temperature is overestimated by about 2-4 degrees CelsiusI had a reference (room thermometer;) ) thermometer.


links:
http://raspberrypi-aa.github.io/session3/firmata.html
http://www.ladyada.net/learn/sensors/temp36.html
http://www.ti.com.cn/cn/lit/ds/symlink/lm35.pdf

No comments:

Post a Comment

Note: only a member of this blog may post a comment.