Arduino uno UV Sensor
This project demonstrates how to read UV (Ultraviolet) sensor values using an Arduino Uno. UV sensors are commonly used to measure the intensity of ultraviolet radiation in a given environment. This project provides a basic setup to read UV sensor values and display them on the Serial Monitor.
How It Works
A UV sensor module is built around a photodiode whose response is deliberately restricted to the ultraviolet band. The two parts common in hobby kits are the GUVA-S12SD, sensitive from roughly 240–370 nm and covering both UVA and UVB, and the ML8511, which responds to 280–390 nm and outputs an analog voltage proportional to intensity.
Both report irradiance, measured in milliwatts per square centimetre, which is then mapped to the familiar UV Index. The GUVA carrier typically produces a voltage that rises with intensity and is converted with an approximately linear relationship across the normal outdoor range.
The Arduino Uno samples with a 10-bit ADC, so analogRead() returns 0–1023 across 5 V. A practical consequence is that the useful outdoor range — UV Index 0 to about 11 — spans only part of the ADC range, so resolution is adequate but not generous. The ML8511 is the better choice when accuracy matters, since it has an internal amplifier and a cleaner transfer characteristic.
Ordinary window glass blocks most UVB, so a sensor indoors behind glass reads far lower than one outdoors even in bright sunshine. That is physics, not a fault.
Components Needed
- Arduino Uno
- Ultraviolet Sensor module
- Arduino Uno
- USB cable for programming and power
- Arduino Uno
Wiring to the Arduino Uno
Connect OUT to A0, VCC to the 5 V rail and GND to ground. If you are using an ML8511, tie its EN pin high as well or the output stays dormant.
Many UV carriers output a maximum around 1 V even on a 5 V supply, which wastes most of a 5 V ADC range. Using the internal 1.1 V analog reference recovers that resolution.
Mount the sensing window facing the sky with nothing above it. A clear acrylic cover is acceptable only if it is UV-transmissive — standard acrylic and glass both attenuate heavily.
| Module pin | Arduino Uno pin | Function |
|---|---|---|
| OUT / SIG | A0 | Analog voltage proportional to UV intensity |
| VCC | 5V | Supply (3.3–5 V) |
| GND | GND | Common ground |
| EN (ML8511) | 5V | Enable — tie high for continuous operation |
Example Code
Converting a GUVA-S12SD reading into UV Index with averaging. Upload it with the board set to Arduino Uno and open the Serial Monitor at 9600 baud.
const int UV_PIN = A0;
const float VREF = 5.0;
const int ADC_MAX = 1023;
float readMilliVolts() {
long total = 0;
for (int i = 0; i < 32; i++) { total += analogRead(UV_PIN); delay(2); }
return (total / 32.0) * VREF * 1000.0 / ADC_MAX;
}
const char* riskLevel(float index) {
if (index < 3) return "Low";
if (index < 6) return "Moderate";
if (index < 8) return "High";
if (index < 11) return "Very High";
return "Extreme";
}
void setup() { Serial.begin(9600); }
void loop() {
float mv = readMilliVolts();
float uvIndex = mv / 100.0; // GUVA-S12SD: ~100 mV per index unit
Serial.print("UV: ");
Serial.print(mv, 0);
Serial.print(" mV Index ");
Serial.print(uvIndex, 1);
Serial.print(" (");
Serial.print(riskLevel(uvIndex));
Serial.println(")");
delay(2000);
}
Applications
A ultraviolet sensor turns up in a wide range of projects. These are the uses where it is the right choice rather than a compromise:
- Weather stations reporting a local UV Index alongside temperature and humidity
- Sun-exposure warnings for wearables and outdoor signage
- Verifying UV sterilisation lamps are actually emitting
- Monitoring UV curing in resin printers and coating processes
- Greenhouse and horticultural light monitoring
Working with the Arduino Uno
The Arduino Uno is built around the ATmega328P and runs on 5 V logic with 2 KB of SRAM and 32 KB of program flash. These details change how this circuit is wired and what the sketch can do, so they are worth stating plainly before you build.
The Uno runs at 5 V, so most hobby sensor modules connect directly with no level shifting.
With only 2 KB of SRAM, avoid large buffers and prefer the F() macro for constant strings.
The single hardware UART is shared with the USB connection, so heavy Serial printing competes with uploads.
| Arduino Uno characteristic | Value | Why it matters here |
|---|---|---|
| Logic voltage | 5 V | Matches most hobby modules directly |
| ADC resolution | 10-bit (0–1023) | Sets how finely an analog reading can be resolved |
| Analog inputs | A0–A5 (six channels) | Determines how many analog sensors can share the board |
| PWM outputs | D3, D5, D6, D9, D10 and D11 | Needed for brightness, speed and tone control |
| I²C pins | A4 (SDA) and A5 (SCL) | Fixed by hardware — wiring copied from another board may not match |
| Interrupt pins | D2 and D3 only | Required for counting fast or asynchronous events |
| Serial | a single hardware UART shared with USB | Monitor runs at 9600 baud by default |
Troubleshooting
Most problems with this module fall into a handful of categories. Work through these before suspecting the part itself:
- The reading is near zero outdoors — the sensor is behind glass, which blocks UVB. Move it outside.
- The index seems far too high indoors — fluorescent and some LED lamps emit stray UV; compare against a known outdoor reading.
- Values are noisy — average heavily. UV changes slowly, so a 32-sample average costs nothing.
- Readings saturate at full scale in sunlight — the module output exceeds the ADC reference; add a divider or choose a lower reference.
- Code written for an ESP board gives odd analog values — the Arduino Uno uses a 10-bit ADC returning 0–1023; rescale any constant taken from a 12-bit example.
- An I²C sensor is not found after copying wiring from another Arduino — on the Arduino Uno I²C is on A4 (SDA) and A5 (SCL).
Taking It Further on the Arduino Uno
Once the basic reading works, where you go next depends very much on which board you are using. These are the directions that suit the Arduino Uno specifically:
The Uno’s shield ecosystem is its real advantage. Once the circuit works on a breadboard, a prototyping shield turns it into something permanent that still stacks with a data-logging or Ethernet shield without rewiring.
Logging to an SD card via a shield is the natural next step, since the Uno has no onboard storage and no network. Timestamp each reading with a DS3231 real-time clock so the log survives power cuts with correct times.
Because SRAM is limited to 2 KB, keep logged strings short and write them out immediately rather than buffering. Building a long String in memory is the most common cause of an Uno sketch that runs for hours and then freezes.
Notes and Practical Limits
UV Index is defined for sunlight. Pointing one of these sensors at an artificial UV source gives a number, but calling it a UV Index is meaningless — the spectral weighting does not apply.
Readings drift as the sensor window ages and clouds with prolonged exposure. For long-running installations, plan to replace the sensor periodically rather than trusting a years-old calibration.