ESP32 S3 - GUVA-S12SD UV Sensor

Sunburn does not wait for a hot day. A cool, bright morning can carry a high UV dose that you cannot see or feel. With a GUVA-S12SD module on one analog pin, your ESP32 S3 can watch that invisible light for you and say how strong it is right now.

What you'll build in this tutorial:

  1. A look at the purple GUVA-S12SD board, its three pins and the UV index scale
  2. Three short wires from SIG, GND and VCC to GPIO8, GND and 3V3
  3. A first sketch that prints the raw ADC count next to the calibrated SIG voltage
  4. A second sketch that averages the input, works out an approximate UV index and names the risk level
  5. A simple way to test it, because a desk lamp is not enough
ESP32 S3 and GUVA-S12SD UV Sensor

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×Alternatively, ESP32 S3 SuperMini Dev Module
1×Alternatively, ESP32 S3 Uno-form Board
1×Alternatively, ESP32 S3 Camera Board
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Optionally, DC Power Jack
1×GUVA-S12SD UV Sensor Module
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for ESP32 S3
1×Recommended: Breakout Expansion Board for ESP32 S3
1×Recommended: Power Splitter for ESP32 S3

Or you can buy the following kits:

1×DIYables ESP32 S3 Starter Kit (ESP32 S3 included)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of GUVA-S12SD UV Sensor

GUVA-S12SD UV Sensor Pinout
image source: diyables.io

Look for the tiny white square on the purple board: that is the GUVA-S12SD photodiode, and it only cares about ultraviolet light. When UV rays land on it, it lets through a very small current. That current is far too weak for a microcontroller, so a VLM358 op-amp next to it scales it up into a voltage on the SIG pin. More UV means a higher voltage, and the ESP32 S3 simply measures that voltage with its ADC.

Key Specifications

The board is about 11mm x 27mm with two mounting holes, and the header comes already soldered. It responds to UV-A and UV-B between 240nm and 370nm over a wide 130 degree view, and it runs from 2.5V to 5V DC. SIG sits near 0V when there is no UV and climbs to roughly 1V or a bit more in strong summer sun. DIYables sells it in a pack of two.

A common hobby rule turns that voltage into a UV index: divide the SIG voltage by 0.1, so each 0.1V is about one UV index point. Treat the result as a good guide, not as a lab meter. The table shows how the WHO groups the index:

UV Index Level What it means
0 to 2 Low Little risk for most people
3 to 5 Moderate Use shade and sunscreen around midday
6 to 7 High Cover up, hat and sunglasses
8 to 10 Very High Stay out of direct sun at noon
11 and above Extreme Unprotected skin burns in minutes

GUVA-S12SD UV Sensor Pinout

The module has three pins. Read the labels on the board; from one side they are:

  1. SIG — the analog output voltage that rises with UV strength (to GPIO8 in this guide)
  2. GND — the 0V return, joined to a GND pin of the ESP32 S3
  3. VCC — power for the photodiode and the op-amp; use the 3V3 pin on the ESP32 S3

One surprise for new users: indoors the module reads almost zero. Room LEDs and normal bulbs give off nearly no UV, and window glass blocks much of the sun's UV-B. So a value close to 0V on your desk is correct, not a fault. Carry the board outside into daylight, or shine a UV flashlight on it, to see real numbers.

Wiring Diagram

The GUVA-S12SD needs no extra parts, so the whole circuit is three jumper wires. SIG goes to GPIO8, which belongs to ADC1 on the ESP32 S3, while GND goes to GND and VCC goes to the 3V3 pin.

The wiring diagram between ESP32 S3 GUVA-S12SD UV sensor

This image is created using Fritzing. Click to enlarge image

GUVA-S12SD Pin ESP32 S3 Pin
SIG GPIO8 (ADC1)
GND GND
VCC 3V3

Safety Notes

Feed the module from 3V3 and not from 5V. The SIG voltage stays low in normal use, but keeping the supply at the board's own 3.3V level means the analog pin can never see more than it is built for. We picked GPIO8 on purpose: ADC1 pins keep working when WiFi is turned on, while ADC2 pins do not, so you can add a web page or cloud upload later without moving the wire. When you take the sensor outdoors, keep the board and its wires dry and out of rain.

How To Program For GUVA-S12SD UV Sensor

There is no library to install, because the sensor is just an analog voltage. In setup(), analogSetAttenuation(ADC_11db) opens the ADC to its full input range. In loop(), analogRead(8) gives the raw 12-bit count from 0 to 4095, and analogReadMilliVolts(8) gives the same input as millivolts, using the chip's factory calibration. We use the millivolt value for every calculation, because it is more accurate than scaling the raw count by hand.

ESP32 S3 Code - Raw ADC Value and SIG Voltage

