Mirley - Electronics & Programming
projects, programs... all about electronics
M
RSS FB TW G+
Universal Minithermometer
October 11, 2011 Measuring Circuits
Main thumb This is 2-channel thermometer, which can measure temperature between -50.0 and +99.9 Celsius degree. Circuit is prepare to measure temperature inside and outside, but It can be also used in other applications. After the change of the source code it can be used as simple thermostat or more complex temperature controller. Device was build on the basis of popular digital temperature sensor DS18B20 and microcontroller ATTiny2313. Thanks to that this universal mini thermometer is much simpler to do and much smaller. All its parts were placed under LED display.

Project is better version of this device (polish version only). Almost each element was replaced by SMD components. In this way the circuit is much smaller. It is possible to use it as small thermometer module or simple thermostat. Slight dimensions allow to use smaller cover (a bit bigger than display). In basic version mini thermometer is able to measure temperatures in two channels. Mini thermometer has two sensors on independent 1-Wire connections. To change between two temperatures, two buttons can be used.

This project was published in Elektronika dla Wszystkich 08/2011 (polish magazine for electronics hobbyists) and is available as AVT2985

How It Works?:

In the picture 1 the schematic of mini thermometer is presented. Main part of this project is microcontroller U1 (ATTINY2313). It works with internal oscillator, without internal frequency divider. In result the clock frequency was set to 8MHz. There are no quartz resonator so PCB is smaller and XTAL pin can be used as input port PA0. This input is connected directly to switch S2. Microcontroller has to: read results of temperature measurement from two sensors, calculate values suitable for LED display, read state of buttons S1 and S2. Capacitor C1 (100nF) is placed close to the microcontroller and is responsible for supply voltage filtration. The same task have capacitors C2 (10uF) and C3 (10uF), which are necessary to properly work of voltage regulator U3 (78L05).
Figure 1: Thermometer Schematic
This project is very simple, because DS18B20 is used as temperature sensor. This sensor is a 12-bits digital thermometer and it can work in area of -55 to 125 Celsius degree. Time needed for temperature conversion is less than 750ms. Temperature readout is completely digital, and for the connection with microcontroller the 1-Wire bus is used.
For the presentation of temperature is used three-digit LED display with internally-connected segments, adapted for multiplexing. Thanks to that the PCB design is much simpler. In this case, using separated LED displays makes impossible to make a one-sided printed circuit board. Resistors R4-R11 (330) limits the current of the LED display to a maximum value around 10-12mA (per one segment). The average current will, however, smaller due to multiplexing. To control the anodes of the LED display, the three popular transistors T1-T3 (BC857) are used. Their currents are limited by the resistors R1-R3 (3k3). Turning on the consecutive digits on the display is done by cyclical setting of a low state on the base of one of the transistors T1-T3. At the same time port B of the microcontroller should be set the value of the encoded digit. An important component is GP1 connector, which is also the place where sensors and control output (in the case of the thermostat) can be connected. Goldpin connector are not necessary, as can be seen in the photos - wires can by soldered directly to the PCB. In the case of thermometer, control output will go to low state when the temperature is negative. Just attach the LED diode with 470R serial resistor between the control output and + 5V to have the signaling of sign "-".

Construction:

View of printed circuit board from the bottom side may be seen here. Figure in a mirror image is available here. The board is designed as a one-sided, and almost all items are SMD. An exception is the LED display, buttons and connectors. Mounting is not complicated but requires little skill in soldering of SMD components. Figure here will be very useful for soldering the printed circuit board (from bottom side). For mounting the top side of PCB very useful will be schematic available here.

At the beginning, it is good to solder all SMD elements, because there are no protruding parts on the other side and mounting is simpler. It should be noted that the GND passes in one place through the button (the button has 2 pairs of shorted outputs). If becomes necessary to abandon the buttons instead of the switch S1, jumper must be soldered. The disadvantage of the small PCBs is lack of the programming connector, so if change the program will be necessary, you will need to solder a wires to microcontroller's pins. The power connector, as in the case of GP1, can be replaced by wires soldered directly to the board. Pinout of the GP1 is shown in Figure 2
Figure 2: Description of Connector
Pins 1 and 2 of this connector is as follows: the power supply and the ground. Control output (OUT) is available at pin 3. Each of the sensors must be connected by three wires: power, ground and data. The data pin of first sensor should be connected to pin 5, and the second sensor to pin 6 of GP1 connector. The thermometer can be powered with voltages of range 7-12V by the voltage regulator 78L05. Nothing stands in the way to skip the voltage regulator, and connect 5V supply voltage directly to the circuit.

