DEV Community

Cover image for Arduino Nano - GUVA-S12SD UV Sensor
Arduino ESP32 Raspberry Pi Tutorials
Arduino ESP32 Raspberry Pi Tutorials

Posted on Originally published at newbiely.com

Arduino Nano - GUVA-S12SD UV Sensor

The GUVA-S12SD is a small sensor that turns UV light into a voltage you can read with an Arduino Nano's analog input. No library needed, just analogRead() and a bit of math to turn the raw number into an approximate UV index, the same kind of number weather apps show you. It's a nice weekend build if you want a sense of how exposed to sun you actually are, not just how bright it looks outside.

The full tutorial, with every detail and the line-by-line code explanation, is on our site: Arduino Nano - GUVA-S12SD UV Sensor

What you need

Wiring

Arduino Nano - GUVA-S12SD UV Sensor wiring diagram

The module has three pins: SIG, GND and VCC. Connect VCC to the 3V3 pin on the Nano (5V also works, since the module accepts 2.5V to 5V), GND to GND, and SIG to analog pin A0. That's the whole circuit, and both sketches in this tutorial use it as-is. If you want sturdier connections than breadboard jumpers, a screw terminal expansion board for the Nano holds the same wiring without things working loose when you move the project.

How it works

The white square on the board is the GUVA-S12SD photodiode, and next to it sits a VLM358 op-amp. UV light hitting the photodiode lets through a tiny current, too weak to read directly, so the op-amp converts it into a voltage on SIG that rises as UV gets stronger. The photodiode only responds to UV-A and UV-B, so indoor light and daylight through a window barely register. You need direct sun, or a UV flashlight, to see a real reading. A common rule of thumb converts this into UV index: divide the SIG voltage in volts by 0.1.

Code

The first sketch is just for checking your wiring: once a second it reads A0 with analogRead(), prints the raw 0-1023 count, and converts it to volts using 5.0 as the reference, since the Nano's ADC always compares against 5V even when the sensor itself runs from 3V3. The second sketch builds on that by averaging 16 readings to smooth out jitter from passing clouds, dividing the result by 0.1 to get a UV index with one decimal place, and printing the matching WHO level name alongside it.

arduino-nano-guva-s12sd-uv-sensor.ino

/*
 * 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
}
Enter fullscreen mode Exit fullscreen mode

Things that go wrong

If your reading sits near 0V at your desk, that's expected, not a fault: ordinary room light and daylight through glass don't trigger the sensor. Take it outside into direct sun, ideally around noon, to see meaningful numbers. Treat the UV index you calculate as an estimate rather than a calibrated reading, since it comes from a simple rule of thumb rather than a lookup table.

Full tutorial

The complete tutorial - wiring diagram, code explanation and troubleshooting - is here: https://newbiely.com/tutorials/arduino-nano/arduino-nano-guva-s12sd-uv-sensor

Top comments (0)