Meça a temperatura usando interface LM35 com Beaglebone preto (Parte 15/15)

Measure temperature using LM35 interface with black Beaglebone (Part 15/15)

Protótipo de monitor de temperatura baseado em sensor Beaglebone Black e LM35

Fig. 1: Temperature monitor prototype based on Beaglebone Black and LM35 sensor

This tutorial explains how to interface LM35 temperature sensor with black Beaglebone to work with sensor interface. The LM35 is an analog sensor that measures temperature and linear output given in the form of voltage. ADC is required to convert the analog output of the temperature sensor into digital output. Since the BBB has an on-chip ADC, you can directly connect these two. The program is written in python script with adafruit GPIO library.

Required tools:

  • Black Beaglebone
  • LM35 breadboard
  • Female to female connectors

Software environment configuration:

Install the latest version of python on BBB as explained in the tutorial How to make the first python program with Beaglebone Black. Install the adafruit python-GPIO library called adafruit_BBIO.

Working:

It is a simple learning tutorial that uses ADC with black Beaglebone. I connected LM35 temperature sensor with BBB 12-bit ADC. The output of the LM 35 is in analog format, which is the input of the ADC. The output of ADC is a digital value and is converted to Celsius and Fahrenheit by formula. The ADC reference voltage is 1.8V. Therefore, you can supply a maximum of 1.8V on the ADC pin.

The step size of the LM 35 is 10 mV, which means that when the temperature changes by 1 degree, the sensor output voltage increases by 10 mV.

Find the Stepsize of the ADC by following the formula:

Step Size = Vref / 212……………………………………………….. (1)

Where Vref is the ADC reference voltage (1.8 V = 1800 mV)

Step Size = 0.44 mv

The digital output is:

Dout = Vin / Stepsize ………………………………………………….. (2)

Where, Vin is the ADC input voltage (LM 35 sensor output)

By the combination formula (1) and (2),

Dout = (Vin * 4096) / 1800………………………………………………. (3)

Here the digital output is 22.75 times larger than the actual output because the Stepsize of LM 35 is 10 mV and the Stepsize of ADC is 0.44 mV so we need to divide it by 22.75 to get the temperature correct in Celsius.

Factor value = 10 mV / 0.44 mV = 22.75 mV

Temperature in Celsius:

Celsius = (Dout)/22.75

Temperature in Fahrenheit:

Fahrenheit = (Celsius * 9/5) + 32

When the script is running, it goes into a continuous loop and displays the temperature in Celsius and Fahrenheit in the terminal. Press ctrl+C to stop the program from running in the SSH command terminal.

Captura de tela do console Linux mostrando leitura de temperatura

Fig. 2: Linux console screenshot showing temperature reading

Description:

Let's first prepare the circuit connection. Take a breadboard and supply VCC and ground from BBB to the breadboard line. Connect 3.3V power from pin number 3 of header P9 and ground from pin number 2 of header P8.

The LM35 has three terminals:

  • Vcc
  • Exit
  • Floor

Diagrama de pinos do sensor de temperatura LM35

Fig. 3: LM35 temperature sensor pin diagram

Terminal vcc is connected with 3.3V supply, Ground is connected to ADC ground of BBB (pin number 34 of header P9). LM 35's output terminal is connected to the input of AIN1 (pin number 40 of header P9).

Imagem do Beaglebone Black usado como monitor de temperatura

Fig. 4: Image of Beaglebone Black used as a temperature monitor

Open the command terminal and access Beaglebone black through SSH as explained in getting started with Beaglebone black . Create a new file using the touch command with .py extension (i.e. LM_35.py) . Open the file with any text editor (i.e. nano, vim etc.) and write code in python language.

Project source code

###


 import Adafruit_BBIO.ADC as ADC
import time Sensor = "P9_40" ADC (Sensor) Configuration while True: Temperature = (float(ADC.read_raw(Sensor))*4096)/1800 Celsius = (Temperature)/22.75 Fahrenheit = (Celsius * 9/5) + 32 print('Temp in C: %dnTemp in F: %dn'%(Celsius, Fahrenheit)) hour.sleep(1)

###

Circuit diagrams

Circuit Diagram-Beaglebone-Black-LM35-Sensor-Temperature-Monitor

Project video

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.