Arduino Nano - GUVA-S12SD UV Sensor

This tutorial instructs you how to use Arduino Nano to read the ultraviolet (UV) light level from a GUVA-S12SD UV sensor and turn it into an approximate UV index. The sensor gives a single analog voltage, so one analog pin of the Nano and the analogRead() function are all it takes. In detail, we will learn:

Arduino Nano GUVA-S12SD UV sensor

We suggest:

Hardware Preparation

1×Official Arduino Nano
1×Alternatively, DIYables Nano V3.0 Development Board
1×USB A to Mini-B USB cable
1×GUVA-S12SD UV Sensor Module
1×Breadboard
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

Or you can buy the following kits:

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 module pinout
image source: diyables.io

The module is a small purple PCB, roughly 11mm x 27mm, with two holes for screws. The tiny white square on it is the GUVA-S12SD photodiode. Next to it sits a VLM358 op-amp. When UV rays land on the photodiode, it lets through a very small current. That current is far too weak to measure directly, so the op-amp turns it into a voltage on the SIG pin. The Nano then reads this voltage with analogRead(). More UV means a higher voltage.

The photodiode only reacts to UV-A and UV-B (240nm to 370nm). Room lamps and normal daylight through a closed window give almost no signal, so do not worry if the reading stays close to 0V on your desk. Take the board outside into direct sun, or shine a UV flashlight on it, to see real numbers.

GUVA-S12SD UV Sensor Module
Sensing element GUVA-S12SD UV photodiode
Amplifier VLM358 op-amp on the board
Wavelength 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 around 1V or a bit more in strong sun
Board size about 11mm x 27mm, 2 mounting holes
Header 3-pin, presoldered

The three pins are labeled SIG, GND and VCC, in this order:

  • SIG pin: must be connected to an analog input pin of Arduino Nano (A0 in this tutorial). Its voltage rises as the UV gets stronger
  • GND pin: must be connected to GND (0V)
  • VCC pin: must be connected to the 3V3 pin of Arduino Nano. The 5V pin is fine too, because the module accepts 2.5V to 5V

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

From Voltage to UV Index

The UV index is the number you see in weather apps. It tells how fast the sun can burn your skin. Hobby projects with this sensor use a simple rule of thumb: UV index ≈ SIG voltage (V) / 0.1. In other words, each 0.1V on the SIG pin adds about one point. For example, 0.45V means a UV index of about 4.5. Treat the result as a good estimate, not as the reading of a calibrated meter.

These are the five UV index levels used by the World Health Organization:

UV Index Level What it means
0 to 2 Low little risk for most people
3 to 5 Moderate seek shade around midday
6 to 7 High sunscreen, hat and sunglasses
8 to 10 Very High extra care, skin burns quickly
11 and above Extreme avoid the midday sun

Wiring Diagram

Feed the module from the 3V3 pin of the Nano and run its SIG wire to analog pin A0. Both sketches below use this same wiring.

The wiring diagram between Arduino Nano and GUVA-S12SD UV sensor

This image is created using Fritzing. Click to enlarge image

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

GUVA-S12SD UV Sensor Arduino Nano
SIG A0
GND GND
VCC 3V3 (or 5V)

How To Program For GUVA-S12SD UV Sensor

The sensor needs no library. A few built-in functions do the job.

  • The first step is to give a name to the analog pin that the SIG wire goes to:
#define UV_SIG_PIN A0
  • Read the pin with analogRead(). The Nano has a 10-bit converter, so the result is a whole number from 0 to 1023:
int raw = analogRead(UV_SIG_PIN);
  • Turn that count into volts. The Nano's converter always compares against 5V, even when the module itself is powered from 3V3, so 5.0 is the right number here:
float sigVoltage = raw * 5.0 / 1023.0;
  • Divide by 0.1 to get the approximate UV index:
float uvIndex = sigVoltage / 0.1;

Arduino Nano Code for GUVA-S12SD UV Sensor - Raw Value and Voltage

Start with this sketch to make sure the wiring is right. Once per second, it prints the ADC count from A0 and the SIG voltage it stands for.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-guva-s12sd-uv-sensor */ #define UV_SIG_PIN A0 // Arduino Nano analog pin wired to the SIG pin of the GUVA-S12SD module const float ADC_VREF = 5.0; // the Nano's ADC measures against 5V, even if the module runs on 3.3V const float ADC_MAX = 1023.0; // 10-bit ADC: values from 0 to 1023 void setup() { Serial.begin(9600); // open the Serial Monitor link at 9600 baud } void loop() { int raw = analogRead(UV_SIG_PIN); // 0 to 1023 float sigVoltage = raw * ADC_VREF / ADC_MAX; // turn the ADC count into volts Serial.print("ADC: "); Serial.print(raw); Serial.print(" -> SIG: "); Serial.print(sigVoltage, 3); Serial.println(" V"); delay(1000); // one line per second }

