# How to switch an LED using logic 0 and 1

The PL2303HX is used to convert USB serial bridge controller.

I would like to connect an LED to TXD pin so that it lights when it is logic 1 and off when it is logic 0.

PL2303HX

PL2303HX datasheet

I would like to consider 5mm white LED (3.3v,20mA).

Can I directly connect the LED anode to TXD with a resistor and cathode to GND.

Does it affect the baud rate?

Is it safe to draw 20mA from TXD pin?

Is there a better way to light the LED using Vcc(5v) as power source and TXD as on and off like-

EDIT

I tried above circuit, but getting error.

I want the LED to turn off when logic 0 and turn on when logic 1. LED is powered by 5v separately. It should switch at the rate of 9600 baud rate.

• what does the datasheet say about maximum current supplied by the TxD pin? – jsotola Dec 18 '19 at 7:56
• "I tried above circuit, but getting error." - what error? – Bruce Abbott Jan 18 '20 at 11:09
• @BruceAbbott I connected TXD to NOT input and output to LED cathode. I thought when TXD is logic1 it is forward bias(on) and logic 0 reverse bias(off). LED is powered by 5v Vcc and I removed pin 1 of NOT gate connection with TXD but the light glows. – Sathvik Jan 18 '20 at 11:16
• @BruceAbbott when I transfer 01111110 I get like 01010000 .I know for sure there is a problem with transmission circuit – Sathvik Jan 18 '20 at 11:18
• @BruceAbbott Actually I don't have NOT gate but I am using MC74F00N Quad 2-Input NAND Gate. Where pin 1 and 2 are connected to TXD and 3 to LED – Sathvik Jan 18 '20 at 11:24

You need to reverse the orientation of the LED. Connect the anode of the LED to the output of the NOT gate, then connect the cathode to the resistor and the other end of the resistor to ground. The LED will light when the output of the NOT gate is high, which is when TX is low.

• I want to draw power from Vcc not from TX. I want TX as switch logic 0 off,logic1 on – Sathvik Jan 18 '20 at 13:16
• 'Connect the anode of the LED to the output of the NOT gate, then connect the cathode to..' I tried to emulate but did not work. – Sathvik Jan 18 '20 at 13:17
• You will be drawing power from the NOT gate, which is drawing its power from Vcc. – Elliot Alderson Jan 18 '20 at 14:02
• ya, got it but how much voltage does logic 1 is produced by MC74F00N. Is it 5v – Sathvik Jan 18 '20 at 14:08
• Well, you didn't tell us you were using a 74F00. That would have been helpful information. Use an actual CMOS inverter instead. – Elliot Alderson Jan 18 '20 at 14:13

Yes, there is a better way: A transistor.

A transistor can be used to switch a strong signal (high LED current from +5V supply) with a weak signal (TXD output pin) without degeneration of the weak signal.

You could use a MOSFET, but they often have high gate capacitance which burdens/degrades the TX signal. It would be better to use a bipolar transistor, but there you need an additional bias resistor for the base.