8. Case 05: Smart Fridge Alert

Level: level auto_fit

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.

pic_100

8.3. Part List


pic_90

8.4. Assembly step


Step 1

In this case, “Big House Model” is used as a home base to start with.

pic

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.

pic

Step 3

Completed.

pic

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.

pic

Step 5

Fold and bend the Model G1 accordinglyand put Model G3 into the Model G1, align with the holes.

pic

Step 6

Put Model G2 onto the Model G1, align with the holes.

pic

Step 7

The fridge completed!

pic

Step 8

Place the fridge at the corner.

pic

Step 9

Assembly Completed! pic

8.5. Hardware connect


  1. Connect the Light sensor to Pin P1

  2. Pull down the Buzzer switch to connect buzzer

pic_90

8.6. Programming (MakeCode)


Step 1. Initialize counter variable

  • On start, create a “counter” variable and set to 0

auto_fit

auto_fit

Step 2. Examine the light intensity

  • In Forever, put a if-else statement

  • Use Get light value (percentage) at Pin P1 > 30 as condition auto_fit

Step 3. Warning counter

  • In the if segment, that’s means the light intensity is strong, the door was opened

  • Add the counter with 1 by change counter by 1 to sum up the time of door opened

  • Put the second if statement with counter >= 60 condition to examine when should issue warning sound

  • In the sencond if segment, put start melody jump down repeating once to issue the warning sound

  • Back to the first if-else level, in the else segment, that’s means light intensity is weak, door was closed, so reset the counter to 0 by set counter to 0

  • Put a pause (ms) 1000 to check the door each second auto_fit

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.

auto_fit

8.8. Think


  1. Apart from making the sound from the buzzer, another method to warn the user?

  2. Can you make use of the fridge, to make a smart box to alert users?