;-- ------------------------------------------------------
;-- Project: Dual or single thermometer with infrared support
;-- with PIC16F628/PIC10F322 and DS18S20/DS18B20
;-- Electric diagram & Software: Bogdan Borca/http://www.bogdi.ro, TIMISOARA, RO
;-- Release date: 29 January 2013
;-- ------------------------------------------------------

#define FEEDBACK http://www.bogdi.ro/guestbook Thank You! :-)
CBLOCK 0x00
;-- Sections

1. Overview
1.1 Features
1.2 About the project

2. Operating modes
2.1 Single local sensor operating mode
2.2 Dual temperature display operating mode
2.3 Single external temperature operating mode

3. Settings
4. Displaying temperatures
5. External circuit
6. Technical data

ENDC

CBLOCK I. The Project (download)
;-- Sections

II. Schematic layouts
III. Supported PIC micro controllers
IV. Supported temperature sensors
V. Display configuration
VI. EE memory, default values, HEX file, checksum
VII. Recompiling

ENDC

1. Overview

This is a dual or single thermometer with infrared support.
The thermometer reads one local sensor (DS18S20 or DS18B20) and listens for infrared temperature signal. The infrared signal is generated by another external circuit which can be placed meters away.
The device can be used to display:
1.1 Features
Two temperatures displayed on a 7x4 segment display, from which: 7x4 common cathode and common anode segment display support
Single or dual mode display for either local, external or both sensors
Configurable display time for both sensors
Configurable Celsius or Fahrenheit temperatures display
Temperature range from -55 up to +120 Celsius degrees using DS18S20 or DS18B20 sensor
Thermostat for the local sensor controlling temperatures between 0 and 99
Led indicating thermostat state
Thermostat active type for the local sensor
Great menu with SET/UP/DOWN buttons
Low power consumption by the external circuit making a long battery life
70 seconds temperature conversion by the external circuit
Up to 8 meters straight infrared range

1.2 About the project
Implemented few years ago the functions to send and receive infrared data. Always wanted to use this with a sensor outside my window to know the outside temperature. While having only this function on my PIC micro I added also the local sensor to have them both in a singular 7x4 segment display. With little configuration I end up with single or dual thermometer I hope you'll enjoy! back to menu

2. Operating modes

2.1 Single local sensor operating mode
At power up, the device tries to establish a communication with the local sensor. If the local sensor exists, then it will display read temperature (TEMP1) for a number of seconds (TS1) set by the user. While working, the device always listens for infrared signal on a dedicated pin. If no valid infrared signal is detected, then only the local sensor is displayed. The user can connect the pin 6 (RB0) to +5V and drop the TSOP1738 usage, in the case external IR temperature is not needed. Local temperature conversion occurs when seconds (TS1) rolls over to 0. This means that user will read a new temperature conversion at every TS1 interval.

2.2 Dual temperature display operating mode
If a valid infrared signal is present, a flag inside the chip is set. When the seconds (TS1) to display local temperature (TEMP1) elapsed, the temperature received through infrared signal will be displayed (TEMP2), also for a number of seconds set by the user (TS2). When the seconds to display external temperature (TEMP2) elapsed, then local temperature (TEMP1) will be displayed. The last digit 4 will blink between C or F and 1 or 2, meaning Celsius/Fahrenheit and first(local)(1)/second(infrared)(2) sensors being displayed. Read more about digit 4 in section 4. "Displaying temperatures".

2.3 Single external temperature operating mode
The device can function without the local sensor. In this case user must connect the pin 1 (RA2) to ground through a 4.7K resistor. In this case, local sensor is not detected and the device will start a countdown from 70 down to 0 to ensure the user that infrared signal is awaited. The countdown will start again until valid infrared signal is detected. If an infrared signal occur then the received temperature will be displayed and the countdown reset. While displaying temperature, if for 210 seconds no infrared signal is detected, then the device will again enter in 70 seconds countdown mode. TS2 has no meaning in this mode.back to menu

3. Settings

