Hello friends, I hope you all are doing great. Today, I am going to share the UV Index and Sunburn Timer with ML8511 and ESP32 - Proteus Simulation, the eighty-first project of our IoT Projects series. If you have searched for an ML8511 UV sensor with an ESP32, how the UV index is worked out, how long you can stay in the sun before you burn, or a UV meter in a Proteus simulation, here is a complete one. A sunburn does not hurt while it happens: the redness comes hours later, when the damage is already done. So the only useful warning is one that comes before it, from something that counts the UV your skin has taken.
This ESP32 reads an ML8511, a small sensor for UV-A and UV-B, works out the UV index, and while you are out in the sun it adds up the UV dose your skin receives, weighted the way skin burns and divided by your sunscreen's SPF. From that it tells you how long you have left before you burn for your skin type, beeps when you have taken half of your burn dose, reminds you to reapply sunscreen after two hours, and tells you to get out of the sun at 80 %. A ring of 12 WS2812B LEDs is a UV index gauge in the official colours, an OLED shows the numbers, and a dashboard shows them on a laptop or a phone. In this tutorial, we will go through the circuit, the UV index and the dose, skin types and SPF, reading an analog sensor against its own reference, and the timer's logic. Then we spend a summer day at the beach in the simulation. At the end, you can download the project with the sketch and every library file.
NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the UV index and sunburn timer with ML8511 and ESP32 in Proteus simulation:
What Does This Sunburn Timer Do?
- Measures the UV: an ML8511 on an analog input, read against the module's own 3.3 V for accuracy.
- Shows the UV index: on the OLED and on a ring of 12 LEDs, one LED per index step in the band's colour: green, yellow, orange, red, violet.
- Counts your dose: the sunburn-weighted UV your skin has taken since you went out, in SED and as a share of your burn dose.
- Knows your skin and your sunscreen: six skin types, and SPF 30 counted in full for two hours, then at half until you reapply.
- Counts down: how long you have left before you burn, at the UV of right now.
- Warns in time: beeps at 50 % (sunscreen and shade), a reminder to reapply, and an alarm at 80 % (get out of the sun).
- Reports everything: a dashboard on the laptop and the phone, with OUT/IN, SPF 30, SKIN and NEW DAY links.
It is a great project for learning analog sensors, ratiometric measurement, integration over time and a little photobiology. In the simulation, the ML8511's pop-up shows a summer day passing, with the sun on its arc, a cloud after noon and the UV through the day, so each reading of the ESP32 can be checked against the sky.
Components Used in the Proteus Simulation
All the parts come from our Proteus libraries, each with its own tutorial. The project zip at the end includes every LIB and DLL file.
| Part | Proteus device | Library post | Connection |
|---|---|---|---|
| ESP32 DevKit V1 | ESP32 DEVKIT V1 | ESP32 DevKit V1 Library for Proteus | U1, ESP32_Sunburn_Timer.hex, Wi-Fi 192.168.1.101 |
| ML8511 UV sensor | ML8511TEP | ML8511 UV Sensor Library for Proteus | U2, OUT on D34, EN on its own 3V3, VIN on VCC |
| Resistors | RESISTOR4BANDTEP | Resistor Library for Proteus | R1 / R2 10k: the module's 3V3 halved to D35; R3 100 ohm |
| WS2812B ring of 12 | WS2812RING12ADVTEP | WS2812B NeoPixel Library for Proteus | NEO1, DIN on D13: the UV index gauge |
| Passive buzzer | BUZZERPASSIVETEP | Passive Buzzer Library for Proteus | BZ1 on D33 through R3 |
| OLED SSD1306 128x64 | OLED12864WHITEADVTEP | OLED SSD1306 Library for Proteus | OLED1 on I2C, 0x3C |
| Laptop WiFi Monitor | LAPTOP WIFI MONITOR | Laptop WiFi Monitor | PC1 |
| Mobile WiFi Monitor | MOBILE WIFI MONITOR | Mobile WiFi Monitor | MOB1 |
Proteus Simulation of the Sunburn Timer: the Circuit
| Part pin | ESP32 | Signal |
|---|---|---|
| ML8511 OUT | D34 | the UV voltage, 0.99 to 3.0 V |
| ML8511 3V3 through R1 / R2 (10k / 10k) | D35 | REF: half the module's 3.3 V, 1.65 V |
| ML8511 EN | (the module's own 3V3) | high = measuring, always on |
| ML8511 VIN / GND | VIN (5 V) / GND | the module's regulator makes 3.3 V |
| WS2812B ring DIN / 5V / GND | D13 / VIN (5 V) / GND | one data line for all 12 LEDs |
| Passive buzzer | D33 | tone() through 100 ohm |
| OLED SDA / SCL | D21 / D22 | I2C at 0x3C |
D34 and D35 are input-only pins of the ESP32 on its first ADC, the usual choice for analog sensors. The divider R1 / R2 is the one unusual part: it is explained below.
How the Sunburn Timer Works
The UV Index
Sunburn is caused mostly by UV-B (280 to 315 nm), with some help from UV-A (315 to 400 nm). Skin is far more sensitive to the short wavelengths: the erythema action spectrum, the official curve of how strongly each wavelength reddens skin, falls by about a thousand times from 300 to 330 nm. The UV index takes the sun's UV spectrum, weights it with that curve, adds it up into an erythemally weighted irradiance in W/m2, and multiplies by 40. So the UV index is simply the burning power of the sunlight: UVI 1 means 0.025 W/m2 of weighted UV. Worked example: on a clear summer noon at mid-latitudes the index reaches about 8 to 10, which is 0.2 to 0.25 W/m2 of weighted UV. The World Health Organization reports it in five bands with fixed colours: 0 to 2 low (green), 3 to 5 moderate (yellow), 6 to 7 high (orange), 8 to 10 very high (red), 11 and above extreme (violet).
The Dose: SED and the Burn Dose
A burn depends on the total dose, not on the moment: weighted irradiance times time, in J/m2. Each second, the skin takes UVI / 40 J/m2. The standard unit is the SED, the standard erythema dose: 100 J/m2. The dose that just reddens your skin is the minimal erythema dose (MED), and it depends on the skin type. The Fitzpatrick scale has six types; typical burn doses are about 200 J/m2 for type I (very fair, always burns), 250 for type II (fair, burns easily), 300 for type III, 450 for type IV, 600 for type V and 1000 for type VI (very dark, rarely burns). Real values vary from person to person, so these are a guide, not a promise. Worked example: skin type II at UV index 8 takes 8 / 40 = 0.2 J/m2 each second, so it reaches its 250 J/m2 in 250 / 0.2 = 1250 seconds: about 21 minutes. A clear summer day gives about 50 SED in total, the burn dose of type II twenty times over.
Sunscreen and SPF
The sun protection factor is measured in a lab: with the sunscreen, skin needs SPF times more UV to redden. So SPF 30 lets through one thirtieth of the burning UV, and in theory stretches the 21 minutes of the example to over ten hours. In practice people apply a quarter to a half of the test amount, and sunscreen is rubbed, sweated and washed off. That is why the advice is to reapply every two hours and after swimming. The sketch models it simply: full SPF for two hours after it goes on, half of it after that until you reapply, and a reminder at the two-hour mark.
The ML8511 Sensor
The ML8511 is a photodiode sensitive from about 280 to 390 nm, UV-A and UV-B, with an amplifier that turns the photocurrent into a voltage. Its output is about 0.99 V in the dark and rises in a straight line to about 2.8 V at 15 mW/cm2 of UV. So the UV intensity is (VOUT - 0.99) x 15 / (2.8 - 0.99) mW/cm2. Worked example: 1.774 V gives (1.774 - 0.99) x 15 / 1.81 = 6.50 mW/cm2. The sensor does not have the skin's spectral response, so the UV index is only an estimate from the intensity: for sunlight about 1.7 per mW/cm2, which makes the 6.50 mW/cm2 an index of 11. That rule holds for the sun's spectrum, not for a UV lamp. The module has a 3.3 V regulator and an EN pin: low puts the sensor in standby at 0.1 uA.
Reading Against the Module's Own 3.3 V
The ML8511 gives about 0.12 V per mW/cm2, so an error of a few tens of millivolts is already a big part of the reading. An ADC measures against its own reference, and that reference is never exact. The cure is a ratiometric measurement: read a voltage you know with the same ADC, and divide. The module's regulator gives a precise 3.3 V, but the ESP32's ADC tops out at 3.3 V, so that voltage itself would read at full scale and clip. A 10k / 10k divider halves it to 1.65 V on D35. Then VOUT = 3.3 x A(OUT) / (2 x A(REF)), and the ADC's own reference cancels out. Worked example: A(OUT) 2201 and A(REF) 2048 give 3.3 x 2201 / 4096 = 1.773 V. The sketch also averages 16 readings of each. EN is tied to the module's own 3.3 V, so the sensor is always measuring.
The Timer and the Alerts
Twice a second, the sketch reads the UV index and, while you are out, adds UVI / 40 / SPF times the elapsed time to your dose. The time left before you burn is the rest of your burn dose divided by the dose rate of right now: (burn dose - dose) / (UVI / 40 / SPF). It is a countdown that changes with the sun: it speeds up towards noon and slows down under a cloud. Indoors, the timer shows how long bare skin would last outside right now. At 50 % of the burn dose the buzzer beeps twice (sunscreen and shade), at the two-hour mark it reminds you to reapply, at 80 % it chirps every two seconds until you go in, and at 100 % it gives a long tone.
A Summer Day in 24 Minutes
A real day is long to wait for. The ML8511 model runs a summer day by its PROFILE DAY: the sun rises at 06:00, its UV peaks at noon (PEAK 6.5 mW/cm2) and sets at 18:00, with a cloud from 12:30 to 13:30 that lets 45 % through, and its SPEED of 300 makes each simulated second five minutes of the day. The sketch has the same constant, TIME_SCALE 300: it counts its clock and the dose at the sun's pace, so the whole day takes 144 simulated seconds. On a real station, TIME_SCALE is 1 and the clock comes from the internet.
The Arduino Code Explained
The sketch is ESP32_Sunburn_Timer.ino, built for our ESP32 DevKit V1 with the WiFi, WebServer, Wire and Adafruit SSD1306 libraries. The constants that matter:
const float TIME_SCALE = 300; // the day's pace: U2's SPEED (300 = 5 minutes a second); 1 for real
const int MED[6] = {200, 250, 300, 450, 600, 1000}; // the burn dose, J/m2 (sunburn-weighted), skin types I - VI
A reading: 16 readings of OUT and of REF, and the ratio:
return 3.3 * a / (2.0 * r); // the divider halves the module's 3.3 V
The maker's line and the UV index:
mw = max(0.0f, (v - V_DARK) * MW_FULL / (V_FULL - V_DARK)); // the maker's line
The dose, through the sunscreen:
const float e = uvi / 40; // the sunburn-weighted irradiance, W/m2
dose += e / protection() * dt;
The sunscreen rule:
return (hours() - spfAt) * 3600 < REAPPLY_S ? SPF : SPF / 2.0;
The countdown:
const float rate = uvi / 40 / (out ? protection() : 1); // J/m2 a second (not out: what bare skin would take)
Two of the alerts:
if (!half && f >= 0.5) { half = true; event(F("HALF your burn dose: put on sunscreen and find shade")); draw(); beeps(2, 1500); }
if (!warned && f >= 0.8) { warned = true; event(F("WARNING 80 % of your burn dose: get out of the sun")); draw(); }
The gauge: LED k lights when the rounded index reaches k, in the colour of k's band:
for (int k = 0; k < LEDS; k++) ring.setPixelColor(k, k + 1 <= r ? bandColour(k + 1) : 0);
The OLED shows the UV index large, its band, the clock, OUT or IN with the skin type and the SPF, the dose bar and the timer or the alert, and each alert redraws it at once. The dashboard's links go to /out, /spf, /skin and /new, and /data gives everything as JSON.
How to Run the Proteus Simulation
- Download the project zip below and install the library files (the steps are under the download button).
- Open ESP32-Sunburn-Timer.pdsprj from the Proteus Simulation folder. Keep the HEX and the DLL files next to it.
- Press Play. The day starts at 06:00 and the UV index climbs through the morning.
- Open the Laptop WiFi Monitor and press Go. Click OUT/IN when you go out, SPF 30 when the sunscreen goes on.
- Click U2 for the sensor's pop-up: the sky, the UV through the day, and the Cloud and Shade chips.
Simulation Results: a Summer Day in Proteus
We spent a summer day at the beach in the simulation: the morning indoors, a walk out at 08:00 without sunscreen, the sunscreen when the timer asked for it, a second coat after two hours, and indoors at the warning. The times below are the sketch's day clock; the whole day, from 06:00 to 13:10, took 86 simulated seconds.
The Morning Indoors
At 06:00 the sensor gave 0.990 V, no UV. The sun rose and the index climbed: 1.0 at 07:00 (OUT 1.061 V, 0.59 mW/cm2) and 3.2 at 08:00 (1.220 V, 1.91 mW/cm2). The model's sun at 08:00 is 6.5 x sin(30 degrees)^1.8 = 1.87 mW/cm2, so the ESP32's reading through the ratiometric method matched it within 2 %. Indoors, the OLED showed how long bare skin of type II would last outside: 1:28 at 07:30, only 0:51 at 08:00.
Out Without Sunscreen
At 08:05 we clicked OUT/IN: out in the sun, skin type II, no sunscreen. The timer started at 0:49. At UV index 3.8 the dose bar reached 21 % by 08:14, and at 08:26 it passed half the burn dose: two beeps and PUT ON SUNSCREEN! on the OLED. Twenty-one minutes in the morning sun had used half of what fair skin can take.
Sunscreen, and a Second Coat
At 08:30 we clicked SPF 30: the dose stood at 61 % and the timer jumped from minutes to 7:07. Through the morning the index rose to 6.0 at 09:00 and 8.6 at 10:00, yet the dose crept only from 61 % to 73 %. At 10:32, two hours after the sunscreen went on, the timer beeped three times: REAPPLY. Counted at half its SPF, the time left fell to 0:55 at UV index 9.6. We reapplied at 10:36.
The Warning: Get Out of the Sun
Even with SPF 30, the late-morning sun kept adding to the dose, and at 10:41 it reached 80 %: WARNING, a chirp every two seconds and GET OUT OF THE SUN! on the OLED. The gauge showed 10 LEDs, two green, three yellow, two orange and three red: UV index 9.9, very high. We clicked OUT/IN at 10:44 and the sketch printed the summary: out from 08:05 to 10:44, skin type II, a dose of 2.02 SED = 81 % of the burn dose, while the open sky had given 19.0 SED since 06:00. The skin stayed under its burn dose.
Noon and the Cloud
Indoors, the station kept measuring. At noon the index reached 11.1 (6.50 mW/cm2, extreme) with 11 LEDs lit into the violet, and the bare-skin timer, with only 19 % of the burn dose left, read 0:02. Then the cloud came over: 4.9 at 12:30 and 4.7 at 13:00, and the gauge dropped back to two green and three yellow LEDs.
Every alert came in the right order and at the right dose, and the numbers matched the dose sums worked out before the run.
Download the Project Files
Click the button below to download UV-Index-Sunburn-Timer-ML8511-ESP32-Proteus-Simulation-v1.0.zip (about 4.6 MB, without the source code of the models):
UV Index and Sunburn Timer with ML8511 and ESP32 - Proteus Simulation V1.0- Proteus Simulation: ESP32-Sunburn-Timer.pdsprj, ESP32_Sunburn_Timer.hex and copies of the models.
- Arduino Code: ESP32_Sunburn_Timer.ino, the sketch.
- Proteus Library Files: the LIB files of every part.
- Proteus Model Files: the DLL models.
- README.txt: the installation steps, the properties, the test results and the links to every library post.
No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.
How to Install the Project Files
- Close Proteus and extract the whole zip file, for example to your Desktop.
- Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
- Copy the files from Proteus Model Files into the MODELS folder.
- Start Proteus and open the project from the Proteus Simulation folder.
Changing the Code
Open the sketch in the Arduino IDE with the TEP Boards for Proteus installed, select ESP32 Dev Module (TEP Proteus), and use Sketch > Export Compiled Binary. Put the new HEX next to the project. The skin type at the start, the burn doses, the SPF, the reapply time, the alert levels and TIME_SCALE are near the top of the sketch.
Ideas to Extend the Project
- Make it wearable: an ESP32 with a battery and the sensor on a clip, so the dose follows you into the shade.
- Take the clock from NTP and log the UV index all day to a web chart.
- Add a button for "just swam": sunscreen comes off in water, so restart the reapply countdown.
- Keep a dose per family member, each with a skin type, on one station.
- Move EN to a GPIO and put the sensor in standby (0.1 uA) at night, for a battery station.
- Send the 80 % alert to a phone as a push message instead of only a beep.
- Use a sensor with the erythema response, such as a UV-B or a dedicated UV index sensor, for a true index.
From Simulation to Real Hardware
- Set TIME_SCALE to 1: the real sun runs at real speed; and take the clock from NTP.
- Calibrate the ADC: a real ESP32's ADC is not linear near its ends; analogReadMilliVolts() gives calibrated readings, and the ratiometric method still helps.
- Give the sensor a clear view: glass and most plastics block UV-B; use a PTFE or quartz window, or none.
- Point it at the sky: the reading depends on the angle; a flat, upward sensor matches how the UV index is defined.
- Treat the index as an estimate: the ML8511 does not see UV the way skin does; for sunlight the estimate is fair, for a UV lamp it is not.
Troubleshooting
- "No ML8511: the reference on D35 reads 0": VIN on the VCC rail, the 3V3 pin to R1, the middle of R1 and R2 to D35.
- OUT stays at about 0.99 V: no UV - the night, the shade, or glass in the way.
- The dose counts too fast or too slow: TIME_SCALE must equal U2's SPEED.
- The OLED stays dark: SDA and SCL on D21 and D22, VCC on 3.3 V.
- The ring stays dark: DIN on D13 and 5V on VCC; under UV index 0.5 no LED lights.
Limitations of the Simulation
- The sun is our library's model: a smooth curve through the day, a cloud that lets 45 % through and a shade that lets 30 % through, without the haze, the ozone, the altitude and the reflection from sand or water that change the real UV.
- The UV index is an estimate from the ML8511's intensity (1.7 per mW/cm2 for sunlight); the burn doses are typical values for each skin type; the SPF rule is a simple model of sunscreen wearing off. None of it is medical advice.
- The network to the laptop and the phone is simulated inside Proteus.
- ESP32 is a product of Espressif Systems and the ML8511 of LAPIS Technology (ROHM); this project is not made or endorsed by them or by Labcenter.
So, that was all about the UV Index and Sunburn Timer with ML8511 and ESP32 - Proteus Simulation. I hope it helps you understand what the UV index really measures, why a burn is about the dose and not the moment, how a sunscreen buys time but not unlimited time, and how to read a small analog signal accurately, all tested in a simulation of a full summer day. More projects with the ESP32 and the Raspberry Pi 5 are coming. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!