11. Case 08: Automatic Sunlight Detecting Curtain

Level: level

auto_fit

11.1. Goal


Make a smart curtain that operates automatically by detecting the sunlight around the house to save energy.

11.2. Background


What is Automatic Sunlight Detecting Curtain

Automatic Sunlight Detecting Curtain is a curtain that scrolls up or down automatically according to the detection of sunlight.

Automatic Sunlight Detecting Curtain Principle

The light sensor is installed outside of the house. When it detects strong light (Light > 70), it indicates that there is sunlight that can reach the house. The curtain in this case should scroll down to prevent heat energy transfer into the house. It can reduce energy loss and can save the energy of air conditioner.

pic_100

11.3. Key knowledge


In programming part, there is a “flag” concept to be used in this case. It can check whether the curtain is pulled down or not and prevent from keeping pull down the curtain.

11.4. Part List


pic_90

11.5. Assembly step


Step 1

In this case, build the “Big Style Model” as a home base.

auto_fit

Step 2

To make a curtain. Attach the curtain rod to 360ᵒ servo by using the screwdriver to assist.

pic_90

Step 3

Cut the curtain paper into a 8cm*8cm square.

pic_90

Step 4

Stick the cutted paper on the curtain rod by glue.

pic_90

Step 5

Shape the blu tack into a recteangle by hand.

pic_90

Step 6

Stick the shaped blu tack at the bottom of the paper curtain.

pic_90

Step 7

Attach the completed curtain (servo) onto Model B1 using M2 * 10mm screws and nuts.

pic_90

Step 8

Close the house by model C1 and C2.

pic_90

Step 9

Attach the light sensor onto model C2 using M4 * 10mm screws and nuts.

pic_90

Step 10

Assembly Completed!

pic_90

11.6. Hardware connect


  1. Connect the light sensor to P1

  2. Connect the 360 degree servo to P2 pic_80

11.7. Programming (MakeCode)


Step 1. Initialize OLED and create the variable

  • On start, initialize the OLED display by initialize OLED with width 128 height 64

  • Create the curtainOn variable and set it to false

auto_fit

Step 2. Create curtain control function “openCurtain”

  • Create function openCurtain

  • Inside the function, control the speed and direction of the 360 degree servo at connected pins, such as Turn 360 Servo with clockwise direction speed level 3 at P2

  • Add pause to wait it rotate for few second (depend on your model setup)

  • Stop the 360 servo with same method, such as Turn 360 Servo with clockwise direction speed level 0 at P2

  • set the curtainOn variable to true

auto_fit

Step 3. Create curtain control function “closeCurtain”

  • Create function closeCurtain

  • Inside the function, following the previous function, but in reversed direction and state

  • control the speed and direction of the 360 degree servo at connected pins, such as Turn 360 Servo with anti-clockwise direction speed level 3 at P2

  • Add pause to wait it rotate for few second (depend on your model setup)

  • Stop the 360 servo with same method, such as Turn 360 Servo with anti-clockwise direction speed level 0 at P2

  • set the curtainOn variable to false auto_fit

Step 4. Get the light intensity value

  • In Forever, reading the value by set light to Get light value (percentage) at Pin P1

  • Clear the OLED display before each update by clear OLED display

  • Show the number of value on display by show number light

auto_fit

Step 5. Examine the light intensity value and reaction

  • Snap a nested if statement to Forever

  • Set light2 >= 70 and curtainOn =  true as first condition

  • In the if segment, that’s means the sunlight is strong, need to close the curtain, call closeCurtain

  • In the second condition, use light2 < 40 and curtainOn = false

  • In the second if segment, that’s means the sunlight is weak, need to open the curtain, call openCurtain

auto_fit

Full Solution

MakeCode: https://makecode.microbit.org/_6sm7bVe3AP2T

You could also download the program from the following website:

11.8. Result


When the light sensor detects the light value outside the house is strong, the servo will rotate to scroll down the curtain. When the light is not strong, the servo will rotate in anti direction to scroll up the curtain

auto_fit

11.9. Think


Q1. Apart from the sunlight value, any other condition can be used to determine the curtain state?