Detailed Instructions

  • If this is the first time you use Arduino Nano, see how to set up the environment for Arduino Nano in Arduino IDE.
  • Wire the components as shown in the diagram.
  • Connect the Arduino Nano board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Choose the Arduino Nano board and its COM port.
  • Paste the sketch above into the editor.
  • Hit the Upload button to flash it to the Nano.
  • Open the Serial Monitor and pick 9600 baud.
  • Leave the sensor on your desk for a few seconds, then carry the Nano (on a laptop or a USB power bank) to a sunny spot outside.
  • The first lines come from indoors, the last ones from the sun:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano' on 'COM15')
New Line
9600 baud
ADC: 2 -> SIG: 0.010 V ADC: 1 -> SIG: 0.005 V ADC: 4 -> SIG: 0.020 V ADC: 2 -> SIG: 0.010 V ADC: 72 -> SIG: 0.352 V ADC: 98 -> SIG: 0.479 V ADC: 131 -> SIG: 0.640 V ADC: 127 -> SIG: 0.621 V ADC: 133 -> SIG: 0.650 V
Ln 11, Col 1
Arduino Nano on COM15
2

A count between 0 and 5 indoors is normal. If the number does not climb in direct sun, check that the SIG wire is on A0 and not on a digital pin, and that the white photodiode faces the sky.

Arduino Nano Code for GUVA-S12SD UV Sensor - UV Index and Level

Single readings jump a little, because clouds pass and the signal is small. This sketch takes 16 readings in a row and uses their average. It then divides the voltage by 0.1 to get the UV index, prints it with one decimal, and adds the WHO level name next to it.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-guva-s12sd-uv-sensor */ #define UV_SIG_PIN A0 // Arduino Nano analog pin wired to the SIG pin of the GUVA-S12SD module const float ADC_VREF = 5.0; // ADC reference of the Nano (V) const float ADC_MAX = 1023.0; // 10-bit ADC const int NUM_SAMPLES = 16; // readings averaged for each result, to calm the output // return the SIG voltage, averaged over a few readings float readUvVoltage() { long total = 0; for (int i = 0; i < NUM_SAMPLES; i++) { total += analogRead(UV_SIG_PIN); delay(5); } return (total / (float)NUM_SAMPLES) * ADC_VREF / ADC_MAX; } // name of the WHO UV index band const char* uvLevelName(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 setup() { Serial.begin(9600); } void loop() { float voltage = readUvVoltage(); float uvIndex = voltage / 0.1; // rough rule: every 0.1V is about 1 UV index point Serial.print("SIG: "); Serial.print(voltage, 2); Serial.print(" V | UV index: "); Serial.print(uvIndex, 1); Serial.print(" ("); Serial.print(uvLevelName(uvIndex)); Serial.println(")"); delay(1000); }

Detailed Instructions

  • Keep the wiring as it is.
  • Replace the old sketch in Arduino IDE with this one.
  • Click Upload.
  • Watch the Serial Monitor while you move the sensor from the shade into full sun, around noon if you can.
  • You should see something like this:
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Nano
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Nano' 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.24 V | UV index: 2.4 (Low) SIG: 0.37 V | UV index: 3.7 (Moderate) SIG: 0.58 V | UV index: 5.8 (Moderate) SIG: 0.66 V | UV index: 6.6 (High) SIG: 0.81 V | UV index: 8.1 (Very High) SIG: 0.79 V | UV index: 7.9 (High)
Ln 11, Col 1
Arduino Nano on COM15
2

※ NOTE THAT:

Glass and many plastics block a big part of UV. A sensor placed behind a window, or inside a closed clear box, will read much lower than the real UV outside. For an outdoor station, keep the photodiode open to the sky, or cover it only with a material that lets UV through.

Additional Knowledge

GUVA-S12SD UV Sensor vs Photoresistor (LDR)

GUVA-S12SD UV Sensor Photoresistor (LDR)
What it senses UV-A and UV-B only (240nm to 370nm) visible light
Indoor reading under lamps close to 0 changes a lot
Output voltage that rises with UV resistance that changes with light
Can estimate UV index yes, roughly no
Typical job sun safety, UV lamp checks day/night switching, brightness

It is evident that the two sensors answer different questions. The photoresistor tells you how bright it is, while the GUVA-S12SD tells you how strong the part of sunlight that burns skin is. A sunny but cool spring day can still have a high UV index.

Project Ideas

  • A beach-bag reminder that beeps when it is time to put on sunscreen again
  • A UV index station that shows the level on an LCD or OLED
  • A tester that checks whether an old UV curing lamp or UV LED still gives out UV
  • An extra channel for an outdoor weather station, next to temperature and humidity
  • A smart blind that closes with a servo motor when the UV index goes above 6

Video Tutorial

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