Temperature (F) to flashing tricolor LED

gengis

New Member
I wanted an excuse to use a DS18B20 to learn how to apply it, and coincidentally have a glass block wall on part of my house, and these dynamite tricolor LEDs that would look good coming through the glass from 20 feet away at night...

The design uses a high flux "piranha" style LED and 08M to read the sensor and control the LED. I already have a dawn to dusk LED area light mounted on a pole and 20 volts DC supplying it.

From 0-54F flash the tens blue / units blue, 55-59 tens blue / units green, 60-74 green/green, 75-79 green/red, 80-99 red/red. Long pause then repeats. Tens flash first with a 600 ms period, longer pause then units with a 400 ms period.

It might seem unwieldy to count flashes to find temperature, but in winter, at least, it is working pretty well.

The whole shebang mounts in an upside down small aluminum (cat food) can (Fancy Feast to be precise - sans cat food and cleaned). A hose clamp holds it to the light pole, and two contact, in line, weather proof connector supplies power. The sensor is wired to #26 AWG (thin so as not to add to the thermal mass) wire and hangs free of the can. Hot melt adhesive holds the wires down and LED in place. Two oversize disks of "closed cell" 3/8" thick plastic foam insulate the inside and keep the works from falling out. The sensor and connections are also dipped in varnish to keep water off the leads.

The code I can't take a lot of credit for.. marks helped me with the C to F conversions so it spans from zero F to 99 (limited by the program). The temp never goes below zero here and 99 at night, is unheard of.

Jamster supplied the logic and greatly improved my spaghetti code.

The small diode that isolates the 5 volt regulator is a 1N4148 and almost anything will work at this low power and voltage. I had 20 volts to play with and this prevents an accidental polarity reversal from killing the regulator or 'axe.

Code:
'Temperature display to leds: 0-55 blu-blu, 55-60, blu-grn, 60-75 grn-grn, 75-80 grn-red,80-99 red-red, >99 OFF
'Readout is a bright common anode tricolor LED (color is on when pin is low)


symbol DegreesF = w0
symbol tens = b10
symbol units = b11
symbol red = 0
symbol blue = 1
symbol green = 2
symbol color1 = b5
symbol color2 = b6
  high red                            'turns off the red led


main2:

    pause 2000                        'pause between whole numbers

    Readtemp12 4, DegreesF
    DegreesF = DegreesF+880*9/80-67         'degrees fahrenheit = 0 to 257

    
    units = DegreesF//10                 'breakout units
    tens = DegreesF/10                 'tens    
    

    if degreesF >=99 then goto main2        'upper limit
          

    'tens = 2                        'for checking dual color setpoints
                                '(main2 has to move too to take out degreesF)
    'units = 2   
    
    let b13=0

    pause 2000

    if tens<=5 then                    'temperature color set points

        let color1= blue                    '50F and lower tens is blue

    endif    
        if tens>=6 then                 '60F - 80F  tens is green
        let color1= green     
    endif

    if tens>=8 then                    
        let color1= red                    '80F and higher tens is red
    endif


    let color2 = color1                'Tens and Units have the same color unless...

   
 '****************
 

    if units>=5 and tens = 7 then            '75F green tens, red units
        let color2= red
    endif

    if units>=5 and tens = 5 then            '55F blue tens, green units
        let color2= green    
    endif

'****************

    
    do until b13=tens                    'Tens flasher
        low color1
        pause 300
        high color1
        pause 300
        inc b13
    loop
    
    pause 1000
    b13=0

do until b13=units                    'Units flasher (a little faster)
        low color2
        pause 200
        high color2
        pause 200
        inc b13
    loop

  goto main2
 

Attachments

Last edited:
Top