logo elektroda
logo elektroda
X
logo elektroda

Thermometer with DS18B20 sensor and two-digit LED display

Sam Sung 1773 19
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • Thermometer with DS18B20 sensor and two-digit LED display
    I made myself a two-digit thermometer with a red ELD-515SURWA seven-segment display (soldered out of a Euroster 1100E thermostat) and a DS18B20 sensor.
    The electronics fit on a 2x8 cm cutout of a 6x17 mesh universal board.




    The housing is a white 2xRJ11 6P4C surface-mounted telephone socket.
    White plastic casing marked for drilling with holes and electric drill nearby White surface-mount box with hand-drilled holes for a seven-segment display White plastic case with a rectangular cutout, file and screwdriver nearby White enclosure with rectangular cutout for seven-segment display Thermometer with red LED display showing 21°C Thermometer with red LED display showing 21°C DIY thermometer with LED display showing 28°C in a white plastic casing. Thermometer with red LED display showing a temperature of 14 degrees Two-digit red LED display showing value 29 on a white casing White enclosure with dark translucent panel for an LED display. Homemade thermometer with red LED display showing 28°C
    Power supply from a 5 V / 120 mA switching power supply.

    Schedule <br/span>
    Thermometer schematic with AT89C2051 microcontroller and ELD-5155URWA display

    Firmware
    The brain of the chip is the AT89C2051. The program in assembler takes 410 bytes. I attach the source and hex.
    The thermometer can show a temperature from -9 to +99 °C.
    I use the smallest resolution of the measurement i.e. 9 bits and show only the integer part of the result.
    By using three wires (i.e. supplying power via a separate wire rather than parasitically), you can ask the sensor if it has finished measuring. When this happens, the program reads scratchpad , checks the CRC and updates the value on the display.
    Multiplexing takes place in a timer interrupt at 1302 Hz. During the time-critical operations of receiving and sending a bit on the 1-wire bus, the interrupts are blocked (up to half a millisecond during 1-wire resets); I did not notice with the naked eye the effect of such multiplexing hang-up on the brightness of the display.


    -- No sensor
    E1 The sensor reported completion of temperature measurement immediately after measurement order
    E2 The sensor failed to report completion of temperature measurement in a timely manner
    E3 CRC error data received from scratchpad a sensor
    __ Temperature ≤ -10 °C
    90c64cdcfda ^^ Temperature ≥ +100 °C






    The sensor here measures the temperature of the hot water at the outlet of the cooker. I cleaned a piece of tubing with sandpaper and on a drop of thermally conductive paste applied the sensor with the inscription side to the tubing, stuck it on with silver repair tape and then wrapped it with a couple of layers of sponge.
    It seems that despite these treatments the thermometer nevertheless underestimates the water temperature by about 2-3 degrees....

    Cool? Ranking DIY
    About Author
    Sam Sung
    Level 33  
    Offline 
    Sam Sung wrote 1982 posts with rating 552, helped 226 times. Been with us since 2005 year.
  • ADVERTISEMENT
  • #2 21825541
    Andrzej_Tomaszewski
    Level 13  
    AT89C2051- I started my uC adventure with it 20 years ago. Did you write the procedure for handling 1Wire and communicating with DS18B20 yourself? How do you limit the current of the diodes in the display as I didn't notice any limiting resistors? Greetings
  • ADVERTISEMENT
  • #3 21825697
    Sam Sung
    Level 33  
    Andrzej_Tomaszewski wrote:
    The procedure for handling 1Wire and communicating with the DS18B20 you wrote yourself?
    Yes, these are my battle-tested procedures, here used in the trivial case of a single sensor on a ~20cm wire. I converted their delays to a 12 MHz clock. So far the smallest pull-up I've had was 1.5k, here it happily runs at 1k, so the ladder from the display takes care of the 1-wire too.
    Andrzej_Tomaszewski wrote:
    How do you limit the diode current in the display because I didn't notice any limiting resistors?
    The 1 kΩ resistor ladder limits the diode current in the display. This is a display with a common cathode. The current flows from plus through the 1k resistor to the anode of the segment, from the cathode it flows into either port P3.4 or P3.5 and through the CPU to ground. If I want to extinguish a segment connected to P1.X, I put a zero there and then the current flows immediately through the processor to GND instead of to the LED. That is, the current consumption is slightly higher when the segments are not lit than when they are lit. I took this clever way of simplifying the circuit from the kit https://www.elektroda.pl/rtvforum/topic3494198.html
  • #4 21825839
    Andrzej_Tomaszewski
    Level 13  
    Well yes, if the WK display is ok but the control method is a bit unusual, not very energy efficient. Regards

    Added after 2 [minutes]:

    Sam Sung wrote:
    That is, the current consumption is slightly higher when the segments are not lit than when they are lit. I took this clever way of simplifying the circuit from the putty https://www.elektroda.pl/rtvforum/topic3494198.html


    And haven't you thought about a resistor ladder with individual leads or just individual resistors?
  • ADVERTISEMENT
  • #5 21825861
    Sam Sung
    Level 33  
    Andrzej_Tomaszewski wrote:
    And you didn't think about a ladder with resistors with individual leads
    I didn't know there were such.
    Andrzej_Tomaszewski wrote:
    or just about individual resistors?
    This kind of circuit would not fit on such a small board.
  • #6 21826321
    Andrzej_Tomaszewski
    Level 13  
    Sam Sung wrote:
    A circuit like that would not fit on such a small board.

    Just out of curiosity - what was dictated by this board size? It seems that the enclosure allowed the use of a slightly larger board.
  • #7 21826625
    saly
    Level 32  
    Years ago I used assembler, then fell in love with C++, I remember from assembler that it was like ploughing acres of field with a hand plough.

    Respect and admiration, especially for your original solution and perseverance.

    If it wasn't for that trick with the display control, you wouldn't be without a few transistors or some ULN28.... for classic control.
    The AT89C2051 itself has probably not a lot of capacity, surely it can't light up 8 segments and power it from the proc ports.
  • #8 21826708
    Andrzej_Tomaszewski
    Level 13  
    The following shows that the output in the low state can accept 20mA while in the high state the current flowing out is negligible. I wonder what was dictated by the choice of this and not another uC.


    Table of microcontroller DC characteristics showing voltage and current conditions
  • #9 21826814
    ex-or
    Level 28  
    Sam Sung wrote:
    a clever way to simplify the circuit

    Way from PCF8574 note
  • #10 21827191
    Sam Sung
    Level 33  
    Andrzej_Tomaszewski wrote:
    Wondering what was dictated by the choice of this and not another uC.
    The choice of board and prock was mainly dictated by the fact that I had one, but I also wanted to see if I could do such a small chip with such an old proc. The port load is high, the ports have a strong zero, so newer procs have no advantage here. Well, unless the 1-wire could work stably without a quartz - then the AT89C2051 would lose out with the lack of an internal RC oscillator.
    ex-or wrote:
    Sam Sung wrote:
    a clever way to simplify the circuit

    Way from the PCF8574 note
    And from which one? I don't see such a diagram in SCPS068J.
  • #11 21827955
    acctr
    Level 39  
    Sam Sung wrote:
    The choice of board and prock was mainly dictated by the fact that I had one, but I also wanted to see if it would be possible to make such a small chip with such an old proc.

    The microprocessor used is very cool, for many one of the first in an electronic career, due to BASCOM. The relatively small amount of ROM is enough for small projects and to practice assembler, because the program does not grow too much.
    the 1-WIRE pulls it off without a hitch, even in BASCOM it was possible to do sensible things.

    In the course of developing the program, how many times did you insert the 2051 into the socket? I suspect that the lack of ISP becomes a nuisance here, especially when debugging. I've used it a few times in projects and I remember the legs stripping down to bare copper from constant programming (I was using a precision cradle).
    Helpful post? Buy me a coffee.
  • #12 21828203
    efi222
    Level 21  
    acctr wrote:
    1-WIRE pulls it off without a hitch, even in BASCOM it was possible to do sensible things.

    Bascom was not as bad as it was painted. Here an example of a thermometer on an ATTiny2313 with a DS18B20.
    http://mirley.net/minitermometr_uniwersalny.html
    This project is also on the electrode as far as I remember.
    Sam Sung wrote:
    I didn't notice with the naked eye the effect of such multiplexing attachment on the brightness of the display.

    The author @mirley has written up the sensor comms in an interesting way. Worth a look. I'll just add that on a similar code I made a temperature controller on an Atmega8 for an etching machine. As a curiosity I will add that I tried to do it in Arduino IDE. (MiniCore/Atmega8 board). Unfortunately, the library alone to handle the DS18B20 was taking up more than 80% of the flash of this probe. In Bascom I did it with a lot of slack :)
  • #13 21828283
    Andrzej_Tomaszewski
    Level 13  
    efi222 wrote:
    Bascom wasn't so bad


    And it still isn't :)
  • ADVERTISEMENT
  • #14 21828418
    Sam Sung
    Level 33  
    acctr wrote:
    In the course of creating the program, how many times did you put the 2051 into the cradle?
    Many times. Well it didn't want to work the first time :)
    efi222 wrote:
    Bascom was not as bad as they paint it. Here an example of a thermometer on ATTiny2313 with DS18B20.
    http://mirley.net/minitermometr_uniwersalny.html
    This project is also on the electrode as far as I remember.
    Hmm, I've done error handling though, and I don't keep flying by no matter what happens on the bus :)
    Well, and I put the microcontroller to sleep - the interrupt wakes it up. And it's not possible to do sleep in Bascom?
    I don't really understand why I need to divide the same number modulo 10 again every 4 ms by chunking the same digits and converting them into the same segment patterns when the number changes every second. The sentence "the Mux=4 state is the phase waiting for the temperature measurement to finish quietly" is probably some nonsense (?) To my mind the Mux=4 state only reduces the brightness of the display from 3/4 to 3/5. In my case I did not introduce a dead multiplexing phase because this 1k ladder limits the current sufficiently. With dimming the brightness is OK.
    In 2011 I also made a thermometer that works a bit like that mini thermometer, i.e. for the duration of all communication with the 1-wire the display was left blank. That's how I know that this causes a rather annoying blinking. Meanwhile, nothing bad happened when here I let multiplexing run in an interrupt, which I pause for the duration of a single operation on 1-wire. There is no flickering (unless of a different kind, when the temp is at the limit and changes by 1 degree every measurement), the display has not burned up.
    Still, these multiplexing phases are written out in bascom in a kind of vascular way, like switch-case in C, as if they were some kind of special case, instead of an elegant mask with a 1 or thereabouts zero turning on a single digit, going around in circles.... well no, this code did not win any sympathy for bascom :P

    Such a curiosity: in the DS18B20 note there is a table with temp measurement times at different resolutions:
    DS18B20 temperature conversion timing table for different resolutions
    And a long time ago the sensors worked like this. Instead, the ones I bought recently on AliExpress seem to measure just as fast, no matter how many bits of resolution you set. They don't even try to pretend to be original? Well, but in parasitic power mode you can't tell.
  • #15 21828543
    Andrzej_Tomaszewski
    Level 13  
    Sam Sung wrote:
    Well, I put the microcontroller to sleep - an interrupt wakes it up. And in Bascom it is not possible to do sleep?


    In Bascom, one short command and the uC sleeps, error detection on the 1Wire bus - it's just testing the state of a dedicated variable, processing data from DS18B20 and converting it to degC with simultaneous dynamic display - a fairy tale, in addition to simultaneous operation of the dynamic display and menu operation in which, among others, I change the brightness of the lights - no problem.

    Best regards
  • #16 21830560
    Strumien swiadomosci swia
    Level 43  
    saly wrote:
    Years ago I used assembler, then I fell in love with C++, I remember with assembler it was like ploughing acres of field with a hand plough.

    Tum no less sometimes it's nice to insert an insert in asm .....
  • #17 21832585
    astony
    Level 14  
    Bravo for the assembler. Pity not at2313 :) .
  • #18 21833967
    Sam Sung
    Level 33  
    astony wrote:
    Bravo for the assembler. Too bad not at2313 :) .
    When you write identical functionality in assembler on ATtiny2313, we'll compare the conciseness of 8051 vs AVR machine code :)
    It seems that the AVR must lose by a landslide because:
    - it's RISC
    - there are no single-byte commands
    - there is no hardware division (by 10)
    - even the GPIO has to be set up
  • #20 21834446
    rb401
    Level 39  
    Sam Sung wrote:
    Andrzej_Tomaszewski wrote:
    or just about single resistors?
    That kind of circuit wouldn't fit on such a small board.


    Your board would fit another twenty resistors without any problem.
    Using SMD resistors instead of chip resistors. SMD resistors of size 0805 and 0603 fit best on such universal boards. The use of SMD allows, among other things, the use of areas covered on the other side, e.g. the base or the display. If the boards have metallized holes, wire connections can be made both on the component side and on the other side. And just using these resistors in such a context, in my opinion, is quite a lot more convenient than the through-hole ones.

    Here, for example, is a typical universal board with a 2.54mm grid and some resistors of both the 0805 and 0603 dimensions, where you can see how much space is left on the eyelet for the wire:

    Close-up of a prototyping board with through-holes and several soldered SMD resistors
ADVERTISEMENT