Programming:

The program controlling the operation of the thermometer was written in the well known program BASCOM AVR. It occupies around 70% of the available memory of the microcontroller and can be successfully compiled in the demo version of BASCOM AVR. The program is not complicated, in brief looks like this: all the time processor runs in an infinite loop, waiting for the setting of one of the timing flags (Timer0 interrupt). Every 4ms the procedure of LED display multiplexing is called, which in due time a jump to the temperature reading (to avoid display blinking).
Timer0 interrupt routine is shown below:
Przerwanie0:
Timer0 = 131
   Set F4ms
   Incr Dziel(1)
   If Dziel(1) = 25 Then
     Dziel(1) = 0
     Set F100ms
     Incr Dziel(2)
     If Dziel(2) = 10 Then
       Dziel(2) = 0
       Set F1s
     End If
   End If
Return
At the beginning the Timer0 is loaded to value of 131, giving a interrupt after counting of 125 pulses (256-131). Timer works with hardware divider 256, so clock frequency equal 8MHz gives interrupt every 4ms. Immediately after the interrupt the F4ms flag is set. Variables Dziel(1) and Dziel(2) work as frequency dividers. First of them is responsible for the frequency division by 25 and setting the F100ms flag. The second variable gives extra frequency divider by 10 and sets F1s flag, every 1s.

The main loop is shown below:
Do

If F4ms = 1 Then
  Reset F4ms                                               'co 4ms
  Wysw = T
  Gosub Wyswietl_zmierz
End If

If F100ms = 1 Then
  Reset F100ms                                             'co 100ms
  If Pind.2 = 0 Then Kanal = 1
  If Pina.0 = 0 Then Kanal = 0
End If

Loop
End
The thermometer operation is very simple and depend only on the flags: F4ms and F100ms. Most of the time the processor spins in an infinite loop, waiting for the setting of one of the flags. Every 4 ms the display procedure and temperature reading procedure are executed, while every 100 ms the buttons states are refreshed. In the basic version of the program a simple keyboard reading was implemented (direct reading of the state of the input pins). Pressing S1 switches thermometer to read the second sensor, and by pressing S2, the circuit passes to reading of the first sensor.

The display procedure and temperature measurement is shown below:
Wyswietl_zmierz:
  Incr Mux
  If Mux = 5 Then Mux = 0

  Portd.3 = Not Minus

  For I = 1 To 3
    Wysw_pomoc = Wysw Mod 10
    Ww = Wysw_pomoc
    W(i) = Lookup(ww , Tabela)
    Wysw = Wysw / 10
  Next I
  If W(3) = 40 Then W(3) = 255          'wygaszenie zera wiodącego

  Select Case Mux
    Case 0:
      Portb = W(3)
      Reset Portd.6
    Case 1:
     Set Portd.6
     Portb = W(2) And &B11011111
     Reset Portd.5
    Case 2:
     Set Portd.5
     Portb = W(1)
     Reset Portd.4
    Case 3:
     Set Portd.4
     Portb = 255
     Gosub Temp
   'Case 4:  
  End Select
Return

Tabela:
    Data 40 , 235 , 50 , 162 , 225 , 164 , 36 , 234 , 32 , 160
Procedure works in 5 steps depending on the state of the Mux variable. It accepts values ​​from 0 to 4, and varies cyclically with the next procedure call. The control output (Portd.3) is set to negated value of the variable minus. It is responsible for displaying negative temperatures and low state on thus port occurs when the measured temperature is negative. Subsequently, through a for loop, the variable Wysw, containing the value to display, is divided into three single digits. They are then converted to LED display codes using the Lookup command (using a conversion table). This procedure gives array W(n) with the coded values​​, where n = 1 ... 3 indexes characters to display.

The rest of the procedure depends on the variable Mux. For values 0-2, one of 3 digits are displayed. In this moment the anode, corresponding to previous digit, is switched off, PortB is set to coded value of next digit, and anode corresponding to next digit is switched on. An exception is the digit of W(2) where additional operation (And &B11011111) provides adding a decimal point after the second character. For the Mux = 3 the temperature measurement procedure is called, and the state Mux = 4 is the phase of waiting for the temperature measurement.

