Overview
Make an automatic window, when the humidity arrives a certain level, the servo will be controlled to close the window automatically. And it can also be controlled by two Line Finders.
Suitable kits: mCookie302
Module List
Module
Other Equipment
- USB cable*1
- Sensor cable*4
- Sensor shell
- Lego or other fixation structures
Module Setup
Setup
- Assemble modules and sensors together:
- Stick the red core module, battery base and green extension module together;
- Connect the servo to pin 6/7 of Hub;
- Connect the servo to pin 1 of the servo connector (the lower three pins);
- Connect the Line Finder to pin A0/A1 and A2/A3 of Hub;
- Connect the Tem&Hum sensor to IIC pin of Hub;
- Plug one end of the USB cable into the battery base, and connect the other end to the computer;
Programming
Required Program Blocks
Programming Thought
When the humidity is larger than 80% or the Line Finder controlling to close the window has induced the approach of hand, the servo will be controlled to open the door automatically.
Start to Program
1. Read the distance values of the two Line Finders and the humidity value and store them.
Variable open is for storing the value of the Line Finder controlling to close the window.
Variable close is for storing the value of the Line Finder controlling to open the window.
Variable hum is for storing the humidity value of the Tem&Hum sensor.
Store the distance value of pin A0 in variable open. Store the distance value of pin A2 in variable close. Store the humidity value in variable hum.
2. Control to close the window
If the distance of the sensor controlling to close the window is less than 150 or the humidity value id larger than 80, the window will be closed slowly.
3. Control to open the window
If the distance of the sensor controlling to open the window is less than 150, the window will be opened slowly.
Test the result
After upload, approach your hand to the Line Finder of pin A0, the servo will spin to 40 degrees to open the window; approach your hand to the Line Finder of pin A2, the servo will spin to 140 degrees to close the window. Blow to the Tem&Hum sensor, the humidity will increase, when it is higher than 80%, the servo will also close the window.
Start the power supply, control the servo to close the window with the sensor to close the window, then switch the power supply off, at this time, use iron wire to fix the window and servo arm, so that the action of servo and that of the window can be synchronized.
Q: The current window can be closed automatically when it is raining through detecting the humidity value, how to make it can be closed automatically when the temperature is high as well?
A: The Tem&Hum sensor can also detect the temperature, so we just need to judge the current temperature as well.
Add a temperature value to implement the function of closing the window when it is hot.
Variable temp is for storing the temperature value of the Tem&Hum sensor.
If the distance value of the sensor controlling to close the window is less than 150, or the humidity value is larger than 80, or the temperature value is larger than 30, the window will be closed.
Technical Specification
Relative Cases
FAQ
|