Arduino - GUVA-S12SD UV Sensor

In this tutorial, we are going to learn:

Arduino GUVA-S12SD UV Sensor

About GUVA-S12SD UV Sensor

Your eyes cannot see ultraviolet light, but your skin feels it later as a sunburn. The GUVA-S12SD module lets Arduino "see" it. The board is small and purple, about 11mm x 27mm, with two mounting holes. On it you find two main parts: the GUVA-S12SD photodiode (the tiny white square) and a VLM358 op-amp chip.

How does it work? When UV light lands on the photodiode, it lets a very small current flow. This current is far too small for Arduino to read. The op-amp turns it into a voltage on the SIG pin, and Arduino reads that voltage with analogRead(). More UV gives a higher voltage.

The sensor only reacts to UV-A and UV-B light (240nm to 370nm). A desk lamp or a ceiling light gives almost no UV, so inside the house the reading stays close to 0V. To see real numbers, take the setup next to an open window in the sun, or go outside. A UV flashlight also works well for a quick test. The module is sold as a pack of two.

GUVA-S12SD UV Sensor Module
Sensor Chip GUVA-S12SD UV photodiode
Amplifier VLM358 op-amp
Spectral Range 240nm to 370nm (UV-A and UV-B)
Viewing Angle 130 degrees
Supply Voltage 2.5V to 5V DC
Output analog voltage, about 0V (no UV) to 1V or more (strong sun)
Header 3-pin (SIG, GND, VCC), presoldered
Board Size about 11mm x 27mm
GUVA-S12SD UV Sensor Pinout
image source: diyables.io

The header has three pins, labeled SIG, GND, VCC in that order:

  • SIG pin: needs to be connected to an Arduino analog input pin (A0 to A5). Its voltage rises as the UV gets stronger.
  • GND pin: needs to be connected to GND (0V)
  • VCC pin: needs to be connected to the 3.3V pin of the Arduino Uno (the 5V pin also works)

From Voltage to UV Index

The UV index is the number you see in the weather app. A simple rule that most makers use for this module is: UV index ≈ SIG voltage / 0.1. In other words, every 0.1V on SIG is about one UV index point. So 0.35V means a UV index of about 3.5.

UV Index Level What it means
0 to 2 Low little risk for most people
3 to 5 Moderate use a hat and sunscreen at noon
6 to 7 High cover up, look for shade
8 to 10 Very High skin can burn quickly
11 and above Extreme stay out of the midday sun

This rule gives a good estimate for hobby projects, such as a sunscreen reminder. It is not a calibrated meter, so do not use it for medical or safety decisions.

Wiring Diagram

Connect the SIG pin of the module to A0, the GND pin to GND, and the VCC pin to the 3.3V pin of the Arduino Uno (or to 5V; both are fine).

Arduino GUVA-S12SD UV Sensor Wiring Diagram

This image is created using Fritzing. Click to enlarge image

Use longer jumper wires if you can. Then the Arduino can stay on the table in the shade while the sensor sits in the sun.

How To Program For GUVA-S12SD UV Sensor

  • No library is needed. Name the analog pin that SIG goes to:
#define UV_SENSOR_PIN A0
  • Read the ADC count. The Uno has a 10-bit ADC, so the result is between 0 and 1023:
int adcValue = analogRead(UV_SENSOR_PIN);
  • Change the count into volts. The ADC reference of the Uno is 5V. This stays true even when the sensor gets its power from the 3.3V pin:
float sigVoltage = adcValue * 5.0 / 1023.0;
  • Estimate the UV index from the voltage:
float uvIndex = sigVoltage / 0.1;

Arduino Code - Read GUVA-S12SD UV Sensor Voltage

Start with the plain numbers. Once per second, this sketch prints the raw ADC count from A0 and the matching SIG voltage. Use it to check the wiring and to get a feel for how small the signal is.

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-guva-s12sd-uv-sensor */ #define UV_SENSOR_PIN A0 // Arduino pin connected to the SIG pin of the GUVA-S12SD module #define ADC_REF_VOLT 5.0 // Arduino Uno ADC reference voltage (5V) void setup() { Serial.begin(9600); // start the Serial Monitor connection } void loop() { int adcValue = analogRead(UV_SENSOR_PIN); // 0 to 1023 float sigVoltage = adcValue * ADC_REF_VOLT / 1023.0; // turn the ADC count into volts Serial.print("ADC: "); Serial.print(adcValue); Serial.print(" | SIG: "); Serial.print(sigVoltage, 3); // 3 decimals, because the signal is small Serial.println(" V"); delay(1000); // one reading per second }