Temperature measurement procedure is shown below:
Temp:
 If F1s = 1 Then
   Reset F1s
   1wreset Pind , Kanal
   1wwrite &HCC , 1 , Pind , Kanal
   1wwrite &HBE , 1 , Pind , Kanal
   T = 1wread(2 , Pind , Kanal):
   Minus = T.15
   T = Abs(t)
   T = T * 10
   T = T / 16
   1wreset Pind , Kanal
   1wwrite &HCC , 1 , Pind , Kanal
   1wwrite &H44 , 1 , Pind , Kanal
  End If
Return
This procedure is called every 20ms, but the temperature measurements takes place every 1s, after detection high state of the F1s flag. It is simple version of 1-Wire bus, configured to communicating with one device. All 1-Wire commands are called with the parameter Kanal, which is responsible for select the proper bus to read temperature (or pind.1 pind.0). After a reset, the skip ROM command and read DS18B20 registers command are sent. Then the two bytes are read and stored in variable T (integer). The temperature sign is read and performs a simple calculations. As a result, the variable T takes the form of temperature in degrees multiplied by 10 (eg. 13 means 1.3 degree). At the end of the procedure the temperature conversion command is sent, which provides always actual temperature value in DS18B20 registers.

The circuit can be converted into a thermostat little effort. We resign then from the two-channel temperature measurement and negative temperatures. To control output (Portd.3) optotriac and triac (for AC receivers) can be connected. DC receiver can by controlled by MOSFET transistor, connected to the control output. In the main loop you will need to make the changes shown below:
If F4ms = 1 Then
  Reset F4ms
  If Ust = 0 Then Wysw = T Else Wysw = Tu
  Gosub Wyswietl_zmierz
End If

If F100ms = 1 Then
  Reset F100ms
  If Pind.2 = 0 Then
    Incr Tu
    Autoret = 20
  End If
  If Pina.0 = 0 Then
    Decr Tu
    Autoret = 20
  End If

  If Autoret > 0 Then
    Ust = 1
    Decr Autoret
  Else
    Ust = 0
  End If

  H = Tu + 10
  L =  Tu - 10

  If T > H Then Set Portd.3
  If T < L Then Reset Portd.3
End If
This code needs to declare variables Tu, H and L as Integer, Ust as Bit and Autoret as Byte. In addition, the variable Tu need the initial value, because it is temperature parameter for thermostat. In temperature measurement and display procedure, the line responsible for signaling negative temperatures should be deleted. Portd.3 is used now as control output. This solution is not perfect, there is no limit to the setting values and cannot save the settings to the EEPROM but in many situations works very well. Fusebits of the microcontroller should be set to work with an internal RC oscillator with a frequency of 8MHz, which in practice is equal to disable only the hardware divider (Bit CKDIV). Fusebits settings are presented below:

Photos:

Parts List:

Thermometer Parts:

Attachments:

PCB Design:
AB AB AB Board (bottom side,thermotransfer method) 10.7 kB
AB AB AB Board (bottom side, mirrored) 10.7 kB
AB AB AB Board (bottom side, few per page, thermotransfer method) 157.0 kB
AB AB AB Mounting (top side) 8.7 kB
AB AB AB Mounting (bottom side) 13.7 kB
AB AB AB Description Layer (top overlay) 53.3 kB
AB AB AB Description Layer (bottom overlay) 100.5 kB
Documentation:
AB AB AB Thermometer Schematic 117.4 kB
Programing:
AB AB AB Thermometer Source Code (BASCOM-AVR) 3.1 kB
AB AB AB Thermostat Source Code (BASCOM-AVR) 3.4 kB
AB AB AB Thermometer Output file (BIN BASCOM-AVR) 1.4 kB
AB AB AB Thermostat Output file (BIN BASCOM-AVR) 1.6 kB
AB AB AB Thermostat Output file (HEX) 4.6 kB
AB AB AB Thermometer Output file (HEX) 4.1 kB
AB AB AB Fusebits Configuration (burn-o-mat) 12.5 kB

Questions and Comments:

comments powered by Disqus


November 15, 2017
Universal step-down controler was presented...
More …
March 23, 2017
Nixie clock with thermometer was finished
More …
More news …

mirley.net
Recommended Sites