Arduino Giga R1 WiFi GUVA-S12SD UV Sensor

In this guide, we will learn how to use the GUVA-S12SD UV sensor with the Arduino Giga R1 WiFi to find out how strong the sun's ultraviolet light is right now. In detail, we will learn:

Arduino Giga R1 WiFi and GUVA-S12SD UV sensor

Sunlight you cannot see is the part that burns skin. With this sensor, a Giga project can warn you before that happens: a sunscreen reminder on the balcony, a UV column for a WiFi weather station, or a quick test to see whether a cheap "UV" flashlight really gives out UV.

Hardware Preparation

1×Arduino Giga R1 WiFi
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×GUVA-S12SD UV Sensor Module
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno/Mega/Giga
1×Recommended: Sensors/Servo Expansion Shield for Arduino Mega/Giga
1×Recommended: Breadboard Shield for Arduino Mega/Giga
1×Recommended: Enclosure for Arduino Giga
1×Recommended: Power Splitter for Arduino Giga

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

The module is a purple board of about 11mm x 27mm with two mounting holes. Look for the little white square near one end: that is the GUVA-S12SD UV photodiode. Beside it sits a VLM358 op-amp chip. Here is the idea in one breath: when UV light lands on the photodiode, it lets through a very tiny current, far too small for any board to read. The op-amp makes it bigger and hands it to the SIG pin as a voltage, and the Giga measures that voltage with analogRead(). More UV gives a higher voltage.

The photodiode reacts to UV-A and UV-B (240nm to 370nm) and looks at a wide 130 degree cone of sky. Normal room lamps and visible light give it almost nothing to work with, so a reading close to 0V indoors is correct, not a fault. Take it outside into direct sun, or shine a UV flashlight at it, to see the numbers climb. A window is not a good test spot either: glass stops most UV-B.

DIYables sells the module in a pack of 2, with the header pins already soldered.

GUVA-S12SD UV Sensor Module
Sensing element GUVA-S12SD UV photodiode
Amplifier VLM358 op-amp
Light it responds to UV-A and UV-B, 240nm to 370nm
Viewing angle 130 degrees
Supply voltage 2.5V to 5V DC
Output analog voltage, about 0V (no UV) to about 1V or more in strong sun
Board size about 11mm x 27mm, 2 mounting holes
Pack 2 modules, presoldered

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

  • SIG pin: connect to an analog input of the Arduino Giga R1 WiFi (A0 in this guide). It carries the UV voltage.
  • GND pin: connect to a GND pin of the Giga (0V).
  • VCC pin: connect to the 3.3V pin of the Giga.

The module can run from 5V too, but on the Giga keep it on 3.3V. Every Giga pin is a 3.3V pin, so feeding the board from the same rail keeps everything at one level.

How to read the voltage as a UV index: most makers use the simple rule "UV index is about the SIG voltage divided by 0.1". So 0.1V is about index 1, 0.5V is about index 5, and so on. This is fine for a hobby project, but it is not a calibrated lab meter. The World Health Organization groups the UV index like this:

UV Index Level What it means for you
0 - 2 Low safe for most people
3 - 5 Moderate shade at midday, use sunscreen
6 - 7 High cover up, hat and sunglasses
8 - 10 Very High avoid the sun around noon
11+ Extreme stay inside or fully covered

Wiring Diagram

The UV module needs no resistor and no breadboard. Three jumper wires go straight from its header to the Giga.

The wiring diagram between Arduino Giga R1 WiFi GUVA-S12SD UV sensor

This image is created using Fritzing. Click to enlarge image

GUVA-S12SD Pin Arduino Giga R1 WiFi Pin
SIG A0
GND GND
VCC 3.3V

The op-amp is already on the module, so there's no need to add one. This makes wiring or soldering easier. If A0 is busy in your project, any other analog pin of the Giga works; just change UV_SIG_PIN in the code.

How To Program For GUVA-S12SD UV Sensor

No library is needed. Reading this sensor is the same as reading a potentiometer.

  • Give a name to the analog pin that listens to SIG:
const int UV_SIG_PIN = A0;
  • Read the raw value. With the default 10-bit setting, the Giga returns 0 to 1023:
int adcValue = analogRead(UV_SIG_PIN);
  • Turn it into volts. The analog pins of the Giga measure from 0V up to 3.3V:
float sigVolts = adcValue * 3.3 / 1023.0;
  • Make a rough UV index from the voltage:
float uvIndex = sigVolts / 0.1;

Arduino Giga R1 WiFi Code - GUVA-S12SD Raw Value and Voltage

The first sketch is a check of the wiring. Once per second it prints two things: the number that analogRead() gives back, and the same reading as a voltage.

/* * This Arduino Giga R1 WiFi code was developed by newbiely.com * * This Arduino Giga R1 WiFi code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-giga/arduino-giga-r1-wifi-guva-s12sd-uv-sensor */ // Arduino Giga R1 WiFi - read the GUVA-S12SD UV sensor // Sensor VCC -> 3.3V, GND -> GND, SIG -> A0 // No library needed. const int UV_SIG_PIN = A0; // Giga analog pin wired to the SIG pin of the UV sensor const float ADC_REF = 3.3; // Giga analog pins measure 0 to 3.3V const int ADC_MAX = 1023; // default 10-bit reading: 0 to 1023 void setup() { Serial.begin(9600); } void loop() { int adcValue = analogRead(UV_SIG_PIN); // raw number from the ADC float sigVolts = adcValue * ADC_REF / ADC_MAX; // turn it into volts Serial.print("ADC: "); Serial.print(adcValue); Serial.print(" | SIG: "); Serial.print(sigVolts, 3); // 3 digits after the point Serial.println(" V"); delay(1000); // one line per second }

