Low Power Wireless Temperature Sensor
PROJECT BOARD

This was the first time I attempted a very low power battery powered project.  I had built several temperature sensors using the DS18B20 but this time I wanted an outside sensor and I didn't want to run a lot of wire thru the walls of my house.  So the software to obtain the temperature using the DS18B20 is pretty much the same as the earlier projects.  What is different is the necessity to minimize power use.

The MC9S08QE8 was touted for ultra-low-power so I chose it as the MCU.  I found the stop mode a little tricky to set up but I worked it out.  The XBee wireless modules from Digi are wonderful short range wireless transceivers.  This project uses them in only their most simple mode but they have many complex networking possibilities.  You need two XBee's, of course.  Right now I have one in the outdoor sensor board and the other in a USB Sparkfun module connected to my PC.  Use a program from Digi called X-CTU to set the source and destination addresses of the XBee.  To make it simple I set the source address to zero and the destination to one on the transceiver connected to the PC.  The XBee in the outdoor sensor has that reversed.

At this point the project sends the data out to my PC.  In future enhancements the data could be used in a graphing program or it could be used by another microcontroller to log the data and/or display it on a display perhaps like my LED Dot Matrix Display Board.

 
Click for a large view

If you would rather not program the MCU yourself you can get it pre programmed.  Check my ordering page.

Put the project board and batteries in a suitable enclosure and put it outside in the shade, perhaps on the north side of your house, a few feet off the ground where there is good air circulation.

You may wish to drill a small hole and run the sensor through it for faster temperature response.  In my case I just left the sensor inside the enclosure.

Low Power Wireless Temperature Sensor schematic

R1 is the pull-up for the off board DS18B20
R2 and the six pin header is for the BDM used to program the MCU.
R3 and the LED are for debugging; leave them off for longer battery life.
IC1 is the MCU
IC2 is a LM2936Z-3.0  This is a low dropout 3 volt regulator that I am using with a three cell AAA battery pack.  You could skip the regulator and use a two cell battery pack or other 3 volt source.  I felt that this would give me the longest time before having to change batteries.  Only time will tell; come back in a year.

This is about five minutes of data from shortly after sunrise when it was warming up quickly.

Assembly language software (Version 1) for MC9S08QE8

First establish a connection with your PC.  After you install the USB module determine the COM port and open your favorite terminal program with that COM port number.  Set the baud rate to 9600.  Then install the batteries.  The project board should send a wake up message to the terminal program.  You can test the DS18B20 by typing the command: TEMP.  The MCU will respond with the temperature and the serial number of the DS18B20.  If it does, everything is working as it should be but the XBee transceiver is still powered and using 50 ma.  Now type the command: SLEEP.  The XBee will go into hibernate mode and use less than 10 µ amps.

When the MC9S08QE8 goes into stop3 mode the supply current drops to less than 1 µ amp.  In stop3 mode all the clocks and peripherals become inactive except the very low power Real Time Clock.  I have programmed the RTC to awaken the MCU ever 20 seconds.  At that point it takes a temperature reading and checks the Vdd voltage.  This takes about 3/4 of a second; then it wakes the XBee and send out the data, maybe another tenth of a second then everything goes back to sleep.

For BDM's

  Lowest cost.

The 9S08 family is programmed using a Background Debug Module and Code Warrior.  CW can be downloaded from the Freescale website.

 

 

TWO YEARS LATER

 


 

I used the Temperature Sensor board, above, for about a third of a year.  Although it performed well I was unhappy with the three battery approach.  The linear regulator inherently wastes power, and worse, it wastes the most when the batteries are freshest.

So, I changed to a two battery holder and removed the regulator.  It worked well when the batteries were fresh but as time went on the output voltage dropped.  The DS18B20 temperature sensor is rated from 3 to 5 volts.  When the battery voltage dropped to about 2.9 volts the sensor started to give inaccurate temperature readings (it read high).  It wasn't too noticeable at first but got worse as the voltage got lower.  At some point the XBee stopped working.  There was still energy in the batteries but it wasn't usable.  The two battery approach was only good if they were fresh.

So I got a Sparkfun 3.3 Volt step-up breakout board and wired it into the prototype area.  Now I had a constant 3.3 V and the DS18B20 and XBee worked well.  Until it stopped.  When the battery voltage finally dropped to the point that the step-up converter stopped working the circuit stopped without warning.  I needed to monitor the battery voltage so that I could change the batteries when they were low and at a convenient time.