The device has few configurable options which user can set using three buttons: SET, UP, DOWN. Menu can be activated using SET button while the device is in one of its operating modes. Menu mode will display the following settings that can be changed using UP and DOWN buttons:

tL ->* thermostat low value, from 0 to tH
tH ->* thermostat high value, from tL to 99
tt ->* thermostat active state: can be active low (L) or active high (H)

;-- -----------------------------------------------
;-- When the measured temperature meets
;-- or exceeds the value stored in tH, thermostat becomes
;-- active and remains active until the measured temperature
;-- falls below the value stored in tL.
;-- This allows the user to program any amount of hysteresis
;-- into the output response. The active state of thermostat can be set by tt.
;-- If thermostat type tt is 1, then active is high (1) else active is low (0).
;-- -----------------------------------------------

t1 ->* time in seconds to show local temperature, from 3 to 50
t2 ->* time in seconds to show temperature received through infrared signal, from 3 to 50
CF -> set show the temperatures in Celsius or in Fahrenheit, C or F

Settings marked with * have no effect in "Single external temperature operating mode"
Menu mode exit at the end on the settings. All user settings are stored in the device EEPROM to prevent configuration every time the power is off.back to menu

4. Displaying temperatures

While the device use 7x4 segment display, certain different display configurations must be considered.
Last digit (DIGIT 4)
The last digit is always used to show whether Celsius or Fahrenheit is used. If dual operating mode, the digit blinks between scale (C or F) and the sensor being displayed (1 or 2). The digit also blinks when only the external temperature mode is used to ensure the user no local sensor exists. The digit stops from blinking between scale and sensor if a bad signal was received, or, if 210 seconds elapsed from the last valid infrared signal. The other three digits are used to show the temperature.
Displaying temperature on the three digits
TemperatureDIGIT 1DIGIT 2DIGIT 3Observations
20°20°
107°107° is dropped in this case
5°DIGIT 1 is shut down
-7°-7°
-15°-15° is dropped in this case
back to menu

5. External circuit

External circuit can be placed meters away from the listener. This mode is then master and slave. The master is the listener/receiver and the slave is the external circuit that sends infrared signal with temperature data, transmitter. For the simplicity of the project, communication between the master and slave is only in one way: from the slave to master. Slave will convert and transmit temperature at every 70 seconds. The transmission starts with a code so master will not be tricked by party/false infrared signals. Between transits, slave sleeps. To receive infrared signal, master should always have slave in view. Wrong temperature data may be received by the master if infrared signal is blocked or obstructed. back to menu

6. Technical data

Master
Is based on PIC16F628 micro controller.
Support for DS18S20 or DS18B20 as local sensor, read temperatures between -55 and +120°C.
Listens 38KHz infrared signal using TSOP1738.
Use 5V or 7.5-18V through CV7805L regulator.
Slave
Very simple design: based on PIC10F322 micro controller, 2N3904 transistor, DS18S20 or DS18B20 sensor and an infrared led!
Slave will send 38KHz signal composed by: CODE+TEMPERATURE at every 70 seconds.
Battery used: lithium, 3V, 1/2AA, 950mAh
Circuit consumption ~ 0,02mA in sleep mode/100mA (if 100mA led is used) in TX mode active 20ms. TX mode active once in 70 seconds => 51 TX/hour => a minimum of 2 years battery life. I used http://oregonembedded.com/batterycalc.htm to determine battery life.
Both Master and Slave use internal oscillator.
Tested leds:
TSHA4401: 100mA 1.5V 20deg
This emitter series is dedicated to systems with panes in transmission space between emitter and detector, because of the low absorbtion of 875 nm radiation in glass. I did small tests and I can say it works through 3 planes (two glases and one transparent plastic) at 5 meters away. It may work even further but I didn't tested it. Free from obstruction the led drives the receiver from like 8 meters (800 cm). At 850 cm the receiver still caught valid signals.
Not tested leds:
CQY36: 50mA 1.2V 40deg.
I bougth this led to make some future tests. Altougth it has 40 ° and only 50mA I expect it to be less in straigth line range. So this is up to user's whishes and battery life expectations.
Note: I'll update led info as soon as I'll make a full test. back to menu

