-->
Page 1 of 2

esp2866 + transistor to switch a couple of LEDs?

PostPosted: Thu Feb 28, 2019 4:59 pm
by Bringamosa
Hi all,

I was wondering if anybody here could help me out. I want to switch 3 LEDs from a 12v strip with the esp8266 running its server.

I got the code running, when giving the commands on the website I can measure the GPIO2 pins voltage, 3.3 at high and 0 at low.

Next step is to incorporate the transistor part. I have the 2n2222 transistor. Collector to the 12v side, base to gpio2 with a 220ohm resistor in between, emitter to ground.

See attachment for the schematics.
[img]here[/img]

However when I plug in the esp8266, it won't go true it's usual cycle. The red powered goes on, but also the blue led stays on.
When I remove the connection to the gpio2 pin it will boot normally.

Anybody any idea? If code is needed I can post that too.

Kind regards.

Re: esp2866 + transistor to switch a couple of LEDs?

PostPosted: Sat Mar 02, 2019 5:46 am
by schufti
main problem: gpio2 is pulled low via b-e of transistor. With gpio2 low, esp wont boot user code.
fix: place resistor between gpio2 and base of transistor.
good practise: use pull-up on gpio0, gpio2, rst for stable operation.

for your set-up 1k pull-ups und 4k7 between gpio and base should work,
depending on led-current and beta of transistor (est. 100).

Re: esp2866 + transistor to switch a couple of LEDs?

PostPosted: Sat Mar 02, 2019 12:46 pm
by Bringamosa
Thanks for the fast answer.

I want to switch only 3 leds, in total consuming 40mA. With the help of some other people we came to the conclusion that 220ohm is good to switch.

So knowing the problem now I have installed a momentary nc switch between the resistor and 2n22222 base. When booting up I press the button and break the connecting between base and gpio pin. This works for now.

However I prefer not to use the button so a 1k pullup would be nice. Please forgive me for the noob question, will this resistor go between gpio pin and ground, or vcc?

And, the resistor between 2n2222 and base, you suggest is now 4.7k because of the pullup resistor it changes so much? Also very new to transistors, calculating the resistance is still a bit magic for me.

Re: esp2866 + transistor to switch a couple of LEDs?

PostPosted: Mon Mar 04, 2019 5:13 pm
by Bringamosa
Thanks. Instead of resistors I have just used a NC push button. I break the base to gpio connection when booting and it works now :)