Use a PICAXE Microcontroller to Read and Display Temperature

July 15, 2015 by Charles R. Hampton

The 08M2 is the smallest member of the PICAXE family of microcontrollers; it is inexpensive, versatile, and easy to program using free software.

The 08M2 is the smallest member of the PICAXE family of microcontrollers; it is inexpensive, versatile, and easy to program using free software.

Recommended Level

Intermediate - Previous knowledge of PICAXE suggested.

Project Objectives

  • Assemble a simple circuit using a 08M2 microcontroller (µC), an LM34DZ temperature sensor, and a few other components on a solderless breadboard.
  • Program the µC to read the temperature from the LM34DZ, and display it on your personal computer screen.

Knowledge, Skills, Abilities and Tools Required

In order to successfully complete this project, you will need to be able to do all the following:

  • Read a simple schematic.
  • Use a solderless breadboard.
  • Read the values on resistors and capacitors.
  • Use a Digital Multi-Meter (DMM).
  • Use a wire cutter and stripper.
  • Use a low-wattage soldering iron (optional).

In addition, you should understand the difference between a “leg” and a “pin” in PICAXE parlance. The 08M2 integrated circuit (IC) or “chip” has eight metal leads; there are four on the left side and four on the right side. In the world of PICAXE, these metal leads are called “legs,” and not “pins.” The legs are numbered from one through eight, and leg one is closest to a small depression or dot at the top left of the body of the IC. From leg one, they are counted counter-clockwise around the body of the chip. Thus, legs one through four are on the left side, and legs five through eight are on the right side; legs one and eight are opposite each other.

“Pins,” are the designations used in PICAXE software to identify the functional locations of the inputs and outputs of the µC. Pins are identified using a letter and number combination. Fortunately, for this project, you don’t need to know a lot about pins and the variety of the functions they can perform. Just have a look at the drawing below; it shows the 08M2 with the legs and the pins properly labeled. From this drawing, and the preceding explanation, you should be able to determine how many inputs/outputs (IO’s) are available on the 08M2. Can you tell?


Assembling the Circuit

Electronic circuits are more clearly explained with a schematic drawing, as shown below. As you can see, there are very few components. Additional details about the parts are provided in the parts list. To facilitate assembly of the circuit, a photograph of the completed breadboard is also provided. Compare the schematic drawing, the parts list, and the photograph for a fuller understanding of the circuit configuration.

Temperature Schematic

Breadboard Assembly

The recommended order of assembly is as follows.

  1. First, orient the solderless breadboard as shown in the photograph. The ground rails are identified by a blue line, and the +V rails are identified by a red line. There should be a blue ground rail at the very top of the breadboard and a red +V rail at the very bottom.
  2. Next, place U1 and U2 on the breadboard as shown in the photo; be sure to orient both components exactly as pictured. Leg 1 of U1 is identified in the photo by a white dot, which corresponds to a small dot on the body of the IC. U2 should be oriented with the flat side of its body toward the bottom of the breadboard, which puts pin one on the left, pin two in the center, and pin three on the right. Seat both U1 and U2 so that the metal leads are inserted about ¼” into the breadboard.
  3. Add the resistors and the capacitor. Note that there is no polarity with these components, so they may be placed either way around. Insert the leads about ¼” into the breadboard.
  4. Now, add the red, black, and yellow wires that do not exit the breadboard. Each wire should have its insulation stripped about ¼” and the stripped ends inserted into the breadboard.
  5. Cut three pieces of wire about three inches long, and strip ¼” of insulation off all the ends. It’s less confusing if you can use the same color wires as shown in the photograph, but not absolutely essential. Solder (preferred) or crimp one end of each wire on one of the terminals on the bottom of the jack, J1. In the photograph, the white wire is attached to the top pin (pin 1) on the jack. The black wire is attached to the center pin (pin 2) on the jack. The blue wire is attached to the lower pin (pin 3) on the jack. Regardless of the color of the wire you use, be sure that each pin on the jack is connected to the breadboard in exactly the place shown in the photograph.
  6. Finally, cut one additional piece of red wire and one piece of black wire, and strip the ends. These two wires are used to connect the breadboard to the power supply. The power supply can be any regulated, filtered source of approximately 5VDC, but must not be higher than 5.5VDC. Anything higher than that stands a good chance of damaging the PICAXE µC. Three AA batteries connected in series will work, as will a “wall wart” with a regulated 5VDC output. The +V should be on the red wire, and the ground (0V) should be on the black wire.

Recheck all the wiring. Then, recheck all the wiring again. If there’s a minor problem, the circuit won’t work, but if there’s a power problem, a component could make smoke, and that’s bad news.

When you are satisfied that the wiring is absolutely correct (you did check it twice, right?), connect the power source to the red and black wires going to the solderless breadboard. Using the DMM, measure the DC voltage on U1 by placing the black DMM probe tip on leg eight, and the red DMM probe tip on leg one. You should read approximately 4-5VDC; if so, and there’s no burning smell in the air, disconnect the power leads from the breadboard and pat yourself on the back.

