What to expect
You will be building and coding a “smart house” filled with several features based on what you have learned in previous activities. This activity might take a couple of sessions – that’s ok!
Connections
In the last few activities, you experimented with analog and digital signals using devices like servo motors, DC motors, and RGB LED module. In this activity, you will be building a smart house and applying what you have learned (and re-using some of the code!) from previous activities to creatively demonstrate all of these concepts (and more!) together.
Materials
Micro:bit w/ USB cable and battery pack
Motor driver expansion board w/ 4AA external battery pack or USB power supply cable
(2) Servo motors
(2) DC Motors
RGB LED Module w/ Jumper Connector
Building materials such as:
Cardboard or foamboard (bonus points for recycling and reusing!)
Hot glue, tape, or other building materials
Cutting tools like scissors or knife
Other Misc. items to decorate your house such as markers, construction paper, etc.
Instructions
This activity has two main parts:
Designing the house
Integrating micro: bit-controlled features
Designing your house
In this part of the activity we encourage you to be creative with making your smart house.
You can design the house however you want. Just make sure that there is an opening in the back of the house so you can see everything. You also want to make sure that there is enough room for a door, an opening for a window or a sunroof.
Figure 1. Example of completed house
Part 2 Connecting the micro:bit
In this part of the activity we are going to glue a “crate” onto the wall of our smart house. We will be doing this because it will make it easier to connect servos and lights to the micro:bit since some of the wire aren’t very long.
Make a crate that surrounds the driver expansion board. This will let your micro:bit stick to the wall. Make sure that there is an opening for the switch and a place to insert the battery wire.
Figure 2. Cradle for micro:bit
2. Connect the crate with the micro bit in it to the side of the wall but make sure that there is enough room to fit a battery.
Figure 3. Battery
3: Add a 5V battery to the bottom of the crate that looks like this.
Figure 4. Battery connecter
3: Unscrew 2 of the connections on the driver expansion board. Make sure that it is the 2 screws that are right by the on and off switch.
Figure 5. Connected Battery
4: Connect the 5V battery. At the end it should look like this.
Integrating Hardware and Coding
Making the Door Movable
Idea 1: Make a movable door using a servo.
Figure 6. Servo
Screw in the white plastic arm into the servo motor. The white plastic arm that we will be using for the door will only have one side (make sure you are not using the double sided white plastic arm).
Figure 7. Door
2. You will want to cut a hole with an Exacto knife (or other accessible tool) in the front to make a door for this first part. Make sure that you keep the cardboard from the hole for the door because we will need it to hook it up to the servo.
Figure 8. Door Hinge
3. Tape the servo motor onto the wall right above the door, and then tape the white part onto the top of the door.
Make sure to add the motor driver expansion board extension like you did in previous activities. Copy and paste this link https://github.com/DFRobot/pxt-motor into the search bar of extensions. (Because this is an unpublished extension, you cannot search it directly and instead have to search using the link.)
Here are some ideas to try. Feel free to “borrow” these ideas for your design, or create your own!
Servo controlled door
Figure 9. Code controls the servo to open and close the door
This code controls the servo to open and close the door. A variable with the “if” block to create a toggle for the door. When the micro:bit starts, the “Door” variable will be set to zero. This means that the door is currently closed. When button B is pressed, the servo will move to 145 degrees out of its 180-degree range, opening the door. Then it will set the “Door” variable to 1 to store the information that the door is open. If you press button B again, the code will run through the first part of the “if” statement. The servo will move to 22 degrees out of its 180-degree range, closing the door. The variable “Door” will then change back to 0, showing that the door is closed.
Figure 10. Connecting the servo
2. Connect the servo to the micro:bit by connecting it to S3, and make sure that the brown pin is connected to the ground so it can work.
Sunroof
In this next section, we will be making a sunroof that automatically adjusts based on how much light the sunroof gets. You can also use this same process to create a window on the side of the house.
Screw the white servo arm into the center of the servo motor. The white plastic arm we will use for the sunroof only has one side (make sure not to use the double-sided plastic arm).
2. Cut a square hole on the top of the house, but keep the bottom side of the hole connected to the house so we can capture light levels most efficiently.
3. Tape the servo right next to the hole and then tape the white part of the servo to a popsicle stick connected to the piece of cardboard from the hole.
4. Connect the servo wire to the micro:bit driver expansion and make sure it is connected to S1, make sure that the brown piece is connected to the ground so it powers the servo properly.
5. Create a variable called “Location” and create the following code to control your sunroof (this is the same code we used when creating our dial that measures light!).
The “Location” variable is the final number that the servo motor is set to. The “map” block tells the micro:bit to take the “light level” input with a range of 0-255 possible levels and convert it to a range from 20-160. This will change the possible range into one that fits into the 0-180 range of that the servo arm can position itself to (allowing 20 degrees of room on either side so that the door doesn’t open or close too far).
RGB LED “Party Light” Module
In 2.4, you learned how to use an RGB LED module. Consider adding an RGB LED module to your design!
Here’s an example we came up with of turning on a light when a loud noise is heard. Feel free to create your own solution!
Figure 17. Code for the house
Explanation of the code
Similar to the door, the “Lighting” variable and “if” statement create a toggle. When a loud noise is heard by the micro:bit it will change the “Lighting” variable between 0 and 1 or on and off. If there is a loud noise and the light is off (Lighting = 0) it will turn the light on (set Lighting = 1). If there is a loud noise and the light is on (Lighting = 1) it will turn the light off (set Lighting = 0).
In the forever block, we tell the micro:bit what to do if the lights are on or off. The green, blue, and red light have a maximum brightness level of 1023. When the light is on (Lighting = 1) the micro:bit will turn on the light attached to P0 and turn off the other colors. It will wait 200 milliseconds then turn on the light attached to P1 and turn off the other colors. It will wait another 200 milliseconds then turn on the light attached to P2 and turn off the other colors. It will wait 200 milliseconds and repeat these steps as long as the light is on (Lighting = 1). When the light is off (Lighting = 0) the colors connected to all the pins will be turned of or equal to 0.
Figure 18. Code for the house
Air Conditioning System (DC Motor)
For this part of the activity we will be adding a DC motor. We will attach a plastic propellor piece onto our DC motor to create a fan. We will be making an AC system in our house; However, you can make it into whatever you want it to be (fan, wind turbine , etc.).
Figures 19 - 20: setting up the fan
Get a mini propellor fan and a DC motor.
Connected the propellor to the metal rod on the end of the DC motor.
Figure 21: setting up the fan
3. Make sure to make a hole in the back so the cord can connect to the micro:bit.
4. The next step is to make a hole on the side of the house that we have not done anything to yet, so we can put the ac system in it. You also want to add a roof on top of your AC system and glue it onto the side of the house with the hole. Refer to activity 2.2 for examples of how to work with the DC motor. Add this code to your project.
Think about it
In this activity, you created your own party house that integrated the features you've developed in this unit based on programmed input conditions.
How could the features of this house make your life easier in your own house?
Where have you seen the features of this house in your community?
Feedback link