ESP8266 - GUVA-S12SD UV Sensor
This tutorial instructs you how to use the ESP8266 NodeMCU to read the strength of ultraviolet light from a GUVA-S12SD UV sensor. Sunburn is caused by UV, not by heat or brightness, so a normal light sensor cannot warn you about it. This tiny module can, and the NodeMCU needs only its single analog pin to read it. Later you can push the value to your phone over WiFi. In detail, we will learn:
- What is on the GUVA-S12SD board, and what its SIG, GND and VCC pins do
- How to connect the module to the NodeMCU: SIG to A0, power from 3V3
- How to program the ESP8266 to print the A0 count and the matching SIG voltage
- How to program the ESP8266 to estimate the UV index and name the WHO risk level (Low to Extreme)

We suggest:
- Utilizing the light sensor tutorial if you want to measure how bright a room is. The UV sensor does not react to normal lamps.
- Utilizing the LDR module tutorial if you need a simple day/night switch with a digital output.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of GUVA-S12SD UV Sensor

The module is a small purple board, about 11mm x 27mm, with two mounting holes. Look for the small white square near one end: that is the GUVA-S12SD photodiode, the part that sees UV. Next to it sits a VLM358 op-amp chip. The header is already soldered, and DIYables sells the module as a pack of two.
How does it work? When UV light lands on the photodiode, it lets a very small current flow. This current is far too weak for the ESP8266 to notice. The op-amp turns it into a voltage on the SIG pin, and the NodeMCU reads that voltage on A0 with analogRead(). More UV gives a higher voltage.
The sensor only cares about UV-A and UV-B light, from 240nm to 370nm. Ceiling lights, phone screens and most window light give it almost nothing, so do not worry if it shows nearly 0 on your desk. That is normal. Carry it outside into the sun, or shine a UV flashlight at it, to see real numbers.
| GUVA-S12SD UV Sensor Module | |
|---|---|
| Sensor chip | GUVA-S12SD UV photodiode + VLM358 op-amp |
| Light it detects | UV-A and UV-B, 240nm to 370nm |
| Viewing angle | 130 degrees |
| Supply voltage | 2.5V to 5V DC |
| Output | analog voltage on SIG |
| SIG with no UV | about 0V |
| SIG in strong sunlight | about 1V or a bit more |
| Board size | about 11mm x 27mm, two mounting holes |
Most makers use a simple rule to turn the voltage into a UV index: UV index ≈ SIG voltage / 0.1. In other words, every 0.1V on SIG is about one UV index point, so 0.5V means a UV index of about 5. This is a good estimate for hobby projects, but the module is not a calibrated UV meter. Do not trust it for medical or safety decisions.
The UV index levels defined by the WHO are:
| UV Index | Level | What it means |
|---|---|---|
| 0 - 2 | Low | Little risk for most people |
| 3 - 5 | Moderate | Wear a hat and sunscreen at midday |
| 6 - 7 | High | Stay in the shade around noon |
| 8 - 10 | Very High | Skin can burn quickly |
| 11+ | Extreme | Avoid the midday sun |
The GUVA-S12SD UV Sensor Pinout
The three pins are printed on the board in this order: SIG, GND, VCC.
- SIG pin: must be connected to the A0 pin of the NodeMCU. It carries the analog UV voltage.
- GND pin: must be connected to a G (GND) pin of the NodeMCU (0V)
- VCC pin: must be connected to the 3V3 pin of the NodeMCU. The module also runs on 5V, but 3.3V matches the logic level of the ESP8266.
※ NOTE THAT:
The arrangement of pins on a module may differ from one manufacturer to another. It is essential to always refer to the labels printed on the module when using it. Take a close look!
Wiring Diagram
The ESP8266 has just one analog input, A0, so the SIG wire has only one place to go. Take 3V3 and G from the same side of the NodeMCU as A0, which keeps the three wires short and tidy.

