Example Code for MakeCode of Ultraviolet Light

Last revision 2026/01/27

This article provides an in-depth exploration of ultraviolet (UV) light, detailing its discovery, types, and effects on the human body. It highlights the advantages of UV rays, such as sterilization and vitamin D production, alongside the potential harms of overexposure, like skin and eye damage. The article introduces UV sensors, explaining their role in measuring UV intensity accurately. Through example code, it guides readers on measuring UV rays using MakeCode, emphasizing the importance of understanding UV exposure for health and safety.

Principle

1.What is UV? Where did it come from?
Ultraviolet light is the general term for radiation in the electromagnetic spectrum with wavelengths ranging from 10nm to 400nm, and our eyes cannot see ultraviolet light directly.

In 1801, German physicist Ritter discovered the presence of ultraviolet light by discovering the presence of ultraviolet light in a section of the purple-end section of the solar spectrum that can sense light from photographic negatives containing silver bromide, hereafter the ultraviolet light is discovered.

Divide according to wavelength, the ultraviolet light can be divided to near UVA, far UV UVB and ultra-short UV UVC. The penetration of ultraviolet rays in human skin is different. The shorter the wavelength of ultraviolet light, the greater the harm to human skin. Short-wave UV rays can pass through the leather, and medium-wave can enter the leather.

2.Advantages and disadvantages of ultraviolet rays to the human body
Advantages
Sterilization: A base cell in the human epidermis contains a tyrosine substance called melanin. Under the action of ultraviolet light, the "melanin" turns black, calming the surface of the sun-drenched skin, making the skin evenly black-brown. This is an important reason for sun-tanned skin. This pigment can absorb more light energy, and quickly transforms it into heat, and stimulates the secretion of the sweat glands to dissipate heat. Solar energy kills bacteria on the skin and prevents skin diseases such as scabies and folliculitis. More sunshine indoor, shining bed and cloth can reduce the spread of disease spreading.

Promotes calcium phosphorus metabolism substance containing sterols in human skin. This substance can be changed to vitamin D by ultraviolet radiation from sunlight. Vitamin D can improve the metabolism of calcium and phosphorus when it enters the bloodstream. It has the effect of anti-rickets, resist bone softening and osteoporosis in old age.

Enhance the body's immunity: Ultraviolet radiation in the sun can stimulate the body's hematopoietic function, so that the number of red blood cells increased, hemoglobin increased, improve red blood cell quality, improve muscle activity. It also can reduce blood pressure, blood sugar, cholesterol, increase the body's immune capacity, promote the body's cellular oxygen absorption capacity and metabolism, comfort asthma and joint pain, relax the muscles and stimulate the blood circulation, enhances physical fitness.

Disadvantages
Ultraviolet rays have a certain bactericidal effect, but excessive exposure to ultraviolet light is harmful to the human body.

  • Damage to the eyes: when exposed to ultraviolet light, the degree of eye injury is proportional to the time, inversely proportional to the distance from the source of the exposure, and is related to the angle of projection of light.
  • Damage to the skin: when UV rays strongly in the skin, it can lead to light dermatitis, red spots on the skin, itching, blisters, edema, eye pain, tears, etc. Severe skin cancer can also be caused.
  • Damage to the nervous central system: when UV light acts on the central nervous system, it may lead to headache, dizziness, elevated body temperature and other symptoms.

Preparation

Get to know ultraviolet sensor and its application
Moderate exposure to UV rays is good for the human body, but excessive exposure is harmful to the human body. So, we need to measure UV light to serve humans and avoid excessive UV rays harm.
Let's take a look at the device for UV measurement
The UV sensor shown below:

Ultraviolet sensor uses photosensitive elements to convert UV signals into electrical signals. It is only sensitive to ultraviolet light, insensitive to other lights like the usual sunlight, lamp light. So, we can measure the intensity of UV light more accurately.

Sample Code

With the knowledge of UV sensors, let's measure the intensity of UV rays by programming.

Measure

Measure the intensity of UV rays in different environments
First, we prepare a table like this:

We recorded data from tests at different locations and time, and tried measuring ambient temperature, light intensity at that time, and then tried to understand the relationship between temperature, light intensity and UV intensity by comparing and summarizing.

Conclusion

Through the learning above, we have learned the following:

  • Ultraviolet light is an electromagnetic wave.
  • Ultraviolet light can be sterilized.
  • Long-term excessive exposure to UV rays is harmful to the human body
  • Ultraviolet sensors can accurately detect ultraviolet rays, but are not sensitive to ordinary light.
  • Mastered the method of measuring ultraviolet rays through programming, and made comparison and summary.

Was this article helpful?

TOP