Detailed Instructions

Follow these instructions step by step:

  • First time with the Giga? Set up its board package with the Arduino Giga R1 WiFi getting started guide.
  • Wire the components according to the provided diagram: SIG to A0, GND to GND, VCC to 3.3V.
  • Plug the Giga R1 WiFi into your computer with the USB Type-C cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino Giga R1 WiFi board (e.g., Arduino Giga R1 WiFi) and COM port.
  • Paste the code above into the editor and click Upload.
  • Open the Serial Monitor and set it to 9600 baud.
  • Watch a few lines on your desk, then carry the board (on a laptop) out into direct sunlight with the white square facing the sky.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Giga R1
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Giga R1' on 'COM15')
New Line
9600 baud
ADC: 2 | SIG: 0.006 V ADC: 3 | SIG: 0.010 V ADC: 2 | SIG: 0.006 V ADC: 6 | SIG: 0.019 V ADC: 108 | SIG: 0.348 V ADC: 177 | SIG: 0.571 V ADC: 186 | SIG: 0.600 V ADC: 183 | SIG: 0.590 V ADC: 189 | SIG: 0.610 V
Ln 11, Col 1
Arduino Giga R1 on COM15
2

The first lines are from indoors: just a few counts, a few millivolts. That is normal, because room light holds almost no UV. Outside the value jumps to around 0.6V on a sunny afternoon. If the number does not move at all in the sun, check that SIG really goes to A0 and not to a digital pin.

One count of the 10-bit reading is about 3.2mV, which is fine for a UV index. If you want finer steps, add analogReadResolution(12) to setup() and change 1023 to 4095 in the code.

Arduino Giga R1 WiFi Code - GUVA-S12SD UV Index Meter

Now let us make the numbers useful. This sketch reads A0 16 times and takes the average, so a passing cloud edge or a little electrical noise does not make the value jump. Then it divides the voltage by 0.1 to get the UV index and prints its WHO level name.

/* * This Arduino Giga R1 WiFi code was developed by newbiely.com * * This Arduino Giga R1 WiFi code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-giga/arduino-giga-r1-wifi-guva-s12sd-uv-sensor */ // Arduino Giga R1 WiFi - GUVA-S12SD UV sensor as a simple UV index meter // Sensor VCC -> 3.3V, GND -> GND, SIG -> A0 // UV index is an approximation for hobby use: about 1 point for every 0.1V on SIG. const int UV_SIG_PIN = A0; // Giga analog pin wired to the SIG pin const float ADC_REF = 3.3; // Giga analog pins measure 0 to 3.3V const int ADC_MAX = 1023; // default 10-bit reading: 0 to 1023 const int SAMPLES = 16; // readings averaged for one result // Read the SIG pin several times and return the average voltage float readUvVoltage() { long sum = 0; for (int i = 0; i < SAMPLES; i++) { sum += analogRead(UV_SIG_PIN); delay(5); } float avgAdc = (float)sum / SAMPLES; return avgAdc * ADC_REF / ADC_MAX; } // 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"; } void setup() { Serial.begin(9600); } void loop() { float sigVolts = readUvVoltage(); float uvIndex = sigVolts / 0.1; // every 0.1V is about 1 UV index point Serial.print("SIG: "); Serial.print(sigVolts, 2); Serial.print(" V -> UV index: "); Serial.print(uvIndex, 1); Serial.print(" ("); Serial.print(uvLevel(uvIndex)); Serial.println(")"); delay(1000); }

Detailed Instructions

  • Keep the same three wires.
  • Upload this sketch and open the Serial Monitor at 9600 baud.
  • Start in the shade, then step into full sun, then cover the sensor with your hand for a moment.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Giga R1
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Giga R1' on 'COM15')
New Line
9600 baud
SIG: 0.30 V -> UV index: 3.0 (Moderate) SIG: 0.35 V -> UV index: 3.5 (Moderate) SIG: 0.66 V -> UV index: 6.6 (High) SIG: 0.70 V -> UV index: 7.0 (High) SIG: 0.75 V -> UV index: 7.5 (High) SIG: 0.85 V -> UV index: 8.5 (Very High) SIG: 0.02 V -> UV index: 0.2 (Low) SIG: 0.72 V -> UV index: 7.2 (High)
Ln 11, Col 1
Arduino Giga R1 on COM15
2

The shade gives a Moderate value, open sun gives High or Very High, and your hand drops it to Low at once. Compare your result with the UV index in a weather app for your town: if yours is always a little higher or lower, you can change the 0.1 in the code to match. Remember it is a guide for a hobby project, not a medical tool.

A next step for the Giga: show the UV level on a display, or switch on a buzzer when it goes above 6. For a sensor that measures visible light instead of UV, see the Arduino Giga R1 WiFi - Light Sensor tutorial.

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!