Measuring the UVA UVB

We all love the sun and of course we know about the dangers of ultraviolet radiation for human skin. Obviously, you cannot sunbathe on the beach for a long time. But it’s not at all obvious, is it possible to walk in the T-shirt under the sun, and swim, walk in the mountains? After another “burning” from the sun in the mountains in Krasnaya Polyana, the question arose - how to measure the instant index of ultraviolet radiation and know when it is time to hide in the shade. As a result, this small device was born - a UV radiation sensor with a number of additional functions.



What should the device be able to


The main function is to measure the UV radiation index. In addition, I wanted to measure the air temperature and the water temperature, with an accuracy of at least 0.5 degrees (especially when I took a dip in the pool with ice water and looked at a Chinese thermometer that was swimming there - 28 degrees, and was not around). And of course, battery power.

Main components: VEML6075 + MCP3421 + STM8


There are not many sensors for measuring the UV index. A commonly used UV probe is a phototransistor. But it turned out to be quite difficult to calibrate. The choice fell on the digital sensor - VEML6075. He turned out to be very good. The only negative is that it’s difficult to buy, delivery had to wait about a month through official channels - “The Fifth Element” (China did not consider it - it’s unpleasant to guess quality in a one-time device). Sensor Advantages:

  • easy calibration at home
  • cosine response of the sensor surface - accounting for the incidence of rays
  • accurate index readings in two ranges - UVA UVB
  • low consumption
  • I2C communication - fully digital sensor


Initially, the sensor size was scary 2x2 mm, there was no hot air gun, I thought it would be difficult to solder such a trifle with an ordinary soldering iron - but it turned out fine.


The second question - the measurement of water temperature, decided with a thermocouple. For accurate data reading from this sensor, use a very accurate ADC, with an integrated reference voltage source - MCP3421. 18-bit resolution + 8x signal amplification for a K-type thermocouple gives 0.01 degree temperature resolution - more than enough. Given the need to measure the temperature of the compound, the accuracy was in the region of 0.2 degrees. Checked by measuring boiling water and ice.

As the microcontroller - the simplest and cheapest option - STM8S003F3. Everything is on board - timers, I2C - needed for the sensor, etc.

Since the device should work in the sun, an LCD screen is used as an indicator. I wanted compactness - I chose this one:


With management had to torment. Multiplexing the LCD pins on a conventional microcontroller is still that task, but in general everything turned out fine.

The case chose a small, compact from the company Sanhe model "20-31". External size - 35x45x18 mm. Everything fit - the board, indicator and battery.

I will not give the circuit and board, everything is on github

UV Sensor Calibration


After receiving readings from the sensor - they were not very pleased, they were not similar to the readings of the "hydro-center". I had to learn how to properly calibrate the sensor.

In order to correctly calculate the UV radiation index according to the sensor readings, it is necessary to use several constants. How to calculate them without special equipment? Here is the full formula for calculating the index: The

constants k1 and k2 cannot be calculated without equipment. But they are necessary for the most accurate calculation, so that they can be taken as a unit. The sensitivity constants of the sensor can be taken from the table:

We need the constants from the first line, since the sensor is not covered by Teflon (we could not buy optical Teflon, so the sensor is finally open). UVAresp and UVBresp. But the constants a, b, c, d must be calculated. I did this with a debugger. It is necessary to obtain the data uva, uvb, uvcomp1, uvcomp2, and calculate the constants in Excel. It is inconvenient to display them on the display - there are too few digits. This is where the debugger is needed. Set a breakpoint after receiving the data and see the calculated values. You can also use the ability to disconnect ST-link from STM8 during debugging and reverse connection. In this case, the debugging session is not interrupted! Another option is to use STM8 STUDIO. This special program allows you to get variables at any given time.

To calculate the constants without special equipment, let's use this (this is described in the application note to the sensor). Sunlight in its spectrum has UV radiation, IR radiation and visible radiation. To calculate the intensity of UV radiation, it is necessary to subtract the excess data about IR radiation and visible radiation. To do this, use the data uvcomp1 (responsible for visible radiation) and uvcomp2 (responsible for IR radiation).

To calculate the constants in the formula used, two artificial light sources are needed:
• an ordinary incandescent lamp - it emits in the IR spectrum and visible radiation, there is no UV radiation
• LED lamp - it emits only in visible radiation, there is no UV and IR radiation
We start with the LED lamp. Since there is no UV radiation, the corresponding index will be zero.

The LED lamp does not have IR radiation, so UVcomp2 will be 0. And in this case, you can find the coefficients

Having these coefficients, it is not difficult to find the coefficients b and d when using a conventional lamp, when UVcomp2 is not equal to zero.


Using this simple method you can get the necessary constants. Such calibration should be carried out in the evening when there is no sunlight and other light sources.
A correctly calibrated sensor is very easy to check. On a sunny day, at noon, when there are no clouds in the sky, you need to measure the intensity by pointing the sensor exactly at the sun. The readings must match the transmitted data on the weather sites.

When tanning, to accurately measure radiation, the sensor must be kept parallel to the surface of the body. To obtain the maximum current index, the sensor must be directed to the sun.

The sensor began to show the best results with the maximum data averaging time (the sensor has the ability to set this parameter - the time during which it itself averages the indicators) - 800ms.

In order to make the readings absolutely perfect, we also had to follow the developer's recommendations - to paint the board black so that it would not reflect and surround the sensor with a black funnel.

Use experience


I’ll say right away about consumption - it is extremely small, it is about 2 mA when all sensors and the microcontroller are working. With infrequent use, the battery lasts for about 3 months on a single charge.

I consider the accuracy of the readings to be very high. I checked in several regions (Moscow, Sochi, Crimea) - the readings coincide at noon with weather sites. Therefore, I believe that in cloudy weather he can also be trusted.

In the manufacture of the sensor, I had to study what UV radiation is, and how it is still harmful. What kinds of it are. How does it affect the skin. How does the position of the sun on the horizon and whether UV radiation is harmful to the eyes.

Personally, I checked all the articles about “burning” on myself. The sensor proved to be excellent. Now, having seen index 13 on the sensor in the mountains, I put on a tight shirt and cover all parts of the body. And in the evening, when index 5 - I walk calmly and bask under the warm rays of the sun.

I learned that on a sunny day, you can get a good sunburn in Moscow - the index reaches 9 at noon. And also, that when swimming, the time spent in the sun doubles.
For me, this device was very useful, I still use it, the whole family trusts the testimony.

At the moment, he added a very accurate humidity sensor - HTS221. It also works on I2C, so I just made a mini-board and pasted it inside. Soldered with a varnished wire 0.15mm. So, now it also shows humidity, much more accurately than Chinese meters sold on the market.

I’ll write a little about the big fat minus - according to the recommendations of the developer, it is better to close the sensor with optical Teflon to isolate the sensor from dust and dirt. It did not work to find such teflon in the rail, so the sensor becomes dusty and sometimes I wipe it with a cotton swab.

All Articles