Quick Steps

  • Connect Arduino to PC via USB cable.
  • Wire the UV sensor module to Arduino as shown in the wiring diagram.
  • Open Arduino IDE, select the right board and port.
  • Copy the above code and paste it to Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to Arduino.
  • Open the Serial Monitor and set the baud rate to 9600.
  • Watch the values at your desk for a few seconds, then carry the board (still on the USB cable of a laptop) into direct sunlight.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
ADC: 1 | SIG: 0.005 V ADC: 0 | SIG: 0.000 V ADC: 3 | SIG: 0.015 V ADC: 2 | SIG: 0.010 V ADC: 41 | SIG: 0.200 V ADC: 87 | SIG: 0.425 V ADC: 94 | SIG: 0.459 V ADC: 101 | SIG: 0.494 V ADC: 98 | SIG: 0.479 V
Ln 11, Col 1
Arduino Uno on COM15
2

The first four lines were taken indoors: almost nothing. The jump to about 0.45V came when the sensor faced the sun. Notice that even in sun the ADC count stays under about 200. This is normal, because the signal only uses the bottom part of the 0V to 5V range.

Arduino Code - GUVA-S12SD UV Index and Risk Level

This sketch turns the reading into something people understand. It takes 16 quick samples and averages them, so the last digit does not jump around. Then it divides the voltage by 0.1 to get the UV index, and prints the level name from the table above.

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-guva-s12sd-uv-sensor */ #define UV_SENSOR_PIN A0 // Arduino pin connected to the SIG pin of the GUVA-S12SD module #define ADC_REF_VOLT 5.0 // Arduino Uno ADC reference voltage (5V) #define SAMPLE_COUNT 16 // number of readings to average void setup() { Serial.begin(9600); } void loop() { // take several readings and average them to calm down the small signal long total = 0; for (int i = 0; i < SAMPLE_COUNT; i++) { total += analogRead(UV_SENSOR_PIN); delay(5); } float adcAverage = total / (float)SAMPLE_COUNT; float sigVoltage = adcAverage * ADC_REF_VOLT / 1023.0; float uvIndex = sigVoltage / 0.1; // rough rule: every 0.1V is about 1 UV index point Serial.print("SIG: "); Serial.print(sigVoltage, 2); Serial.print(" V -> UV index: "); Serial.print(uvIndex, 1); Serial.print(" ("); Serial.print(uvLevel(uvIndex)); Serial.println(")"); delay(1000); } // return the WHO name for a UV index value 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"; }

Quick Steps

  • Keep the same wiring.
  • Copy the above code and paste it to Arduino IDE.
  • Click Upload button on Arduino IDE to upload code to Arduino.
  • Open the Serial Monitor (baud rate 9600).
  • Move the sensor from the room, to the shade outside, and then into full sun around midday.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' 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.18 V -> UV index: 1.8 (Low) SIG: 0.21 V -> UV index: 2.1 (Low) SIG: 0.47 V -> UV index: 4.7 (Moderate) SIG: 0.62 V -> UV index: 6.2 (High) SIG: 0.66 V -> UV index: 6.6 (High) SIG: 0.64 V -> UV index: 6.4 (High)
Ln 11, Col 1
Arduino Uno on COM15
2

※ NOTE THAT:

If the value stays near 0 even in the sun, check that the white photodiode faces the sky and is not behind a glass window. Normal window glass blocks most UV-B light, so readings behind glass are lower than outside.

Ideas for what to build next:

  • A sunscreen reminder that beeps with a piezo buzzer when the UV index reaches 3.
  • A small UV station that shows the index on an LCD next to the door.
  • A tester to check if a UV lamp or a UV LED still gives real UV light.
  • A smart blind that closes with a servo motor when the sun gets too strong.

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

The Best Arduino Starter Kit

※ OUR MESSAGES