Project: PIC 4-Digit DS18B20 Temperature Monitor

Discussion in 'The Completed Projects Collection' started by MMcLaren, May 6, 2012.

  1. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    Here is a Digital Temperature Monitor project that uses a Maxim/Dallas 1-Wire® DS18S20 or DS18B20 temperature sensor attached to a simple 4-digit display board. The display board contains a PIC16F1828 micro controller and a miniature 4-digit red, green, yellow, white, or blue display available from Sparkfun.

    The DS18S20 and DS18B20 sensors can measure temperatures in the range of -55° to 125° Celsius with accuracy to ±0.5°C over the range of -10°C to +85°C. Unlike analog temperature sensors that output a voltage proportional to temperature which must be translated using ADC (analog to digital conversion), the DS18S20 and DS18B20 produce a digital temperature value that can be read directly from the sensors via a bidirectional 1-Wire® bus.

    The board powers up using the Celsius temperature scale but you can toggle between Celsius and Fahrenheit scales by pressing the Right Arrow key.

    [​IMG]

    Hardware

    The circuit was built on a Radio Shack prototype board (sku 276-149) with a plastic laminated paper silk-screen glued onto the component side of the board. I used 30 guage Kynar wire and point-to-point wiring on the copper side of the board.

    The circuit does not include column/digit driver transistors and relies on the combined ~250 ohm RDS(ON) resistance of the PIC I/O pin high side and low side FET drivers for segment current limiting. The display is refreshed one segment at a time (1/32nd duty cycle) to provide even brightness across the entire display.

    [​IMG]

    Parts List
    Code ( (Unknown Language)):
    1.  
    2. 1 ea. PIC16F1828-I/P (DIP package)
    3. 1 ea. 0.1-uf (100nf) ceramic capacitor
    4. 1 ea. 10 kOhm, 1/8th watt carbon film resistor
    5. 4 ea. 1N914 or 1N4148 silicon switching diode
    6. 1 ea. Sparkfun COM-09483 Red Common Anode 4-Digit Display
    7. 4 ea. generic momentary contact switch
    8. 1 ea. Soberton GT111P Piezo Speaker
    9. 1 ea. Maxim/Dallas DS18B20 (TO-92 package), or, DS18B20 Probe Kit (eBay)
    10. Misc. sockets, connectors, prototype circuit board
    11.  
    While I used a DS18B20 device in a TO-92 transistor style package, you might consider purchasing a water-proof stainless steel DS18B20 Probe kit from one of several vendors on eBay for around $4 (including shipping). An older DS1820 or DS18S20 sensor can also be used.

    [​IMG]

    Software

    The HEX file in the ZIP file attachment can be used directly with a PICKIT2, PICKIT3, or similar device programmer to program the PIC16F1828. The program source file is also included in the ZIP file attachment. The program was written using the free/lite version of BoostC from Sourceboost and it uses 427 of the 4096 words of program memory available in the 16F1828.

    The program configures the 16F1828 to run from the internal oscillator at 8-MHz. The Timer 2 module is used to generate 250-usec (500 cycle) interrupts and the ISR (interrupt service routine) refreshes one new segment of the display each interrupt. All thirty two segments of the display are updated once every 8-msecs for a 125-Hz refresh rate (and 1/32nd duty cycle).

    Temperature data is collected from the temperature sensor about once per second in the main program loop. The program reads the sensors "family ID" byte (the first byte of the sensors eight byte ROM ID) to determine if the sensor is a DS1820 or DS18S20 (family ID 0x10) with 9-bit temperature data, or a DS18B20 (family ID 0x28) with 12-bit temperature data. The program automatically converts 9-bit temperature data (0.5° resolution) to the higher resolution 1/16° 12-bit format (0.0625° resolution) and then displays the temperature as a decimal value rounded to one decimal place.

    I wrote the program to test new low level 1-Wire® read/write drivers of my own design which I plan to use in future projects. Please keep that in mind when you look at the program which is basically an experiment with some assembly language routines that may be difficult to understand.

    Regards, Mike
     
    Last edited: Jun 12, 2012
    RRITESH KAKKAR likes this.
  2. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    Interesting project, how accurate is it, and does it need calibration?
     
  3. chrisw1990

    Active Member

    Oct 22, 2011
    543
    41
    hi, can i ask what you do the schematic (i guess its a form of schematic?) in?
    the image? i assume you use some photoshop like package?
     
  4. Wendy

    Moderator

    Mar 24, 2008
    20,766
    2,536
    You know, with a bit of tweaking, this could make a decent temperature controller. It would need a high and a low setpoint, or a setpoint that is +/- 2° and two controller outputs.
     
  5. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    From the data sheet... "accuracy to ±0.5°C over the range of -10°C to +85°C." I don't know if it needs calibration. Sorry!
     
  6. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    Those options are similar to several different methods I've thought of for Temperature Control. It might make an interesting discussion on the main Projects forum, ie., different methods for implementing a Thermal Controller... I suppose it really depends on the application, thermal mass, hysterises, etc. You probably wouldn't need two outputs if you're just switching a 12 vdc cooling fan on and off. On the other hand, two outputs might be handy to control "open" and "close" relays for motorized louvers on a Greenhouse.

    Anyway, I figure the 'A' and 'B' LEDs can be implemented and then the up and down arrow keys could be used to select one of three displays; (1) both LEDs off when you're viewing the "real time" temperature, (2) LED 'A' lighted when you're viewing the "threshold #1" value, and, (3) LED 'B' lighted when you're viewing the "threshold #2" value. Pressing the <set> switch while viewing "threshold #1" would allow you to modify that setpoint. While in <set> mode, the up and down arrow keys would be used to modify the threshold or setpoint. Then you'd probably want to save each setpoint automatically to EEPROM after modifying it so that it could be used as the default value on power-up. Instead of "threshold #2", maybe you'd want to have a minimum "on time" for an output while the temperature remains above a certain threshold. I suspect there are a staggering number applications, methods, and options...
     
    Last edited: May 8, 2012
  7. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    Just wanted to mention that the program source and hex files attached to the first post have been updated.

    The updated program squashes one software 'bug' and adds support for the older 9-bit DS1820 or DS18S20 digital temperature sensors in addition to the 12-bit DS18B20 sensor.

    Cheerful regards, Mike
     
    Last edited: May 16, 2012
  8. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    Just wondering if anyone would like to see an Indoor/Outdoor Thermometer project? I just finished testing a low level 1-Wire "SearchROM" driver which allows using multiple DS18x20 sensors on the same 1-Wire buss.

    Cheerful regards, Mike
     
  9. bratib

    New Member

    Oct 17, 2011
    1
    0
    I certainly would! I gave up on the 1 wire buss as I could not get reliable sensing of all the sensors on the buss. I was using an Atmel mega328 and had to use a separate input for each sensor. Most of what I found out there did the same thing or used an interface that basically created separate inputs for each sensor. I felt it kind of defeated the idea of addressable sensors. The documentation makes it sound simple but in the real world I found it wasn't. If you have managed to make them work I would love to see how you did it. I eventually went with NTC themistors for the project as they were much cheaper, but would still love to revisit it with DS18s.
     
  10. MMcLaren

    Thread Starter Well-Known Member

    Feb 14, 2010
    759
    116
    Hi bratib,

    My drivers are written in PIC assembly language so I'm not sure they would be of much help for an Atmel enthusiast.

    I have working code for the PIC 4-digit demo board but I need to add indicator LEDs so you know which sensor you're looking at. Give me a while to get that working and I'll post the whole thing as a new project.

    Meanwhile, not sure this will help you, but, here's a (BoostC) program (below) for a Serial 12F1822/DS18x20 demo. My 1-Wire driver library uses 99 words of program memory after adding the SearchROM routine. Simply hook up the TX(RA0) and RX(RA1) pins from the 12F1822 to your PC via a serial adapter or a usb-to-serial adapter. Connect the "data" pin on one or more DS18S20 or DS18B20 temperature sensors to the RA2 pin. Bring up your favorite terminal program on the PC and press a key to display the temperature of each DS18x20 found on the 1-wire bus. The graphic below shows repeated readings from a DS18S20 (romid = 0x10) and a DS18B20 (romid = 0x28) connected to the bus.

    Cheerful regards, Mike

    [​IMG]
     
    Last edited: Oct 3, 2012
    Rocker_BR likes this.
Loading...