This image is created using Fritzing. Click to enlarge image
See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.
| GUVA-S12SD UV Sensor | ESP8266 NodeMCU |
|---|---|
| SIG | → A0 |
| GND | → G (GND) |
| VCC | → 3V3 |
If you want to take readings outdoors, use longer jumper wires so the sensor can face the sky while the NodeMCU stays in the shade, or power the NodeMCU from a USB power bank.
How To Program For GUVA-S12SD UV Sensor
No library is required. The analogRead() function from the ESP8266 core is all we need.
- The first step is to give a name to the analog pin that is wired to SIG:
- Then, read the pin with the analogRead() function. On the NodeMCU, the result is a number from 0 to 1023:
- To get the SIG voltage, scale the count. The bare ESP8266 chip only accepts 0V to 1V on its ADC, but the NodeMCU board adds a voltage divider in front of A0. Because of that, 1023 stands for about 3.3V:
- Finally, estimate the UV index with the 0.1V-per-point rule:
One A0 count is about 3.2mV, which is roughly 0.03 UV index points. So the reading can move by a few counts even when the sunlight stays the same. The second sketch averages 16 readings to calm this down.
ESP8266 NodeMCU Code for GUVA-S12SD UV Sensor - Raw Value and Voltage
Start with this sketch to check the wiring. Once per second, it prints the A0 count and the SIG voltage with three decimals.
Detailed Instructions
- If this is the first time you use ESP8266, see how to setup environment for ESP8266 on Arduino IDE.
- Wire the UV sensor to the NodeMCU as shown in the table and diagram above.
- Connect the ESP8266 NodeMCU board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Choose the board NodeMCU 1.0 (ESP-12E Module) and the COM port of your NodeMCU.
- Copy the code above into a new sketch.
- Click the Upload button and wait for the upload to finish.
- Open the Serial Monitor at 9600 baud. On your desk, the numbers stay close to zero.
- Take the laptop and the NodeMCU near a sunny window that is open, or outside, and point the white square at the sky. The values rise:
Normal window glass blocks most UV-B and part of UV-A. If the value barely moves behind a closed window, open it or go outside.
ESP8266 NodeMCU Code for GUVA-S12SD UV Sensor - UV Index and Risk Level
This sketch turns the voltage into something people understand. It averages 16 quick readings, divides the voltage by 0.1 to get the UV index, rounds it, and prints the WHO level name next to it.
Detailed Instructions
- Keep the same wiring. SIG stays on A0.
- Paste the code above into a new sketch and click Upload.
- Open the Serial Monitor (9600 baud).
- Start in the shade, then hold the sensor in direct sunlight. Shade it with your hand for a moment to see the level drop.
- A sample from a sunny late morning:
The last line is a reading taken with a hand over the sensor. Clouds have a smaller effect than you might expect: thin clouds let a lot of UV through.
※ NOTE THAT:
The ESP8266's ADC is fine for a rough UV estimate like this one, but it is not very precise. If your project needs steadier numbers, you can use an external ADC such as the ADS1115 with the ESP8266.
Additional Knowledge
GUVA-S12SD UV Sensor vs Light Sensor (Photoresistor)
| Question | GUVA-S12SD UV Sensor | Light Sensor (LDR) |
|---|---|---|
| What it measures | UV-A and UV-B (240nm to 370nm) | Visible brightness |
| Reaction to indoor lamps | Almost none | Strong |
| Output direction | More UV = higher voltage | Depends on how the divider is wired |
| Can estimate the UV index? | Yes, roughly (voltage / 0.1) | No |
| Extra resistor needed? | No, the op-amp is on the board | Yes, for a bare photoresistor |
It is evident that the GUVA-S12SD is the right part when you care about sunburn risk, while a light sensor is better for "is it dark or bright?" jobs. The two can even work together in the same weather station.
Ideas for Using the UV Sensor
- Sunscreen reminder: when the UV index stays at 3 or more, send a message to your phone every two hours.
- WiFi UV station: show the live UV index on a small web page served by the NodeMCU.
- UV lamp tester: check if an old UV curing lamp or UV LED still gives out UV light.
- Weather station: log UV together with temperature and humidity over a whole day.
- Smart blind: close a window blind with a servo when the UV level becomes High.