user16593: I have a simple fan.
When I plug it to GND and Vin it spins.
I'd like to have the ability to turn it on / off with code.
Any example will do, as long as it gets it to spin.
I have a NodeMCU board, if that helps.

user33226: Depending of the type of fan you are using, two solutions exist. 

First one, use a MOSFET to drive the FAN from you nodemcu 
Second one, use a relay to drive the FAN from your nodemcu 

Things to consider :

The mosfet allow you to drive the fan without mechanical part moving. 
The relay require some transistor and feedback diode to be driven by your µc. 


16593: <p>I have a simple fan.
When I plug it to GND and Vin it spins.
I'd like to have the ability to turn it on / off with code.
Any example will do, as long as it gets it to spin.
I have a NodeMCU board, if that helps.</p>
 33226: <p>Depending of the type of fan you are using, two solutions exist. </p>

<ul>
<li>First one, use a MOSFET to drive the FAN from you nodemcu </li>
<li>Second one, use a relay to drive the FAN from your nodemcu </li>
</ul>

<p>Things to consider :</p>

<ul>
<li>The mosfet allow you to drive the fan without mechanical part moving. </li>
<li>The relay require some transistor and feedback diode to be driven by your µc. </li>
</ul>
