Outline
Make a refrigerator light: when the door is open, the light can be turned on automatically; when close the door, it can be turned off automatically.
Suitable kits: mCookie102, mCookie202, mCookie302, IBC
Module List
Module
Other Equipment
- USB cable*1
- Sensor cable*1
- Sensor shell*1
- Lego or other fixation structure
Module Setup
- Assemble the modules and sensors together:
- Stick the red core module, USB upload module and green extension module together;
- Connect the crash sensor to pin 6/7 of Hub;
- Connect the LED to pin 4/5 of Hub;
- Insert one end of USB cable into USB upload modules and connect the other to computer;
Programming
Programming Thought
When the refrigerator door is open, the crash hasn’t been squeezed by the door(the state is release), the LED is on; when the door is closed, the crash is squeezed by the door(the state is press), the LED is off.
Programming
1. When open the door, the crash sensor is “release”, and the LED is turned on
Change the pin of crash sensor into 6, the state into release; change the digital signal pin into 4, the state into high;
2. When close the door, the crash is “press”, and the LED is turned off
Change the crash sensor pin into 6, and the state into press; change the digital output pin into 4, and the state into low;
Test the result
After the upload of the program, the crash sensor is keeping pressed down, the LED is off all the time(representing the door is closed); when the crash is released, the LED keeps on(representing the door is open).
- Q: Sometimes, I forget close the door, all the things in the refrigerator will melt, is there any way to remind me?
- A:You can add a reminder function. If the door has been open for a period of time, it will produce alarming sound automatically. And you also need to add a “delay”. If over a certain time, you haven’t shut the door, the buzzer will start to alarm!
Required Program Blocks
Programming Thought
Judge whether the crash has been released. If the state of it is press(the door is closed), turn the light and the buzzer off; if the state is release(the door is open), turn the light on, and after a timeout, the buzzer alarms.
Programming
1. If the door is open, crash 6 is released, the LED will light up.
2、When it is timeout after the door is open, the buzzer will alarm.
Define the timer1, start timing, after the crash is released, repeat executing the internal program (judge whether the time of “timer1”exceeds 4000, if it is, the buzzer will alarm), not until the crash is pressed(close the door) does it end.
3. After close the door, the LED and the buzzer go off.
Test the result
After upload the program, release the crash sensor, after above 4s, see whether the buzzer will alarm?
Technical Specification
- The product number of crash sensor is: MSDS11
- Digital signal inputting sensor.
- For details, please refer to Sensor-Crash.
Related Cases
FAQ
|