Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

curious not the same? HIGH(relay) or relay=1

Status
Not open for further replies.

MrDEB

Well-Known Member
Was redoing some code I wrote last year for a beer cooler, basically cleaning it up making it work more efficient. Found several minor issues and unwanted lines of code.
I couldn't figure out why Relay = 1 didn't work but High(Relay) works.
Shouldn't both be the same? the relay is pin 1 of a uln2803 which is my next step, connecting and getting it to work as planned.
Code:
  // main program loop...
 
            sens_temp()                    //call sub routine for box temp
          
            LCD.MoveCursor (1,1)
            LCD.WriteAt(1,1,"desired temp=", DecToStr(deg_s))  // Display DESIRED TEMP  using ADC
            
            LCD.MoveCursor (2,1)
            LCD.Write("box temp = ", DecToStr(tempF),"    ")   //Display box temperature
            DelayMS(500)
           // LCD.Cls
     If tempf < deg_s Then High (Relay)    // box temp is at or below desired temperature 
      LED_g  = 1 // green led  on
      LED_r = 0
      End If
     If tempF>=deg_s +3  Then Low (Relay)     // box temp is at or above desired temperature 
      LED_r  = 1 // red led  on
      LED_g = 0
     End If 
        
     Wend
     //xxxxxxxxxxxxxxxxxxxxxxxxxxx
 
I would guess that high sets the pin to output as well as setting it to 1.

Mike.
 
I thought about that so I tried setting the pin as output(Relay)
but didn't seem to make any difference.
After I get done with this I want to look into this minor issue just out of curiosity.
 
Pommie is right. In Swordfish Basic (you really do need to specify what language you're asking about),

Code:
Dim BrdLED As PortB.0

Output (BrdLED)

On = 0
Off = 1

BrdLED = On

BrdLED = Off

Works fine. My LED is connected between +5v and the port pin, so a low port pin turns the LED on and a high port pin turns the LED off. The HIGH() and LOW() commands take care of setting the pin to be an output automatically.

Don't forget you'll need the SetAllDigital command from Utils.bas if you're using an analog pin for your relay – well, at any rate, that pin needs to be set to digital if you're using some ADC pins to read a sensor or something.
 
I just looked over my code and I thought I had the SetAllDigital but must have deleted it along the way. Using last years code. I do have the Utils.bas .
I also put OUTPUT (relay) but will investigate. Pretty sure its the SetAllDigital being deleted in error. I have some printed code from last year and SetAllDigital is in there.
For the relay, I am using a ULN2803 w/ 4.7K pullup on pin 1. Have pin 10 connected to 12v+ as well but using a diode across the relay coil so the diode is not really needed but its there just for safe keeping.
I never tried LED = On. Have only used LED = 1 or HIGH (LED). Learn something every day.
Oh before I forget, I looked at your greenhouse code and see how you handled the DS18B20 conversion ( tempF = ((TempA * 10+ TempB / 1000)*9/5+320)/10 ). This math works very well and easier to do the comparison between desired temperature and actual temperature. What I had worked but not real well.
 
You don't really need the diode across the relay. The ULN2003/ULN2803 chips are specifically designed to drive relays and have the necessary back-EMF diodes built in. It won't hurt anything but won't help anything either.

You also don't need the pull-up resistor at the input of the ULN2803. The micro port pin is always defined as an output and is always high or low.

A pull-up resistor is usually used with an open collector output. An open collector output is tied to ground when asserted, and floating when it's not. A pull-up resistor is used to pull an open collector output high when it's not asserted.

A pull-up resistor doesn't provide any benefit in the circuit you described. In fact, it just wastes some power unneccessarilly fighting the micro output.
 
I had the pull up in the circuit from last year and just left it there. The revisions I made for this year was to put the 7805 voltage regulator on board with the pic. Being 3 ft away I was getting erratic behavior from the circuit. YES poor design on my part. Should have known better.
Over the winter I had a hard drive crash and most all my info on the beer cooler went poof! so using what I had printed for code and schematic (several pages of revisions) I was able to basically redesign the power supply on- board w/ the pic and edit the code.
I mentioned the diode in post #5 but debating on leaving it or cutting it out of the circuit. The resistor on pin 1 is history.
 
Status
Not open for further replies.

Latest threads

Back
Top