Use output pins as GND and control them

Hi everyone,

I have a question to which I can't find any answers... I have in my possession arduino ESP8266 with which I have already programmed a lot of things but here I would like to recover leds from an old coffee machine ... The problem is that the 5V+ is connected on all the leds (printed circuit that I keep) and when I have an output with HIGH or LOW as variable it's 5V+ that comes out of my pins. So I can either turn them all on or off by linking all the GDNs but I would like to be able to control them one by one. Is there a solution to get out of the GND on the output pins and to be able to choose the ON/OFF as HIGH/LOW?

Thanks in advance,

Sébastien C.

Yes, it is standard practice to use an output pin as "ground".

You must use a current limiting resistor with an LED, and obey the restrictions on pin current. Check the ESP8266 data sheet for the allowable maximum current into the pin (it may be the same as "out of the pin").

Ok, thank you for your positive response :grinning:. I reused the resistors that were on the pcb and I'm sure the leds don't exceed the current limit of the arduino... Can you give me an example of a start of code for how I should I do to be able to do my ON/OFF with GND? I will understand it very quickly and will adapt it to my project but I don't know at all what I have to put to do that with the GND...

pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);  //set as virtual GND = LED  ON

Example for several LEDs:

Hi,
Are you wanting to connect the LEDs that are powered by the +5V pins of the ESP8266?
I don't think it's very safe, despite the current limiting resistor, even so when in HIGH, on the pin you will have +5V,
The ESP8266 datasheet states that the maximum voltage on the ESP8266 I/O pins is 3.6V.
" I/O VIL/VIH -0.3V/0.75V 0.25V/3.6V "

Good point above, although ESP8266 pins are often claimed to be 5V tolerant. Discussion here.

It is best to use a 3.3V source to supply the LED power. Reduce values of the current limiting resistors if needed.

Yes! Thank you very much :hugs:.
The sketch looks exactly like what I have.
But how can I turn off the leds? I will not send HIGH? It will create a short circuit, right? Or do you have to send HIGH to turn off the led? Can you tell me more please?

Yes...

But I can use an external 5V+ input, I think that's what I'll do, but know that I've already tested with 5 of the 9 LEDs on and there were no problems. And I will never have more than 4 lit at the same time for my project. So no risks at this level :wink:.

I always use them in 5V and I never had any problems for my part :slightly_smiling_face:. But I can try in 3.3V, it costs nothing to test...

If you power the LEDs from the 3.3V supply, then set the port pin HIGH to turn off the LED.

You may not be able to turn the LED off it is powered by 5V, because the port pin output voltage cannot exceed 3.3V.

Wrong.
If you think it will create a short circuit then I think you need to know more about basic electrical theory.

Yes I know, a friend sent me the book "The Arduino for Dummies" and I'm going to read it. For the moment I haven't really learned anything yet, I watch, I analyze and I create according to my projects that come to mind. I don't have any in-depth knowledge of this :wink: .

Thank you very much @jremington !

Use ULN2003 or ULN2803 to drive the leds from 5V. Or use transistor like BC547 or BC817 (SMD)

How much mA need the leds? IO Imax = 12mA. From the datasheet page 19.

. Old leds are in most cases 20mA but you don't know by recuperation leds. If they are 2mA and you put 10mA on them, they hasn't a long time to live.