Arduino UNO R4 - GUVA-S12SD UV Sensor

In this guide, we will learn how to use the GUVA-S12SD UV sensor with the Arduino UNO R4. Your eyes cannot see ultraviolet light, but your skin feels it a few hours later as sunburn. This small module lets the Arduino UNO R4 put a number on that invisible light, so a project can say "put on sunscreen now" instead of you guessing. In detail, we will learn:

Arduino UNO R4 and GUVA-S12SD UV sensor module

Overview of GUVA-S12SD UV Sensor

GUVA-S12SD UV sensor module pinout
image source: diyables.io

The DIYables GUVA-S12SD module is a narrow purple board, roughly 11mm by 27mm, with a mounting hole at each end. It comes in a pack of two, and the 3-pin header is already soldered, so you can plug jumper wires in right away.

Two parts do the work. The tiny white square is the GUVA-S12SD photodiode. When UV light falls on it, it passes a very small current, much too weak to measure directly. The second chip, a VLM358 op-amp, boosts that current into a voltage on the SIG pin. The Arduino UNO R4 then reads this voltage with analogRead(). In short: more UV, higher voltage.

The photodiode only "sees" UV-A and UV-B, from 240nm to 370nm, over a wide 130 degree angle. Ordinary room light is mostly visible light, so on a desk the sensor gives a voltage near 0V. That is normal. To get real numbers, carry the board outdoors into the sun, or point a UV flashlight (the kind used to check bank notes) at it.

GUVA-S12SD UV Sensor Module
Sensor chip GUVA-S12SD UV photodiode
Signal amplifier VLM358 op-amp
Wavelength range 240nm to 370nm (UV-A and UV-B)
Viewing angle 130 degrees
Power supply 2.5V to 5V DC
SIG output analog, near 0V without UV, about 1V or a bit more in strong sun
Size about 11mm x 27mm, 2 mounting holes

From left to right, the pins are printed SIG, GND, VCC:

  • SIG pin: connect to an analog input of the Arduino UNO R4. This guide uses A0.
  • GND pin: connect to GND (0V).
  • VCC pin: connect to 3.3V (or 5V). The diagram uses 3.3V, but the module accepts anything from 2.5V to 5V.

From Voltage to UV Index

The UV index is the number you hear in weather reports. A simple rule used by many makers is: UV index ≈ SIG voltage / 0.1. Put another way, each 0.1V on SIG is about one index point, so 0.6V means about index 6. This is a good estimate for a hobby project, not a calibrated meter. The World Health Organization sorts the index into five levels:

UV Index Level Simple advice
0 to 2 Low no special care for most people
3 to 5 Moderate wear a hat, use sunscreen
6 to 7 High stay in the shade around noon
8 to 10 Very High cover up, avoid long time in the sun
11 and up Extreme stay inside if you can

Wiring Diagram

Three jumper wires are all you need. SIG goes to A0, GND to GND, and VCC to the 3.3V pin, as the diagram shows. Moving VCC to the 5V pin also works if 3.3V is already in use.

UV Sensor Pin Arduino UNO R4 Pin
SIG A0
GND GND
VCC 3.3V (or 5V)
The wiring diagram between Arduino UNO R4 GUVA-S12SD UV sensor

This image is created using Fritzing. Click to enlarge image

See The best way to supply power to the Arduino Uno R4 and other components.

Keep the white photodiode facing up and uncovered. A finger or a wire over it blocks the light and gives a false low value.

How To Program For GUVA-S12SD UV Sensor

There is no library to install. The sensor is just an analog voltage, and the Arduino core already knows how to read it.

  • Name the analog pin that the SIG wire goes to:
const int UV_SIG_PIN = A0;
  • Read the pin. By default the Arduino UNO R4 gives a number from 0 to 1023:
int adcValue = analogRead(UV_SIG_PIN);
  • Change the number into volts. The analog reference of the Arduino UNO R4 is 5V, and it stays 5V even when the module is powered from 3.3V:
float sigVolt = adcValue * 5.0 / 1023.0;
  • Estimate the UV index:
float uvIndex = sigVolt / 0.1;

※ NOTE THAT:

The ADC of the Arduino UNO R4 can do more than 10 bits. If you call analogReadResolution(14); in setup(), analogRead() returns 0 to 16383, and the formula becomes adcValue * 5.0 / 16383.0. Each step is then about 0.3mV instead of about 4.9mV. For a UV index with one decimal, the default 10 bits is already enough, so the code below keeps it simple.

Arduino UNO R4 Code - Read SIG Voltage