I. The Project
Download the project below:
Dual or single thermometer with infrared support with
PIC16F628/10F322 and DS18B20/DS18S20

The zip file contains:
II. Quick schematic overview
Receiver
Common cathode display
Common anode display
Transmitter

III. Supported PIC micro controllers
Both transmitter and receiver can be compiled with any PIC with support for the pins and with internal oscillator.
In define.inc file from the Inc folder you can find the PROCESSOR defined as PIC16F628.
You can set your own device. Make sure to select same micro controller in the project settings. Specific processor settings are its CONFIG attributes and FRA value. FRA is used for different bank address selection between micro controllers. For example PIC16F84 has File Registers starting from H'10' address and PIC16F628 has it starting from H'20'. back to menu

IV. Supported temperature sensors
DS18S20 or DS18B20
The project already has HEX files for both sensors.back to menu

V. Display configuration
Common cathode display or Common anode display
The project already has HEX files for both display types.back to menu

VI. EE memory, default values, HEX file, recompiling
VI.I EE memory
Important note for the transmitter: EE must be loaded with the EEPROM_dual_temp_on7x4.MCH before compiling/exporting HEX file for the project.
This file has the configuration to display characters (0-9 and letters/signs C/F/H/°/-/t/L/H) needed by the project, also holds default values for the settings (tL/tH/tt/t1/t2/CF).

VI.II Changing EE default values
To change these values, start counting FFs back from the end of the file:

[...] 19 -> default thermostat low value in hexadecimal 19=25 (decimal) [0..tH hex]
1E -> default thermostat high value in hexadecimal 1E=30 (decimal) [tL..99 dec]
01 -> default thermostat type, active high [1,2], 2 means active low
05 -> default time in seconds to display local sensor's value [3..50]
05 -> default time in seconds to display infrared temperature [3..50]
01 -> default Celsius scale to display temperature [1,2], 2 means Fahrenheit is used
FF
FF
FF
[...]
FF
FF
FF -> end of the file (last entry)

VI.III Changing default values in HEX file
Default values can be changed directly in the original HEX file without recompiling the project.
Line that start with :10424000 (in the hex file) contains default EE values:
:1042400019001E000100050005000100FF00FF002D
Identifying the values, I made the selection for a better association:
:10424000 [19] 00 [1E] 00 [01] 00 [05] 00 [05] 00 [01] 00 [FF] 00 [FF] 002D
Changing default values should be done with care because they must meet range criteria! Please consider that values are in hexadecimal format!
After changing is complete a checksum recalculation is needed.

VI.IV Checksum recalculation
Assuming the following line:
:1042400019001E000100050005000100FF00FF002D
Checksum is 2D, the last two digits. It's value is calculated as follows:
1. Add all 2 digit groups: 10+42+40+00+19+00+1E+00+01+00+05+00+05+00+01+00+FF+00+FF+00=2D3
2. From the 2D3 result, drop 2 and XOR D3 with FF: D3 XOR FF = 2C
3. Add 1 to the result from 2. => Checksum = 2C + 1 = 2Dback to menu

VII. Recompiling
To have a valid hex file, after compilation/building project, use Export option from File menu (MPLAB), I don't know other IDE, used one on Linux but don't remember much from it. In export window make sure hex code and hex memory are selected. This will generate the hex file with both code and memory. Without EE into the hex the device will not function.
VII.I Changing sensor type
There are defined DS18S20 and DS18B20 in project's Inc\ folder, define.inc file

; #define DS18S20 "Present" ;-- Compile project using DS18S20
#define DS18B20 "Present" ;-- Compile project using DS18B20
;-- If you want to compile the project using ds18S20 then
;-- comment #define DS18B20.. and uncomment #define DS18S20

Comment/Uncomment the sensor you want (not to use)/use and recompile, export new hex, use it.back to menu