-->
Page 1 of 1

3.4v led 20ma using nodemcu

PostPosted: Sat Mar 12, 2022 1:00 pm
by Happ
I'm completely new to electronics, electricity and wiring but having a great time learning so here I am. I'm planning on using a 3mm 3v-3.4v 20ma led with a nodemcu esp8266 and 9v battery. It'll use a simple on/off switch so won't be powered for very long. I've setup a quick test with what I had using a 5mm led that came with an arduino kit using the usb for power and a 650ohm resister. I'm using pin 13 or D7 with the sketch I uploaded to pulse the led. Using a 9v battery the led on the breadboard was much brighter than when using the usb. My questions are: How do I get my 3-3.4v 20ma from pin 13? From everything that I've reviewed it won't output 20ma to an accessory like an led. Do I need something in between pin 13 and the led to get the current required? How many volts does the nodemcu use so I can calculate my resistors down the line to include the power being used by the nodemcu? I have a few things in addition to the led that I will be connecting to the 3.3v rails that require less current which I'll use resistors for. Any help would be appreciated. Thanks.

Re: 3.4v led 20ma using nodemcu

PostPosted: Sat Mar 12, 2022 4:07 pm
by btidey
Driving an LED directly from a ESP8266 GPIO is OK providing you only want a smallish current <10mA AND the LED has a turn on voltage less than 3.3V. This turn on voltage varies with the colour of the LED with blue or white LEDS having the highest turn on voltage. You then calculate the resistor by taking the 3.3V supply - turn on voltage and dividing by the current you want.

When you want higher currents or you want to better handle LEDS with higher turn on voltages then you need a driver between the GPIO pin and the LED. The driver can be a bipolar transistor or a MOSFET transistor.

You can find simple schematics on the web for both of these. Basically the GPIO drives either the base (bipolar) or the gate (MOSFET). The emitter (bipolar) or source (MOSFET connects to 0V, and the LED + current limiting resistor goes to your power supply (e.g. 5V or 9V). In the biploar case you need a resistor between the GPIO and the base to et how much current is fed into the transistor to switch it on. This isn't needed for the MOSFET case.

If you only want 20mA LED current then the biploar using just about any npn transistor may be easiest for you. If you want to drive powerful LEDS with much higher currents then the MOSFET method has many advantages.

Re: 3.4v led 20ma using nodemcu

PostPosted: Sat Mar 12, 2022 7:05 pm
by Inq720
You're right... about noting that the NodeMCU should not be asked to supply 20 mA our a pin. And btidey is right.

I think... the 20mA number on LED is like their max rating... not what will get them lit. Here's a calculator I use all the time... you can put in btidey's suggestion of 10 ma, and the details about the LED and the 3.3V of the pin and it'll calculate the resistor you need.

http://ledcalc.com/