Start with the raw data. This sketch reads A0 a little faster than once per second and prints two values on one line: the ADC number and the voltage it stands for. It is the best way to check the wiring before doing any math.

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-guva-s12sd-uv-sensor */ const int UV_SIG_PIN = A0; // Arduino UNO R4 pin connected to the SIG pin of the UV sensor void setup() { Serial.begin(9600); // analogRead() on the UNO R4 is 10-bit by default: 0 to 1023 for 0V to 5V } void loop() { int adcValue = analogRead(UV_SIG_PIN); // raw number from the ADC float sigVolt = adcValue * 5.0 / 1023.0; // the reference is 5V, even with the sensor on 3.3V Serial.print("ADC: "); Serial.print(adcValue); Serial.print(" | SIG: "); Serial.print(sigVolt, 3); Serial.println(" V"); delay(800); }

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Wire the UV sensor module to the Arduino UNO R4 according to the provided diagram.
  • Plug the Arduino UNO R4 into your computer with a USB Type-C cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino UNO R4 board (e.g., Arduino UNO R4 WiFi or Arduino UNO R4 Minima) and COM port.
  • Paste the code above into the Arduino IDE.
  • Click the Upload button.
  • Open the Serial Monitor at 9600 baud. On your desk, the numbers stay tiny.
  • Now take the laptop and the board outside into the sun (closed window glass blocks much of the UV). The values jump up.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
ADC: 2 | SIG: 0.010 V ADC: 3 | SIG: 0.015 V ADC: 2 | SIG: 0.010 V ADC: 0 | SIG: 0.000 V ADC: 78 | SIG: 0.381 V ADC: 113 | SIG: 0.552 V ADC: 141 | SIG: 0.689 V ADC: 152 | SIG: 0.743 V ADC: 149 | SIG: 0.728 V
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

The first lines come from indoors, the last ones from direct sunlight. If the value stays at 0 even in the sun, check that SIG really goes to A0 and that VCC has power.

Arduino UNO R4 Code - UV Index and Level

Now let's make the reading useful. This sketch takes 16 quick readings, averages them so the number does not jump around, converts the result to a UV index, and adds the WHO level name.

/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-guva-s12sd-uv-sensor */ const int UV_SIG_PIN = A0; // Arduino UNO R4 pin connected to the SIG pin of the UV sensor const int SAMPLE_COUNT = 16; // number of readings averaged for each result void setup() { Serial.begin(9600); } void loop() { // add up several readings to smooth out small jumps long total = 0; for (int i = 0; i < SAMPLE_COUNT; i++) { total += analogRead(UV_SIG_PIN); delay(5); } float adcAverage = (float)total / SAMPLE_COUNT; float sigVolt = adcAverage * 5.0 / 1023.0; // 10-bit ADC, 5V reference float uvIndex = sigVolt / 0.1; // about 1 UV index point for every 0.1V Serial.print("SIG: "); Serial.print(sigVolt, 2); Serial.print(" V -> UV index "); Serial.print(uvIndex, 1); Serial.print(" ("); Serial.print(uvLevel(uvIndex)); Serial.println(")"); delay(1000); } // return the WHO level name for a UV index value const char* uvLevel(float uv) { if (uv < 3) return "Low"; if (uv < 6) return "Moderate"; if (uv < 8) return "High"; if (uv < 11) return "Very High"; return "Extreme"; }

Detailed Instructions

  • Do not change the wiring.
  • Copy this second sketch into the Arduino IDE and click Upload.
  • Watch the Serial Monitor. Indoors you see "Low". Outside at midday, the level climbs.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
SIG: 0.01 V -> UV index 0.1 (Low) SIG: 0.01 V -> UV index 0.1 (Low) SIG: 0.43 V -> UV index 4.3 (Moderate) SIG: 0.58 V -> UV index 5.8 (Moderate) SIG: 0.64 V -> UV index 6.4 (High) SIG: 0.72 V -> UV index 7.2 (High) SIG: 0.81 V -> UV index 8.1 (Very High)
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

A cloud passing over the sun can drop the index by a few points in seconds. Thin clouds let a lot of UV through, so do not trust a cloudy sky too much.

To check your result, compare it with the UV index in a local weather app at the same time. If your board is always a little high or low, you can change the 0.1 in the code to match.

Project Ideas

A few ways to build on this with the Arduino UNO R4:

  • Sunscreen reminder: when the index reaches 3, beep a buzzer every hour you stay outside.
  • UV level on the LED matrix: the Arduino UNO R4 WiFi has a 12x8 LED matrix on board, so it can show the current index number without any extra display.
  • Online UV station: send the index from the Arduino UNO R4 WiFi to a web page on your phone, next to temperature and humidity.
  • UV lamp tester: hold a UV LED or a nail-curing lamp over the sensor to see if it still gives out enough UV.
  • Smart blind: use a servo motor to close a window blind when the UV level becomes High.

Video Tutorial

Function References

※ 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!