Outline
Make a refrigerator light: open the door, then it can light up automatically; close the door, the it will go off automatically.
Suitable kits: mCookie102, mCookie202, mCookie302, IBC
Module Bill
Module
Other Equipment
- USB cable*1
- Sensor cable*1
- Lego shell*1
- Lego or other fixation structure
Module Setup
- Assemble the modules and sensors:
- Stick the red core module, USB upload module and green extension module together;
- Connect the crash button to pin 6/7 of Hub;
- Connect the red LED to pin 4/5 of Hub;
- Insert one end of USB cable into the USB upload module, and connect the other end to computer;
Programming
Programming Thought
When the door is open, the crash button isn’t squeezed (in release state) by it, LED is on; when the door is closed, the crash button is squeezed (in press state) by it, LED is off.
Start to Program
1. Open the door, and the crash button is “released”, then the LED is activated.
Change the pin of crash button into 6, and the state into released; change the digital output pin into 4, and set the state to high.
2. Close the door, and the crash button is “pressed”, the LED will go off.
Change the state of the crash button into 6, and set the state to press; change the digital output number into 6, and the set the state to low.
Test the result
After upload, when the crash button keeps pressed, the LED keeps off(representing the door is closed). When the crash button keeps free, the LED keeps on all the time(representing the door is open).
- Q: Sometimes, I would forget to close the door, all things in the refrigerator will go melted, is there some way to alarm me?
- A: you can add an alarming function, if the door is open for a certain period of time, it will produce alarming sound. For that, you can add a “timing” function. If the door hasn’t been closed for a period of time, the buzzer will ring to alarm!
Required Program Blocks
Programming Thought
Judge whether the crash button is released. If it isn’t( the door is closed), turn the LED off; if it is (the door is open), turn the LED on, and active the buzzer when the door has been open for a certain period of time.
Start to Program
1. When the door is open, the crash button 6 is free, turn the LED on.
2. When it is overtime, the buzzer starts to alarm.
Define the timer timer1. Start to time. When the crash button is released, repeat executing the internal program (judge whether the timing time of timer 1 is over 4000ms, if it is, active the buzzer to alarm), until the crash button is pressed( close the door).
3. After the door was closed, the LED and buzzer go off.
Test the result
After upload the program, release the crash button, after 4s, check whether the buzzer alarms.
Technical Specification
- The product number of crash button: MSDS11
- Digital signal input sensor.
- For details, please refer to Sensor-Crash.
Related Cases
FAQ
|