Projects / Pocket UV index meter

Pocket UV index meter

Beginner1.3 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. NANOVEML607011.7 mASSD1306

    Install the libraries

    VEML6070, SSD1306 and GFX.

  2. NANO

    Wire the sensor

    VCC, GND, SDA to A4, SCL to A5.

  3. NANO

    Wire the display

    Same four wires on the same pins.

  4. NANO11.7 mA

    Add the LED

    D8 through 220 ohm to GND.

  5. NANO

    Upload the sketch

    A band and a raw number appear.

  6. NANO

    Test indoors

    Expect Low near a window.

  7. NANO

    Test outdoors

    Point the sensor at the open sky.

  8. NANO

    Compare

    Check against a local UV forecast.

In short

How do you build a pocket UV index meter?

A UV sensor shows the sun exposure level with a coloured LED scale and an on-screen number. You need Arduino Nano, VEML6070 UV sensor, SSD1306 OLED Display, LED 5 mm red, Resistor 220 Ω and Breadboard 830 Tie Points. It takes 8 steps and about 75 minutes.

Level
Beginner
Time
About 75 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
UV sensor VCCNano 5VCheck your board label, many accept 3.3 V to 5 V
UV sensor GNDNano GNDCommon ground
UV sensor SDANano A4Shared I2C data
UV sensor SCLNano A5Shared I2C clock
OLED VCCNano 5VCheck the label on your module
OLED GNDNano GNDCommon ground
OLED SDA and SCLNano A4 and A5Same bus as the sensor
Red LED through 220 ohmNano D8 to GNDHigh exposure warning

Code

The VEML6070 measures ultraviolet light and gives a raw number over I2C. The more UV, the bigger the number, so a sunny outdoor reading is far higher than one in a bright room. The sketch sorts the number into five bands, Low to Extreme, and shows the band and the raw value on the display. The red LED lights from the High band upwards. The band limits come from the datasheet table for one integration time, so they are only approximate and depend on the resistor on your board and the setting in the code. Treat this as a learning meter, not as sun-safety advice: it does not know your skin type, the time you spend outside or how your sensor ages, and it cannot replace the official UV forecast. Glass and many plastics block UV, so the sensor must face the sky with nothing in front of it. Never look at the sun to aim it. Compare the readings with a local UV index forecast to see how well your bands match, and adjust the thresholds if you wish.

Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <Adafruit_VEML6070.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_VEML6070 uv;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const int RED_LED = 8;

// Approximate bands for the raw reading with the 1T integration time.
// Check the VEML6070 datasheet table for your resistor and integration time.
const char* band(uint16_t raw) {
  if (raw <= 560) return "Low";
  if (raw <= 1120) return "Moderate";
  if (raw <= 1494) return "High";
  if (raw <= 2054) return "Very high";
  return "Extreme";
}

void setup() {
  Serial.begin(9600);
  pinMode(RED_LED, OUTPUT);
  uv.begin(VEML6070_1_T);
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println("OLED not found"); while (1) { } }
  oled.setTextColor(SSD1306_WHITE);
}

void loop() {
  uint16_t raw = uv.readUV();
  const char* b = band(raw);
  digitalWrite(RED_LED, raw > 1120);       // red from High upwards

  oled.clearDisplay();
  oled.setTextSize(2);
  oled.setCursor(0, 0);
  oled.print(b);
  oled.setTextSize(1);
  oled.setCursor(0, 30);
  oled.print("Raw: "); oled.println(raw);
  oled.println("Indicative only");
  oled.display();

  Serial.println(raw);
  delay(1000);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Nano with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

0

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Dark roomRaw near zero, Low
Bright indoor lightLow
Outdoor sunHigher band, red LED may light
Hand over the sensorReading falls
Behind a windowMuch lower than outside

If it does not work

Always zero

Check SDA and SCL, and that the sensor faces the sky.

OLED blank

Try address 0x3D instead of 0x3C.

Readings jump around

Average several readings.

Sensor not found

Some boards use two I2C addresses, 0x38 and 0x39.

Low outdoors

Glass or a plastic cover is blocking the UV.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the pocket UV index meter?

Arduino Nano, VEML6070 UV sensor, SSD1306 OLED Display, LED 5 mm red, Resistor 220 Ω and Breadboard 830 Tie Points.

How long does the pocket UV index meter take to build?

About 75 minutes for a beginner maker, in 8 steps.

How do I know the pocket UV index meter works?

Dark room: Raw near zero, Low. Bright indoor light: Low. Outdoor sun: Higher band, red LED may light.

Always zero: what should I check?

Check SDA and SCL, and that the sensor faces the sky.

OLED blank: what should I check?

Try address 0x3D instead of 0x3C.

Readings jump around: what should I check?

Average several readings.

Sensor not found: what should I check?

Some boards use two I2C addresses, 0x38 and 0x39.