So I redesigned the board and added a trace from battery input to the MCU to measure the voltage.  I also made the board a bit smaller by eliminating the prototype area.  I had to change the software, of course.  Besides adding the battery voltage as part of the output I made it so the period of time between readings can be set by the user.  The command to do this is PERIOD  xx  Where xx is the number of seconds the MCU sleeps, between 2 and 255. The value is saved in flash so you do not have to reset it when you change batteries.  Here is an Excel spreadsheet that gives a rough approximation of battery life depending on period.  In my home I use the sensor with a PERIOD of 20 seconds which gives me a battery life of about 45 days.  Here is an Excel spreadsheet with a graph of a voltage curve over that time.

 
Click for larger view

Here is the Rev 2 Schematic.

Here is the software Version 2.

If you would rather not program the MCU yourself you can get it pre programmed.  Check my ordering page.

This is Revision 3.  I reduced the size of the board somewhat to reduce the cost.  The software is the same as Rev 2.  I decided to sell the blank pcb directly.  Check my ordering page.

From time to time I will have parts kits and/or assembled units.  Email me for availability.

Use minimal amount of solder when mounting the 2mm 10pin XBee Socket.  It has a tendency to wick into the socket.  See the comments on this page.

The display to the left on a terminal emulator program could be described as verbose.  This is fine for a PC screen but not the most convenient format if the goal is to send the data to another embedded device.
The display to the upper left is from a terminal emulator program.  If you would prefer a graphical representation of the same data check out the screen cut to the left.

It is a Processing sketch.  Download the zip file.

On my computer the XBee to USB adaptor is on COM84.  Find the line of code below and change that to whatever COM port you are using.

After you are satisfied with the way the Processing sketch is running you can convert it to a stand alone Thermometer.exe program.  Look in the Files tab of Processing.

There is another command called LIN.  That will format the same information so each data item is on a new line with reduce verbiage.  See screen dump to the left.  In addition each line is preceded by a control character which can be seen by the screen to the right where all characters are shown in hexadecimal.  The first line preceded by hex 11, then hex 12 and 13.

XBee

There are two different kinds of XBee radios.  Series 1 is basically for point to point, very reliable and simple communication.  Technically called a 802.15.4 stack.  This is the radio the Low Power Temperature Sensor is designed to work with.

The other kind is a Series 2.  These modules allow you to create complex mesh networks based on the XBee ZB ZigBee mesh firmware.  They will work with the  Low Power Temperature Sensor but require some special setup.  I tested the Series 2 with two radios; not exactly an "network".  This is what I did:

The radio connected to the  Low Power Temperature Sensor was configured as an END AT and the one connected to the PC as a COORDINATOR AT.  At first it didn't work but I found that a value called SN or "Number of Cyclic Sleep Periods" should be set to a higher value than default.  I used 100 but that could vary with the number of radios and the PERIOD of the sensor.  This value must be programmed into the COORDINATOR AT with X-CTU.  I think that when the XBee comes out of hibernation it takes time to negotiate an network path.  Setting the higher SN value helps it to remember the path longer.  I also put in a few delay tweaks that help a bit (see below).  Bottom line is that it worked once it was in SLEEP mode but the output was a little irregular, based I think, on buffering in the system.  The screen dump to lower right is with a Series 2 XBee.

Building Wireless Sensor Networks by Robert Faludi is recommended reading.
Xbee part numbers overview may be helpful.

Software Versions

Here is the software Version 3.  For the normal system of a sensor using a Series 1 XBee, Fahrenheit temperature and PERIODS based in seconds it is basically unchanged from the previous version.

But I had requests for a longer interval between temperature reading than 255 seconds.  So there is a Long Period version where the PERIOD is minutes rather than seconds.  So you can set it for up to 255 minutes between readings.

Then there is the Series 2 tweak version as described above.

And finally for our friends outside of the US there is the Celsius version.  These variations are selected by conditional assembly.  The screen dump to the right has the MCU programmed with both Series 2 and Celsius selected.  As a test I put the Sensor in my freezer for awhile.

If you choose to buy a preprogrammed MCU from me just ask for the versions you want.  See  my ordering page

In June, 2014 I tried using a XBee Pro.  I expected to get a shorter battery life.  Surprisingly it was about the same a the regular XBee.  I did notice that the unit failed when the battery voltage got down to 2.2 Volts.  It usually works until the voltage gets down to 2.0 Volts.  I replaced the batteries and am trying another cycle.  Expect an update in mid September 2014  

Roger's Embedded Microcontrollers Home Page     


This page written by Roger Schaefer. Last updated July 31, 2014