8. Case 05: Smart Fridge Alert¶
Level:
8.1. Goal¶
Create a fridge that can detect the door state, when the door was not in close state for a long time, warning the user.
8.2. Background¶
What is Smart Fridge Alert?
Smart Fridge is a Fridge that has an extra sensor to help it determine the door close state, when the user forgets to close the door, it will warn the user to close it to reduce waste of energy and prevent food poisoning.
Smart Fridge Alert Principle
Firstly, we set the time counter variable as 0. When the door is closed, inside the fridge should be dark (light sensor value < 30), nothing happened;
When the door is opened, the room light will go into the fridge (light sensor value > 30), the counter will start counting the time every 1 second, if time counter > 60, the buzzer will be turned on to alert the user.
8.3. Part List¶
8.4. Assembly step¶
Step 1
In this case, “Big House Model” is used as a home base to start with.
Step 2
Let’s build a kitchen. Put Model E3 onto the Model A and B4, align with the holes at it. Put Model E1 onto the Model A, align with the holes at Model A and B3.
Step 3
Completed.
Step 4
To build a fridge, attach light sensor onto model G1 using M4 * 10mm screws and nuts. And the connecting wire could be bended to the hole below it.
Step 5
Fold and bend the Model G1 accordinglyand put Model G3 into the Model G1, align with the holes.
Step 6
Put Model G2 onto the Model G1, align with the holes.
Step 7
The fridge completed!
Step 8
Place the fridge at the corner.
Step 9
Assembly Completed!
8.5. Hardware connect¶
Connect the Light sensor to Pin P1
Pull down the Buzzer switch to connect buzzer
8.6. Programming (MakeCode)¶
Step 1. Initialize counter variable
On start, create a “counter” variable and set to 0
Step 2. Examine the light intensity
In
Forever
, put aif-else
statementUse
Get light value (percentage) at Pin P1 > 30
as condition
Step 3. Warning counter
In the
if
segment, that’s means the light intensity is strong, the door was openedAdd the counter with 1 by
change counter by 1
to sum up the time of door openedPut the second
if
statement withcounter >= 60
condition to examine when should issue warning soundIn the sencond
if
segment, putstart melody jump down repeating once
to issue the warning soundBack to the first
if-else
level, in theelse
segment, that’s means light intensity is weak, door was closed, so reset the counter to 0 byset counter to 0
Put a
pause (ms) 1000
to check the door each second
Full Solution
MakeCode: https://makecode.microbit.org/_YUbMtDiJJhWg
You could also download the program from the following website:
8.7. Results¶
When the door is opened for more than 1 minute, the buzzer will play some sound to warn the user.
8.8. Think¶
Apart from making the sound from the buzzer, another method to warn the user?
Can you make use of the fridge, to make a smart box to alert users?