# Measuring Temperature with a BeagleBone Black

## Overview

In this tutorial, you will learn how to connect temperature sensor to a BeagleBone Black.

![](https://cdn-learn.adafruit.com/assets/assets/000/009/307/medium800/beaglebone_overview_web.jpg?1396887274)

Because the BBB runs Linux, there are many ways in which it can be programmed. In this tutorial we show how to read analog values form a TMP36 temperature sensor using Python.  
  
The temperature sensor chip used is the TMP36. You can find out more about this chip here: [http://learn.adafruit.com/tmp36-temperature-sensor/overview](http://learn.adafruit.com/tmp36-temperature-sensor/overview)

# Measuring Temperature with a BeagleBone Black

## You WIll Need

To try out this tutorial, you will need:

# Measuring Temperature with a BeagleBone Black

## Installing the Python Library

This tutorial uses Ångström Linux, the operating system that comes pre-installed on the BBB.  
  
Follow the instructions here, to install the Python IO BBIO library. [http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black](http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black "Link: http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black")

# Measuring Temperature with a BeagleBone Black

## Wiring

Wire up the solderless breadboard using the header leads as shown below.

![](https://cdn-learn.adafruit.com/assets/assets/000/009/312/medium800/beaglebone_fritzing.png?1396887361)

Make sure that you get the TMP36 the right way around.  
  
The blue lead is connected from the GNDA\_ADC connection to the GND pin of the TMP36 temperature sensor. The red lead is connected from pin 3 of the other connector (3.3V) to the positive supply pin of the TMP36 and the orange lead to pin P9.40. Note that only certain pins can be used as analog inputs (see [http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/adc](http://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/adc))  
  
The pins are numbered left to right, 1, 2 then on the next row down 3,4 etc. You can find out about all the pins available on the P8 and P9 connecters down each side of the BBB here: [http://stuffwemade.net/hwio/beaglebone-pin-reference/](http://stuffwemade.net/hwio/beaglebone-pin-reference/)

# Measuring Temperature with a BeagleBone Black

## The Python Console

Before writing a Python program to measure and report the temperature, we can try some experiments in the Python Console.  
  
To launch the Python Console type:

```auto
# python
Python 2.7.3 (default, Apr  3 2013, 21:37:23) 
[GCC 4.7.3 20130205 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
```

First, we need to import the library, so enter the command:

```auto
>>> import Adafruit_BBIO.ADC as ADC
```

Now enter the command below into the Python Console to setup the ADC (Analog to Digital Convertor).

```auto
>>> ADC.setup()
```

You can now read the value at the analog input (between 0 and 1) using the command below. Try it a few times while putting your finger on the TMP36 to warm it up. The readings should gradually increase.

```auto
>>> ADC.read("P9_40")
0.38999998569488525
>>> ADC.read("P9_40")
0.38833332061767578
>>> ADC.read("P9_40")
0.39722222089767456
>>> ADC.read("P9_40")
0.42500001192092896
```

Info: 

These readings are not yet an actual temperature, so in the next section we will write a short Python program to display the temperature in both degrees C and F.

# Measuring Temperature with a BeagleBone Black

## Writing a Program

Exit the Python Console by typing:

```auto
>>> exit()
```

This should take you back to the Linux prompt.  
  
Enter the following command to create a new files called **tmp36.py**

```auto
nano tmp36.py
```

Now paste the code below into the editor window.

```auto
import Adafruit_BBIO.ADC as ADC
import time

sensor_pin = 'P9_40'

ADC.setup()

while True:
    reading = ADC.read(sensor_pin)
    millivolts = reading * 1800  # 1.8V reference = 1800 mV
    temp_c = (millivolts - 500) / 10
    temp_f = (temp_c * 9/5) + 32
    print('mv=%d C=%d F=%d' % (millivolts, temp_c, temp_f))
    time.sleep(1)
```

![](https://cdn-learn.adafruit.com/assets/assets/000/009/313/medium800/beaglebone_nano.png?1396887398)

Save and exit the editor using CTRL-x and the Y to confirm.  
  
To start the program, enter the command:

```auto
python tmp36.py
```

You will then see a series of readings.

```auto
mv=757 C=25 F=78
mv=760 C=26 F=78
mv=762 C=26 F=79
mv=765 C=26 F=79
mv=763 C=26 F=79
mv=763 C=26 F=79
mv=766 C=26 F=79
mv=768 C=26 F=80
```

When you want to stop the readings, use CTRL-c.

Info: 

# Measuring Temperature with a BeagleBone Black

## Next Steps

Now that you can measure the temperature, you could do other things with it like displaying a message when the temperature exceeds some limit.   
  
You could also use the project as a temperature logger, using Python to write the readings to a file, each accompanied by a time stamp. If the temperatures are written one per line, with a comma between the time and the reading, then you will be able to import it directly into a spreadsheet and produce charts from the data.

 **About the Author.**  
As well as contributing lots of tutorials about Raspberry Pi, Arduino and now BeagleBone Black, Simon Monk writes books about open source hardware. You will find his books for sale [here](http://www.adafruit.com/index.php?main_page=adasearch&q=simon+monk) at Adafruit.
## Featured Products

### BeagleBone Black - Rev B

[BeagleBone Black - Rev B](https://www.adafruit.com/product/1278)
**[Adafruit is no longer shipping the BeagleBone Black Rev B, it has been replaced with the Rev C as of 5/12/14](https://www.adafruit.com/products/1876) - the Rev C now has 4G flash and also comes with Debian, it also costs slightly more. There are no exchanges or...**

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1278)
[Related Guides to the Product](https://learn.adafruit.com/products/1278/guides)
### TMP36 - Analog Temperature sensor

[TMP36 - Analog Temperature sensor](https://www.adafruit.com/product/165)
Wide range, low power temperature sensor outputs an analog voltage that is proportional to the ambient temperature. To use, connect pin 1 (left) to power (between 2.7 and 5.5V), pin 3 (right) to ground, and pin 2 to analog in on your microcontroller. The voltage out is 0V at -50°C and...

In Stock
[Buy Now](https://www.adafruit.com/product/165)
[Related Guides to the Product](https://learn.adafruit.com/products/165/guides)
### Adafruit Proto Plate for Beagle Bone & Beagle Bone Black

[Adafruit Proto Plate for Beagle Bone & Beagle Bone Black](https://www.adafruit.com/product/702)
Ready to prototype your next [Beagle Bone](http://www.adafruit.com/products/1278) project? You'll certainly want this handy Proto-Plate! Not only is it really good looking, its also very useful, holding your [Beagle Bone or Beagle...](http://www.adafruit.com/products/1278)

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/702)
[Related Guides to the Product](https://learn.adafruit.com/products/702/guides)
### Half Sized Premium Breadboard - 400 Tie Points

[Half Sized Premium Breadboard - 400 Tie Points](https://www.adafruit.com/product/64)
This is a cute, half-size breadboard with&nbsp;400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm&nbsp;x 5.5cm&nbsp;with a standard double-strip in the middle and two power rails on both sides.&nbsp;You can pull the power rails off easily to make the breadboard as...

In Stock
[Buy Now](https://www.adafruit.com/product/64)
[Related Guides to the Product](https://learn.adafruit.com/products/64/guides)
### Breadboarding wire bundle

[Breadboarding wire bundle](https://www.adafruit.com/product/153)
75 flexible stranded core wires with stiff ends molded on in red, orange, yellow, green, blue, brown, black and white. These are a major improvement over the "box of bent wires" that are sometimes sold with breadboards, and faster than stripping your own solid core wires. Makes...

In Stock
[Buy Now](https://www.adafruit.com/product/153)
[Related Guides to the Product](https://learn.adafruit.com/products/153/guides)

## Related Guides

- [Character LCD with Raspberry Pi or BeagleBone Black](https://learn.adafruit.com/character-lcd-with-raspberry-pi-or-beaglebone-black.md)
- [Adding a Real Time Clock to BeagleBone Black](https://learn.adafruit.com/adding-a-real-time-clock-to-beaglebone-black.md)
- [Bone Box](https://learn.adafruit.com/bone-box.md)
- [Connecting a Push Button to BeagleBone Black](https://learn.adafruit.com/connecting-a-push-button-to-beaglebone-black.md)
- [RePaper eInk Development Board for ARM + GNU/Linux](https://learn.adafruit.com/repaper-eink-development-board-arm-linux-raspberry-pi-beagle-bone-black.md)
- [DHT Humidity Sensing on Raspberry Pi or Beaglebone Black with GDocs Logging](https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging.md)
- [MPR121 Capacitive Touch Sensor on Raspberry Pi & BeagleBone Black](https://learn.adafruit.com/mpr121-capacitive-touch-sensor-on-raspberry-pi-and-beaglebone-black.md)
- [Controlling a Servo with a BeagleBone Black](https://learn.adafruit.com/controlling-a-servo-with-a-beaglebone-black.md)
- [BNO055 Absolute Orientation Sensor with Raspberry Pi & BeagleBone Black](https://learn.adafruit.com/bno055-absolute-orientation-sensor-with-raspberry-pi-and-beaglebone-black.md)
- [Adafruit WebIDE](https://learn.adafruit.com/webide.md)
- [Using the BMP085/180 with Raspberry Pi or Beaglebone Black](https://learn.adafruit.com/using-the-bmp085-with-raspberry-pi.md)
- [MCP9808 Temperature Sensor Python Library](https://learn.adafruit.com/mcp9808-temperature-sensor-python-library.md)
- [Trellis Python Library](https://learn.adafruit.com/trellis-python-library.md)
- [SSH to BeagleBone Black over USB](https://learn.adafruit.com/ssh-to-beaglebone-black-over-usb.md)
- [Fading a RGB LED on BeagleBone Black](https://learn.adafruit.com/fading-a-rgb-led-on-beaglebone-black.md)
