Introduction

When it's hot outside, it might be a pleasure to have a mini fan nearby. This lesson will teach you how to use a micro: bit to build a mini fan, and we can use a button to control the relay to turn on or off the fan. Connect the switch button to the P0 interface, connect the relay to the P1 interface, and connect the fan to the other side of the relay.

Parts Needed You will need the following parts:

WIRING 

Connection for the relay:
Microbit Breakout Relay
5V VCC
GND GND
P1 SIG
Connection for the  button module:
Microbit Breakout Button Module
5V VCC
GND GND
P0 SIG
How to connect the DC motor :
Micro bit breakout Relay DC Motor
​/ COM Red wire
GND / Black/Brown Wire
+5V NO /

Run Your Script

If you are not familiar to make code, don't worry. At first, you can enter this link: https://makecode.microbit.org/reference to get the reference of microbit block.Either copy and paste, or re-create the following code into your own MakeCode editor by clicking the open icon in the upper right-hand corner of the editor window. You can also just download this example by clicking the download button in the lower right-hand corner of the code window. https://makecode.microbit.org/_VRPHPy82Tb0s

RESULT

When the download is completed, press the button, the relay is turned on and the fan is turned on; release the button, the relay is disconnected, and the fan stops turning.