Start with this sketch to prove that the wiring works. Once per second it reads GPIO8 both ways and prints the raw count and the voltage on one line, so you can compare the two.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-guva-s12sd-uv-sensor */ #define UV_SIG_PIN 8 // ESP32 S3 GPIO8 (ADC1) connected to the SIG pin of the GUVA-S12SD module void setup() { Serial.begin(9600); // 11 dB attenuation lets the ADC measure the full 0 to ~3.1V range analogSetAttenuation(ADC_11db); } void loop() { int raw = analogRead(UV_SIG_PIN); // 12-bit value: 0 to 4095 int milliVolts = analogReadMilliVolts(UV_SIG_PIN); // calibrated voltage in mV float volts = milliVolts / 1000.0; Serial.print("ADC raw: "); Serial.print(raw); Serial.print(" | SIG voltage: "); Serial.print(volts, 3); Serial.println(" V"); delay(1000); // one line per second }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Place the module on the breadboard and run the wires from the table: SIG to GPIO8, GND to GND, VCC to 3V3.
  3. Plug the ESP32 S3 into your computer with the Type-C cable.
  4. Open the Arduino IDE, then pick the ESP32 S3 board under Tools > Board and its port under Tools > Port.
  5. Copy the sketch into a new window and click Upload.
  6. Open the Serial Monitor and set it to 9600 baud.
  7. Note the numbers on your desk, then take the laptop and board to a sunny window that is open, or step outside.
  8. Pro Tip: Point the white sensor square straight at the sky, not at the sun's reflection on a wall; the angle changes the reading a lot.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
ADC raw: 0 | SIG voltage: 0.000 V ADC raw: 3 | SIG voltage: 0.012 V ADC raw: 0 | SIG voltage: 0.000 V ADC raw: 11 | SIG voltage: 0.018 V ADC raw: 548 | SIG voltage: 0.421 V ADC raw: 762 | SIG voltage: 0.587 V ADC raw: 797 | SIG voltage: 0.614 V ADC raw: 785 | SIG voltage: 0.605 V
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

The first lines were taken indoors, so they sit near zero. The jump happens when the board moves into direct sun.

ESP32 S3 Code - UV Index and Risk Level

Now the voltage becomes something people understand. This sketch takes 16 quick millivolt readings and averages them, because the ADC and moving clouds both make the value jump a little. It then divides the average voltage by 0.1 to get the UV index, prints it with one decimal, and adds the WHO level name from the table above.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-guva-s12sd-uv-sensor */ #define UV_SIG_PIN 8 // ESP32 S3 GPIO8 (ADC1) connected to the SIG pin of the GUVA-S12SD module #define SAMPLES 16 // number of readings to average void setup() { Serial.begin(9600); analogSetAttenuation(ADC_11db); // full 0 to ~3.1V input range } // return the UV level name for a UV index (WHO scale) const char* uvLevel(float uvIndex) { if (uvIndex < 3) return "Low"; if (uvIndex < 6) return "Moderate"; if (uvIndex < 8) return "High"; if (uvIndex < 11) return "Very High"; return "Extreme"; } void loop() { // average several readings to calm down the noise long sum = 0; for (int i = 0; i < SAMPLES; i++) { sum += analogReadMilliVolts(UV_SIG_PIN); delay(5); } float volts = (sum / (float)SAMPLES) / 1000.0; // rough hobby conversion: every 0.1V on SIG is about 1 UV index point float uvIndex = volts / 0.1; Serial.print("SIG: "); Serial.print(volts, 2); Serial.print(" V -> UV index: "); Serial.print(uvIndex, 1); Serial.print(" ("); Serial.print(uvLevel(uvIndex)); Serial.println(")"); delay(1000); }

Detailed Instructions

  1. Keep the same three wires in place.
  2. Open the UV index sketch and click Upload.
  3. With the Serial Monitor at 9600 baud, take the sensor from the shade into full sunlight.
  4. Watch the UV index and the level name change as you move.
  5. Pro Tip: If you have a weather app with a UV forecast, compare it at noon on a clear day. If your number is always a little high or low, multiply uvIndex by a small correction factor in the code.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
SIG: 0.01 V -> UV index: 0.1 (Low) SIG: 0.02 V -> UV index: 0.2 (Low) SIG: 0.19 V -> UV index: 1.9 (Low) SIG: 0.34 V -> UV index: 3.4 (Moderate) SIG: 0.47 V -> UV index: 4.7 (Moderate) SIG: 0.66 V -> UV index: 6.6 (High) SIG: 0.72 V -> UV index: 7.2 (High) SIG: 0.81 V -> UV index: 8.1 (Very High)
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

※ NOTE THAT:

The GUVA-S12SD with the voltage / 0.1 rule gives an estimate, good for hobby projects and for spotting when the sun gets strong. It is not a calibrated UV meter, so do not use it alone for medical or safety decisions.

Application and Project Ideas

Knowing the UV level opens up many outdoor and health projects on the ESP32 S3.

  1. Sunscreen reminder: Beep a buzzer every two hours while the UV index stays at 3 or more.
  2. Balcony UV station: Show the current UV index and level on an OLED or a small web page over WiFi.
  3. UV lamp checker: Test whether a UV curing lamp or a UV LED strip still gives off real ultraviolet light.
  4. Smart blind: Close a window blind with a servo when strong UV starts to hit your plants or furniture.
  5. Weather station add-on: Log UV next to temperature and humidity to see how they change through the day.

Challenge Yourself

  1. Beginner: Turn on an LED on GPIO7 whenever the UV index reaches 6 (High) or more.
  2. Intermediate: Keep the highest UV index of the day in a variable and print it every minute along with the current value.
  3. Advanced: Serve the UV index and level on a web page from the ESP32 S3 over WiFi, and color the page from green (Low) to purple (Extreme).

Video Tutorial

The video for this ESP32 S3 UV sensor lesson will appear here.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!