2.2.2
A Smart Way to Keep Cool
A Smart Way to Keep Cool
What to expect
In this activity, you will connect a micro:bit to a DC motor to create a smart fan. The speed and direction of the fan can be controlled based on programmed conditions such as a button press or sensor input.
Connections
In the previous activity, you created a game using embedded input and output signals. In this activity, you will explore external output signals. These activities will come together in a final project later in this unit.
Materials
Micro:Bit w/ USB cable
Driver Expansion Board
4AA External battery pack or USB power cable
DC Motor
Mini Propeller Fan
There are three main parts to this activity:
Assemble the Hardware
Create a Simple Program to Test Motor Function
Make a Temperature Controlled Fan
Instructions
Assemble the Hardware
Connect your micro:bit to the Driver Expansion Board. (Make sure the micro:bit LED matrix is facing outwards – away from the motor driver board.)
Connect the DC Motor to the Driver Expansion Board as shown. Loosen the screws, but don’t take them out for M1+ and M1-. Attach the motor. At this point, it doesn’t matter which wire goes to M1+ or M1-. Just connect one to each. (Hint: You are using M1 for this activity, but the motor driver expansion board is capable of operating 4 DC motors at the same time – for future activities!) If you have rings on the end of the motor wire, twist them, and carefully remove them by pulling back and forth.
3. Motors need more power than what the micro:bit typically provides. Connect the 4AA external battery pack to the motor driver expansion board. Alternatively, you can use the special USB power cable that works with the motor driver board. Either is fine for this activity, but you only need one or the other.
4. Place your propeller on your DC Motor. Press it on to the end of the DC Motor, by wiggling it back and forth if needed.
Create a Simple Program to Test Motor Function
Figure 1 : Naming the project
Create a new project using Micro:Bit Makecode. Name it something like “2.2 DC MOTOR FAN”
Figure 2: added extensions part 1
2. This activity uses special blocks to control the motor with the motor driver board. Click on “Extensions” from the blocks menu.
Figure 3: added extensions part 2
3. This extension isn’t in the featured menu. Instead, copy and paste the following link: https://github.com/DFRobot/pxt-motor. Select the “motor” extension that appears. The extension is now added to your block library.
4. Once you have the extension added, you’ll notice some new blocks that can control motors:
5. Create the following code to test your connection:
Code explanation:
In this code, you are telling your motor to turn on at a speed of 30 out of a possible range of 0 - 255, where 255 is fastest – all the way on – and 0 is slowest – off) when button A is pressed. Pressing the B button will stop the motor and “reset” the speed back to zero. When you push A+B at the same time, the micro:bit will increase the speed by 10.
2.2.1 DC MOTOR FAN SETUP: https://makecode.microbit.org/S79343-55776-51749-03260
Make a Temperature-controlled Fan
Try this code to have the fan turn on when temps are above 30C (86F). Note that the A button is used to stop the motor if needed, giving the user a 2-second delay before it checks the code again.
2.2.2 DC MOTOR TEMP CONTROLLED FAN: https://makecode.microbit.org/S72486-67173-16879-20730
Tip: If you want to use Farenhieght temperature measurements, you can modify your code to use this instead. Just substitute temperatureC with the ‘tempF’ variable in your If-Then blocks.
Test your program by applying some warm air to the micro:bit. Use some sunlight or blow hot air on it. If you have a hair dryer or some other warmer, you can use that, too… just be careful not to make things too hot!
You can add more options to the if-then statement… For example, maybe if it is 35C (95F) the fan will turn on at twice the speed!
Going Further
Can you make the motor turn the opposite direction when pressing a different input, like the logo button or adding conditions to you if-then statement?
Think about it
In this activity, you controlled a DC motor with the expansion board.
Do you have a better understanding about how DC motors work?
Did you have any ideas of fun things you could do with the DC motor?
Feedback link