I want to wire a transistor into my setup (just a simple soil moisture sensore on my NodeMCU 1.0 ESP8266), so i can trigger my 5v water pump with this.
But something is wrong in my setup - everytime, i connect the 5v cable of my water pump it will start, but i should only goes on when the d2 (gpio4) is triggered in my script.
My wiring looks like this:
Left pin from transistor ---- d2
Right pin from transistor -- GND
middle pin from transistor - (-)pin (negative one) from my water pump
(+)pin (positive one) from my water pump --- 5V
The rest of my setup (soil moisture sensore on my NodeMCU) is not necessary, this works perfectly.
My scrip looks like this:
int soilmosture_Sensor = 0;
int speed;
const int motorPin = 4;
void setup() {
Serial.begin(115200);
pinMode(motorPin, OUTPUT);
}
void loop() {
int soil= analogRead(soilmosture_Sensor);
Serial.println(soil);
if (soil>= 800)
{
Serial.println("start pump");
analogWrite(motorPin, HIGH);
}
else
Serial.println("do nothing");
analogWrite(motorPin, LOW);
delay(1000);
}
Edit: ok i see, i used analogWrite instead of digitalWrite - however, the pump goes on when its connected to 5v.
It might be a good idea to post the specifics on the components, along with a hand drawn diagram of your circuit. Right off the start you need a base resistor, if you are using a bjt.
I use an BC547 NPN Transistor. Sorry for my lack of knowledge in electronic parts, but i'm more like an programmer with an affinity for IoT stuff.
(the dc motor is my 5v water pump. I had to use the d1 mini in this circuit, 'cause i don't have the Node MCU 1.0 ESP8266 part, but is nearly the same).
I thought, i have to wire the base from the transistor to a gpio pin (d2 in this case), so i can trigger my water pump. Also wire the vvc of my water pump to the ermitter, the gnd of the water pump to gnd of the esp8266 und the collector to the 5v of the esp8266. But i found this kind of setup somewhere in the internet.
The wiring is incorrect, check the datasheet for the correct pinout.
Look online for schematics to drive a DC motor.
I'm pretty sure that the pump draws more than 100mA, which is the maximum rated collector current for a BC547. You should use something more powerful, like a BD139 or a ULN2003, or maybe a 3.3V Logic Level MOSFET.
If you're using a BJT, you need a base resistor, otherwise, way too much current will flow from the ESP through the transistor to ground, damaging the microcontroller.
When using MOSFETs, it's recommended to use a small gate resistor and a large pull-down resistor.
When dealing with inductive loads like motors, you need a flyback diode to protect the transistor, and a capacitor across the power rails to keep the voltages under control when you turn off the motor.
Thanks. I will try a BD139 and a way new circuit. The pump draws around 130-220mA. So i hope this will work. 1k Ω resistor should be good for the base, i think? What kind of capacitor do i need for this project?
1k might not give enough base current to get your BD139 (BD135 is better) into full saturation.
The pump will only get 4volt if you're lucky (measure it).
You need a base current of about 10% of the collector current for that transistor to fully saturate.
You might be able to get away with 220ohm ((3.3-0.7) / 220 = ~12mA).
I think max pin current for an ESP is 12mA.
A "3.3volt logic" fet is ofcourse the best solution.
Leo..
How much µF should my capacitor have? The pump works with max 220mA and will get with some luck around ~4-5V from my esp8266.
So with the formula P = U * I i'll get 5 * 0,22 = 1,1 W.
I read somewhere, that 100 Watt needs around 0,1 farad. Which means i need (0,1 / 100) * 1,1 = 0,0011 farad, which are 1100 µF. Is this right? The capacitor should have something around 1100 µF? Is this not way too much?
(Also, when a capacitor get more then this amount, it will get destroyed. Does this mean the voltage and ALSO farad? But what happens, when it get way less than 1100 µF? i.e. 100 µF or 1 µF? Does his also work, because a capacitor can't be "to big"?)
Placing a bulk capacitor at the motor is a way to help minimize voltage sag when the motor demands high current loads, normally during startup. The capacitance needed depends upon the ability of the power supply to source that current, along with the wiring, connections, traces. Too much capacitance can act as a load to the power supply, while too little won't prevent sag. Small motors with adequate supplies may not require any capacitors at all.
You need to look up the specifications on your ESP. That is a lot of current you are trying to pull from a small regulator. I'm sure if you stall the motor, or put any kind of load on it, the ESP regulator is going up in smoke.
I was informed I made a blunder on my last post, and sure enough I did. Brain/finger miscommunication. The bulk capacitor goes on the fet power supply, not the motor itself. The reasoning is correct.
As for the power available from an ESP,....- there simply isn't enough to power the motor from the module. If the board has a USB input, the computer supply will still struggle to source the stall current + the ESP demands. A 3v motor would simply overload the regulator. A separate supply is the only safe bet.