I've attached a fritzing showing how everything is hooked up.
Ontop of what I have on the sketch there is also a DHT11 for temperature and humidity hooked up to all of this.
Everything is working alright but I'm afraid I might have made some kind of error when hooking it up because when I have the system hooked up to my PC via USB I constantly get the connect/disconnect sound of a USB device connecting/disconnecting.
The DC motor in the fritzing is really a 3V-5V water pump.
Is there something wrong with my wiring? And if so what?
You can't draw that much current from a USB port, the stall current of the pump is way higher than 100 or even 500mA. There's probably a polyfuse on the NodeMCU and in the computer as well, so the voltage drops. Either the CH340G resets or browns out, or the computer turns off the USB port because it thinks the device is faulty.
You should add reservoir and decoupling capacitors as well, and a flyback diode across the motor.
PieterP:
You can't draw that much current from a USB port, the stall current of the pump is way higher than 100 or even 500mA. There's probably a polyfuse on the NodeMCU and in the computer as well, so the voltage drops. Either the CH340G resets or browns out, or the computer turns off the USB port because it thinks the device is faulty.
You should add reservoir and decoupling capacitors as well, and a flyback diode across the motor.
Pieter
I see. I thought that might have been the problem.
My external power supply is 5V 2.1A and I believe that should be sufficient for my needs. But when developing from the computer I will then need what you said about a reservoir and decoupling.
No, the capacitors and diodes are not a replacement for a capable power supply. You shouldn't power a powerful motor from a USB port. Period.
When developing on your computer, either use an external power supply for the motor alone, or replace the motor by an LED or something.
You could add a diode between the external 5V supply and the NodeMCU's 5V pin for powering it when the USB is disconnected. Take a look at the schematic of the Arduino Nano for example.
That's impossible. 3W @ 3V → 1A, not 0.05A, one of these figures has to be incorrect.
Voltage alone means nothing, you need to know the current as well.
Then your only option is to measure the current draw of the motor. If your multimeter has min/max options, try measuring the maximum current drawn by the motor, and the minimum voltage on the 5V line.