Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to understand HIGH and LOW
22-01-2014, 07:24 PM,
#1
Trying to understand HIGH and LOW
Hi, i am new with pinguino and i'm trying to make a relay work. I attached one side of the relay to the pin 22 and other side to +5V. When I want to close the circuit i have to send LOW to that pin. It works ok but it is unconfortable, i prefer writing HIGH to close the circuit, so I connected one side of the relay to the pin and another to GND. The problem is that when I do this the circuit doesn't close with HIGH or LOW and i don't unserstand why.
I hope you to help me.
Greetings!
Reply
22-01-2014, 08:33 PM, (This post was last modified: 24-01-2014, 10:50 AM by fcapozzi.)
#2
RE: Trying to understand HIGH and LOW
It dipends how much current you need to trigger the switch .. a pic pin usually is capable to source from 10 mA to 50 mA dipends of the data sheet so if this current is enought to trigger the relay simply connect the pic pin to the relay instead of 5V and the other relay pin to ground.
In your case that is the case A the relay don't close probably because the max source current capability of the pic is not enough to trigger the winding.
Look at this drawing.

   

The case that worked for you is B. Here you have to pay attention because usually the relay winding primary has a very low resistance and so the pic pin is forced to sink a potentially higher current that the port can handle. The internal circuitry can be broken up if the device does not have an internal over-current protection.

The situation that could solve you problem is the case A. Here the pin when set HIGH has 5 Volt output and can drive the relay winding if the triggering current is lower than the max current that the pic pin can source (see datasheet) but for your relay it wont work as you seen.

A better alternative is to use a transistor used as a switch (in the saturation region) to separate the pic from the primary relay winding. In this case C, a very low current is capable to put tthe transistor in the saturation region. When this happen, the voltage across collector and emitter is about 0.2 Volt. So if you put a HIGH level on the pic pin you have a quite zero (0.2V) voltage entering the relay.
When you put a LOW level in the pic pin the transistor shut-off and the collector became floating (now the voltage entering the relay is 5 volt minus the voltage drop in the Rb resistor. You can choose the resistor in order to have whatever current you want in the relay. Only pay attention that when the transistor is saturated this current will flow inside the transistor.
Let make a practical example. Suppose that your relay need 100 mA to switch. This current is higher than the pic pin capability .. so we choose Rb = 5/100*1000 = 50 Ohm
If we choose BC548 general purpose transistor for Ic=100 mA the datasheet report that we need a current of 5 mA to make him saturate ... so we can calculate the Ra with (5-Vbe)/Ra = 5mA
in the saturation voltage the Vbe is around 0.75 V so solving last equation we have 832 Ohm .. so any resistor lower than 832 Ohm will make the transistor reach the saturation region.
We can choose a common value of 470 Ohm ..

(22-01-2014, 07:24 PM)matiaslang Wrote: Hi, i am new with pinguino and i'm trying to make a relay work. I attached one side of the relay to the pin 22 and other side to +5V. When I want to close the circuit i have to send LOW to that pin. It works ok but it is unconfortable, i prefer writing HIGH to close the circuit, so I connected one side of the relay to the pin and another to GND. The problem is that when I do this the circuit doesn't close with HIGH or LOW and i don't unserstand why.
I hope you to help me.
Greetings!
Reply
28-01-2014, 06:49 AM,
#3
RE: Trying to understand HIGH and LOW
The common way to control the relay is using a transistor like the case C fcappozi mentioned in his post, but his circuit has a few flaws.

Firstly when PIC outputs HIGH, the transistor turns on and the relay cuts off. It is still LOW output from PIC to energize the relay it is not what you want. The circuit draws high current via Rb while the relay is off. There is voltage drop at Rb reducing the efficiency of relay operation.

Better (or proper) way to control the relay is using the transistor as low side switch. I use N channel FET 2N7000 to drive the relay instead of the transistor. Please refer to the circuit attached.

There are many advantages to do so. While a transistor is a current amplifier, MOSFET is a switch and it is more efficient to control ON/OFF status with uA current to the gate. 2N7000 can handle max 60V 200mA with less than 2 ohm resistance when turned ON. Many small relays can be driven by less than 10mA current to energize. With this way, you can also use bigger size relay to 12V instead.

It is very important to add the diode parallel to the relay to protect the circuit. The led parallel to relay is for indication of the switch status only and not necessary for operation.


Attached Files Thumbnail(s)
   
Reply
28-01-2014, 08:28 AM,
#4
RE: Trying to understand HIGH and LOW
(28-01-2014, 06:49 AM)djpark Wrote: Better (or proper) way to control the relay is using the transistor as low side switch. I use N channel FET 2N7000 to drive the relay instead of the transistor.

I wasn't aware of this nice little transistor. It's cheap as an conventional bipolar transistor (5 euro cent) and has an logic level interface.

Many thanks for this tip!

An extract from the datasheet:
Features
  • Low Threshold: 2.1 V
  • Low Input Capacitance: 22 pF
  • Fast Switching Speed: 7 ns
  • Low Input and Output Leakage
Applications
  • Direct Logic-Level Interface: TTL/CMOS
  • Drivers: Relays, Solenoids, Lamps, Hammers, Displays, Memories, Transistors, etc.
  • Battery Operated Systems
Reply
28-01-2014, 09:57 AM,
#5
RE: Trying to understand HIGH and LOW
It is a versatile yet cheap fet indeed. The best thing I do with it is using it as TTL / RS232 converter. The input gate / source voltage is +/- 20V and it can take RS232 input directly. It is so convenient to use this for serial interface instead of adding RS232/TTL converter chip.

Thanks to its low input capacitance, it produces clean output for 115,200 baud.
Reply
28-01-2014, 11:01 AM,
#6
RE: Trying to understand HIGH and LOW
(28-01-2014, 09:57 AM)djpark Wrote: The best thing I do with it is using it as TTL / RS232 converter. The input gate / source voltage is +/- 20V and it can take RS232 input directly. It is so convenient to use this for serial interface instead of adding RS232/TTL converter chip.

Interesting. Could you provide a schematic? That's worth to write an little article in the pinguino wiki.
Reply
28-01-2014, 04:39 PM,
#7
RE: Trying to understand HIGH and LOW
I didn't create the circuit, I picked up from Internet. Google search will bring many. You can get the detail from a few of them such as...

http://www.botkin.org/dale/rs232_interface.htm

http://weeklybuild.com/2007/03/cheap-and...converter/
Reply
28-01-2014, 06:49 PM,
#8
Tongue  RE: Trying to understand HIGH and LOW
(28-01-2014, 04:39 PM)djpark Wrote: I didn't create the circuit, I picked up from Internet. Google search will bring many. You can get the detail from a few of them such as...
http://www.botkin.org/dale/rs232_interface.htm

Thanks for the hint. I have found some more schematics on google searching for "level shifter 2n7000". This one is a bidirectional 3V3 <-> 5V level shifter working with I2C and SPI.
Just for the record :-)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)