# Getting Started with MicroPython and the SparkFun Inventor's Kit for micro:bit

Pages
Contributors: LightningHawk

## Experiment 7: Reading the Temperature Sensor

### Introduction

A temperature sensor is exactly what it sounds like — a sensor used to measure ambient temperature. In this experiment you will read the raw 0–1023 value from the temperature sensor, calculate the actual temperature and then print it out over the LED array on your micro:bit.

#### Parts Needed

You will need the following parts:

• 1x micro:bit
• 1x micro:bit Breakout with Headers
• 3x Jumper Wires
• 1x TMP36 Temperature Sensor

#### Didn’t Get the SIK for micro:bit?

If you are conducting this experiment and didn’t get the Inventor’s Kit, we suggest using these parts:

PRT-12002
\$4.95
36

DEV-14208
\$14.95
5

BOB-13989
\$5.49
1

PRT-12795
\$1.95
2

SEN-10988
\$1.50
16

### Introducing the TMP36 Temperature Sensor

The TMP36 is a low-voltage precision centigrade temperature sensor. It provides a voltage output that is linearly proportional to the Celsius temperature. It also doesn’t require any external calibration to provide typical accuracies of ±1°C at +25°C and ±2°C over the −40°C to +125°C temperature range. The output voltage can easily convert to temperature using the scale factor of 10 mV/°C.

If you are looking at the flat face with text on it, the center pin is your signal pin, the left-hand pin is supply voltage (3.3V in this tutorial), and the right-hand pin connects to ground.

Pro Tip: The TMP36 looks a lot like a transistor. Put a dot of fingernail polish on the top of your TMP36 so it’s easy to find.

### Hardware Hookup

Ready to start hooking everything up? Check out the wiring diagram below to see how everything is connected.

 Polarized Components Pay special attention to the component’s markings indicating how to place it on the breadboard. Polarized components can only be connected to a circuit in one direction.

Please note: The temperature sensor can only be connected to a circuit in one direction. See below for the pin outs of the temperature sensor — TMP36.

#### Wiring Diagram for the Experiment

Having a hard time seeing the circuit? Click on the wiring diagram for a closer look.

### Code to Note

#### str

We have already covered `display.show()` but we need to convert our number (temperature) to a string (type) before displaying it to the micro:bit 5x5 LED array. Type conversion in MicroPython is a snap with a simple `str` placed in front of the variable holding the temperature of type number.

CHALLENGE: How would you modify this code to get the temperature in degrees Fahrenheit?

### What You Should See

When your micro:bit turns on, the temperature reading from the TMP36 temperature sensor will be displayed and scrolled across the LED array.

### Troubleshooting

#### Temperature Value is Unchanging

Try pinching the sensor with your fingers to heat it up or pressing a bag of ice against it to cool it down.

#### Temperature Sensor is Really Hot!

You have wired it backward! Unplug your micro:bit immediately, let the sensor cool down and double check your wiring. If you catch it soon enough, your sensor may not have been damaged and may still work.

In 2003, CU student Nate Seidle blew a power supply in his dorm room and, in lieu of a way to order easy replacements, decided to start his own company. Since then, SparkFun has been committed to sustainably helping our world achieve electronics literacy from our headquarters in Boulder, Colorado.

No matter your vision, SparkFun's products and resources are designed to make the world of electronics more accessible. In addition to over 2,000 open source components and widgets, SparkFun offers curriculum, training and online tutorials designed to help demystify the wonderful world of embedded electronics. We're here to help you start something.