

The "on button B pressed" event triggers and the micro:bit writes a digital 0 signal to pin P2. Press and release button B on the micro:bit. The part of the circuit connected to the motor is now closed and the motor turns on. A large amount of current (up to 200 mA) starts flowing from the positive terminal of the Battery Holder (B1), through the DC Motor (M1), the collector and the emitter of the transistor, the GND pin of the snap:bit, and back to the negative terminal of Battery Holder (B1). The small amount flowing through the base of the transistor is enough to trigger the current flow from the collector to the emitter. The resistor protects the transistor from this risk. The transistor would be damaged if a large current flows through it. The 1kΩ Resistor (R2) limits the current flowing to the base of the transistor to a very small amount - around 1 mA. This closes the circuit between the P2 and GND pins and a small current starts flowing to the base of the NPN transistor, through the transistor's emitter, the GND pin of the snap:bit, and back to the negative terminal of the Battery Holder (B1). The "on button A pressed" event triggers and the micro:bit writes a digital 1 signal to pin P2. Press and release button A on the micro:bit. Therefore, no current flows between the collector and the emitter of the transistor, so that part of the circuit is open and the DC Motor (M1) is off. When you close the slide switch (S1), the Battery Holder (B1) powers the snap:bit through the 3V snap and the micro:bit turns on.Īt this moment no current flows from pin P2 of the micro:bit to the base of the NPN transistor (Q2). Both the USB and the battery pack must be disconnected from the micro:bit. Then disconnect all cables from your micro:bit.
#Snap circuits code
Once ready, download the code to your micro:bit. You will find the "digital write pin" block under the Advanced > Pins section.Īlternatively, open the ready project here: You can build the code yourself in the MakeCode Editor.