Installing PICAXE Editor 6

For a PICAXE µC to do anything at all, it must be "programmed." Programming consists of writing a series of instructions, called the "program" or the "code," and downloading the instructions to the PICAXE. The makers of PICAXE chips have developed a computer application specifically for writing and downloading PICAXE code: the PICAXE Editor 6, also referred to as PE6.

PE6 is actually not the first, nor the only program that can be used to program PICAXE chips, but it is the latest and is recommended for users of personal computers with a Windows operating system. As of 8 July, 2015, PE6 is at version, and is considered a stable beta version. It is not open source, but is freeware and available to download at the PICAXE web site. 

To install PE6 on your Windows computer:

  1. Go to, and click on the Software tab.

  2. Click on the PICAXE Editor 6 link.

  3. On the PICAXE Editor 6 page, click on the Downloads tab.

  4. Next, click on the PICAXE Editor 6 (main installer) button.

  5. Download PICAXEEditor6.exe, run the program, and follow the instructions.

Note that using Program Editor 6 will require a driver to support the AXE027 cable that you will use between your Windows computer and the PICAXE circuit. That driver is also available at the PICAXE website; follow the instructions to download and install the driver on your computer.

Programming the PICAXE µC

  1. Download the code file PA-08M2 LM34DZ Temperature Reader.bas included with this project, and save it to your computer.

  2. Disconnect power to the PICAXE circuit.

  3. Connect the AXE027 cable from the USB port on your computer to jack J1.

  4. Connect power to the PICAXE circuit.

  5. Start PICAXE Editor 6 (PE6), and maximize the screen.

  6. In the Workspace Explorer window, choose the Settings view. Under PICAXE type, choose PICAXE-08M2. Under COM Port, choose the port corresponding to the USB port you are using with the AXE-027. Under Simulation, choose PICAXE-08M2.

  7. Click the File tab, and choose Open. Navigate to the folder on your computer where your copy of the code file PA-08M2 LM34DZ Temperature Reader.bas is stored. Select the file and open it; it should open in the main editing window of PE6, and should look like the picture below.

  8. In the Workspace Explorer window, change to the Compiler view.

  9. Click the PICAXE tab, and then click Program. The program should begin downloading to the 08M2, and the progress should show in the Compiler view. When the program download has completed, the program will begin running.

  10. To see the temperature output on your computer, click on the Terminal icon at the top left of the PE6 PICAXE tab screen. The terminal window will open, and you should see the temperature displayed much like the screenshot below.

Note that the temperature is displayed in degrees Fahrenheit, and is refreshed about once per second. Grasp the body of the LM34DZ lightly between your thumb and index finger, and watch the temperature climb, then release the LM34DZ, and watch the temperature return to ambient.

Calibrating the Code

The circuit will display the temperature of the LM34DZ based on the inherent accuracy of the IC, and the accuracy of the calculations contained in the code. You can’t do much about the built-in accuracy of the LM34DZ, but you can (and should) tweak the code to improve its accuracy in your assembly.

A complete explanation of the code is beyond the scope of this project, but you need to have the math in the code match the actual supply voltage of your circuit. To check and resolve any accuracy issues, follow the steps below:

  1. Connect power to the circuit, and using the DMM, measure the DC voltage on U1 by placing the black DMM probe tip on leg eight, and the red DMM probe tip on leg one. Record the exact reading. (The code included with this project was based on a supply voltage of 4.919VDC, but your voltage will almost certainly be different.)

  2. Divide the voltage reading by 1024. (4.919 ÷ 1024 = .0048037)

  3. Multiply the result by 1000, and round that result to two decimal places. (0048037 × 1000 = 4.80)

  4. In lines 24, 25, and 26 of the code, replace the dark blue numerals 4, 8, and 0 with the corresponding results you obtained in Step 3.

  5. Save the code file with your changes, and then download it to the circuit. The results shown in the Terminal window will be more accurate when the code reflects your circuit's power supply voltage.

Feel free to experiment with the code. The worst that can happen is that it stops running, in which case, you can simply go back to the original code posted with this project, and continue your experiments.

Final Thoughts

If you prefer to measure temperature in Celsius instead of Fahrenheit, simply substitute an LM35DZ for the LM34DZ, and change (F) in line 29 of the code to (C). 

If your computer has a serial connection, you can use a serial cable such as the AXE026 instead of the AXE027 for programming. You could also make your own serial cable, but that is not recommended for beginners.

The algorithm for reading and converting the output from the LM34DZ is widely available on the web. The code in this project was adapted from the work of P. H. Anderson and others.

Additional information and software for programming PICAXE µCs at is available here.

Give this project a try for yourself! Get the BOM.