3. Case 02: UV Light Detection Device#

3.1. Introduction#


  • The most direct effect of excessive ultraviolet radiation is the gradual darkening of the skin. This is because ultraviolet rays cause a large amount of melanin to deposit in the epidermis, leading to permanent blackening, and the marks are not easy to fade; it will accelerate skin aging over time, about 90% of human skin aging is due to ultraviolet rays. Thus we can make a UV detection device for reminding.

3.2. Function#


  • Detect the UV light intensity with the UV sensor, if the intensity is strong, program to drive the servo to lift the parasol.

3.4. Picture#


../../_images/microbit-Smart-Health-Kit-case-01-02.png

3.5. Hardware Connection#


Connect the UV sensor to P1 and the servo to P2 on sensor:bit.

../../_images/microbit-Smart-Health-Kit-case-02-03.png

3.6. Software Programming#


Click “Advanced” in the MakeCode to see more choices.

../../_images/microbit-Smart-Health-Kit-case-01-04.png

For programming, we need to add a package: click “Extensions” at the bottom of the MakeCode drawer and search with “smarthome” in the dialogue box to download it.

../../_images/microbit-Smart-Health-Kit-case-01-05.png

For programming, we need to add a package: click “Extensions” at the bottom of the MakeCode drawer and search with “servo” in the dialogue box to download it.

../../_images/microbit-Smart-Health-Kit-case-01-06.png

Notice: If you met a tip indicating that some codebases would be deleted due to incompatibility, you may continue as the tips say or create a new project in the menu.

3.7. Program#


Save the value detected from the UV sensor connecting to P1 as the variable “UV” and display the value on the micro:bit.

../../_images/microbit-Smart-Health-Kit-case-02-07.png

Judge if the variable is over 5, if yes, set the servo connecting to P2 to drive to 0°; or to drive to 90°.

../../_images/microbit-Smart-Health-Kit-case-02-08.png

Link: https://makecode.microbit.org/_exdb9fFJjeuj

3.8. Result#


  • If the intensity of the UV light is strong, program to lift the parasol.