■ FIGURE 4
■ FIGURE 5
converter on different 16F870 PICs. They tend to show
anywhere from .1 degrees to 1.5 degrees high or low from
the actual temperature measured by the LM34 sensor. The
16F870 chip I used in my unit indicated a temperature of
. 8 degrees higher than from the LM34 sensor. I added an
extra step in the program to correct for this.
In the program, I have included this step, but you
may have to change that value depending on the
measurements you note in your own unit.
In the rich text format version of the program
(8Bit TstatRTClk2.rtf), that line is shown in red. There are
more details on this available from the file on the Nuts &
The third problem to solve was multiplexing the input
signals to only use up to four ports on the PIC (there are
eight for each of the function inputs). I used diodes to
convert each pushbutton input to a binary number. That
worked well because with four inputs, a maximum count
of 16 can easily be represented, i.e., 2 to the fourth power,
or binary 1111 (see Figure 1). The printed circuit board
(PCB) for this encoder is also available on the website.
The fourth problem was getting a pulse every second,
but getting it short enough to only increment or decrement
the functions once per second. Since the main clock loop
in the program loops through every .065536 seconds, the
pulse width had to be the same length. To get the pulse
out of the PIC once per second required a timing loop to
count from 0 to 15 and give a high pulse on only one of
those loops. (See the text version of 8Bit TstatRTClk2.txt;
the last item in the program shows how this was done.)
The final problem was converting the + 5 volts output
from the PIC output port to control the 24 volts AC to the
heating/cooling relays. That was accomplished using an
MOC3033 opto-coupled, zero-crossing detector triac to
control a higher power triac to switch up to one amp of
current into the 24 VAC heating/cooling relays.
Construction and Connections
Since I only needed to make two PCBs (thermostat
and eight line to four line encoder), I first cut the double
copper clad PCBs to the correct dimensions; 3. 7” x 3.1”
for the thermostat board and 1.7” x 1” for the encoder
board. I then printed out the patterns (available on the
NV website) using the program Irfanview.exe (a free
graphics program available from www.irfanview.com).
This program allows you to specify the exact size of the
finished print which — unfortunately — was NOT exact
when it printed. I had to set the dimensions to 3.705” x
WHY USE THE 16F870 PIC?
1) It is inexpensive (less than $5) and readily available
from many popular vendors; i.e., www.mouser.com,
www.microchip.com, and www.melabs.com, and is easily
ordered via the Internet.
2) It features two full eight-line input/output ports and one
five line input/output port.
3) It features optional analog-to-digital conversion on
the five-line port, enabling inputs from any analog sensor
configuration with 10 bit, 50 microsecond resolution.
4) It features a reduced set of only 35 instructions for
programming and is easily accommodated by most of the
currently available PIC compilers and programmers. The
free program, MPLAB IDE (available from www.micro
chip.com), may be used to construct a programmable hex
file for the PIC from assembly language programs you can
write yourself. Go to www.microchip.com and do a site
search for MPLAB IDE; this takes you to a page with the
software download at the bottom of the page.
5) Information for the PIC is readily available from many
sources on the Internet; i.e., www.melabs.com, www. sq-1.com, www.mouser.com, and www.microchip.com.
6) It has many other features which are outlined in the first
pages of its data sheet (16F870,871.pdf), available on the
Nuts & Volts website ( www.nutsvolts.com) and listed
under this article.
7) Last but not least, it is possible to use two 16 pin DIP
sockets in line to accommodate it. The RadioShack
locations carry these sockets but not the 28 pin DIP sockets.
April 2008 47