Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » UV Sensor ML8511 & Arduino for UV Ray Intensity Meter
Arduino Projects

UV Sensor ML8511 & Arduino for UV Ray Intensity Meter

Mamtaz AlamBy Mamtaz AlamUpdated:August 22, 20221 Comment6 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
UV Sensor ML8511 Arduino
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this project, we are interfacing UV Sensor ML8511 with Arduino for measuring Ultra Violet Light Intensity in mW/cm^2. We will interface UV Sensor ML8511 with Arduino & LCD or OLED Display. UV Radiation or Ultraviolet light radiation occurs from 10nm to 400nm wavelength in the electromagnetic spectrum. So in order to get effective output in accordance with UV light the GY/ML8511 sensor from lapis semiconductor helps a lot. The ML8511 UV sensor detects 280nm – 390nm light in a better way, this wavelength is categorized as part of the UVB-burning rays spectrum and most of the UVA-tanning rays spectrum.

The ML8511 sensor is very easy to use. It outputs an analog voltage that is linearly related to the measured UV intensity (mW/cm2). If your microcontroller can do an analog to voltage conversion, then you can detect the level of UV. It has Low supply current of 300uA and a low standby current of 0.1A. It comes with Small and thin surface-mount package (4.0mm x 3.7mm x 0.73mm(0.16″ x 0.15″ x 0.03″), 12-pin ceramic QFN). The UV Sensor can be used in Triad Spectroscopy Sensor as well.


Bill of Materials

The following are the components required for interfacing UV sensor ML8511 with Arduino and 16X2 LCD Display. All these components can be purchased from Amazon.

S.N.Components NameQuantityPurchase Links
1Arduino Nano Board1Amazon | AliExpress
2ML8511 UV Sensor1Amazon | AliExpress
3Potentiometer 10K1Amazon | AliExpress
416x2 LCD Display1Amazon | AliExpress
50.96" OLED Display1Amazon | AliExpress
6Connecting Wires10Amazon | AliExpress
7Breadboard1Amazon | AliExpress




UV Sensor ML8511

Introduction:

ML8511

The ML8511 UV sensor is easy to use the ultraviolet light sensor. The MP8511 UV (ultraviolet) Sensor works by outputting an analog signal in relation to the amount of UV light that’s detected. This breakout can be very handy in creating devices that warn the user of sunburn or detect the UV index as it relates to weather conditions.

This sensor detects 280-390nm light most effectively. This is categorized as part of the UVB (burning rays) spectrum and most of the UVA (tanning rays) spectrum. It outputs an analog voltage that is linearly related to the measured UV intensity (mW/cm2). If your microcontroller can do an analog to digital signal conversion then you can detect the level of UV!


Block Diagram:

The UV Sensor ML8511 has Photodiode sensitive to UV-A and UV-B. Then it has an internal Embedded operational amplifier which will convert photocurrent to voltage output depending on the UV light intensity.

UV Sensor ML8511 Block Diagram

The output is always in the form of Analog voltage. Through the voltage output, it is easy to interface with external microcontrollers and ADC.

UV Characteristics:

The characteristics are drawn between output Voltage from the sensor with respect to UV intensity (mW/cm²) at constant VDD supply. The curves in different colors represent sensor operation in the different temperatures range.


Circuit Diagram: Interfacing UV Sensor ML8511 with Arduino

The circuit diagram for interfacing UV sensor ML8511 with Arduino and LCD Display is given below. The 16×2 LCD RS, EN, D4, D5, D6, D7 is connected to Arduino 12, 11, 5, 4, 3, 2 pins. LCD is supplied with 5V. It has 10K POT attached to LCD pin 3 to adjust the contrast.

The UV Sensor has 5 pins Vin, 3V3, GND, OUT, EN. Some of the modules don’t have Vin pin which is not used too. The EN pin and 3V3 pin are connected to the 3.3V pin of Arduino. The same 3V3 Pin is connected to Analog pin A1 which is used as a reference voltage. The out pin is connected to A0 of Arduino and GND to GND.

This connection for ML8511 is somewhat tricky. Analog to digital conversions rely completely on VCC. We assume this is 5.0V, but if the board is powered from USB this may be as high as 5.25V or as low as 4.75V. Because of this unknown window, it makes the ADC on the Arduino fairly inaccurate. To fix this, we use the very accurate onboard 3.3V reference (accurate within 1%). So by doing an analog to digital conversion on the 3.3V pin (by connecting it to A1) and then comparing this reading against the reading from the sensor, we can extrapolate a true-to-life reading, no matter what VIN is (as long as it’s above 3.4V).

Program/Source Code:

The ML8511 Arduino Source Code is given below. Copy the source code and upload it to the Arduino Board.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//Hardware pin definitions
int UVOUT = A0; //Output from the sensor
int REF_3V3 = A1; //3.3V power on the Arduino board
 
void setup()
{
  Serial.begin(9600);
  lcd.begin(16, 2);
 
  pinMode(UVOUT, INPUT);
  pinMode(REF_3V3, INPUT);
 
  Serial.println("ML8511 example");
  
}
 
void loop()
{
  int uvLevel = averageAnalogRead(UVOUT);
  int refLevel = averageAnalogRead(REF_3V3);
  
  //Use the 3.3V power pin as a reference to get a very accurate output value from sensor
  float outputVoltage = 3.3 / refLevel * uvLevel;
  
  float uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0); //Convert the voltage to a UV intensity level
 
  Serial.print("output: ");
  Serial.print(refLevel);
 
  Serial.print("ML8511 output: ");
  Serial.print(uvLevel);
 
  Serial.print(" / ML8511 voltage: ");
  Serial.print(outputVoltage);
 
  Serial.print(" / UV Intensity (mW/cm^2): ");
  Serial.print(uvIntensity);
  lcd.clear();
  lcd.print("UV Ray Intensity");
  lcd.setCursor(0, 1);
  lcd.print(uvIntensity);
  lcd.print(" mW/cm^2");
  
  Serial.println();
  
  delay(200);
}
 
//Takes an average of readings on a given pin
//Returns the average
int averageAnalogRead(int pinToRead)
{
  byte numberOfReadings = 8;
  unsigned int runningValue = 0;
 
  for(int x = 0 ; x < numberOfReadings ; x++)
    runningValue += analogRead(pinToRead);
  runningValue /= numberOfReadings;
 
  return(runningValue);
}
 
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}


Circuit Diagram: UV Sensor ML8511 with Arduino & OLED Display

The circuit diagram for interfacing UV sensor ML8511 with Arduino and OLED Display is given below. The OLED display used here is 0.96″ 128×64 I2C OLED display. So it’s connected to I2C Pins of Arduino. The SDA pin is connected to A4 of Arduino and SCL to A5.

The UV Sensor has 5 pins Vin, 3V3, GND, OUT, EN. Some of the modules don’t have Vin pin which is not used too. The EN pin and 3V3 pin are connected to the 3.3V pin of Arduino. The same 3V3 Pin is connected to Analog pin A1 which is used as a reference voltage. The out pin is connected to A0 of Arduino and GND to GND.

This connection for ML8511 is somewhat tricky. Analog to digital conversions rely completely on VCC. We assume this is 5.0V, but if the board is powered from USB this may be as high as 5.25V or as low as 4.75V. Because of this unknown window, it makes the ADC on the Arduino fairly inaccurate. To fix this, we use the very accurate onboard 3.3V reference (accurate within 1%). So by doing an analog to digital conversion on the 3.3V pin (by connecting it to A1) and then comparing this reading against the reading from the sensor, we can extrapolate a true-to-life reading, no matter what VIN is (as long as it’s above 3.4V).

Program/Source Code:

The ML8511 Arduino OLED Source Code is given below. Copy the source code and upload it to the Arduino Board.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 
int UVOUT = A0; //Output from the sensor
int REF_3V3 = A1; //3.3V power on the Arduino board
 
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
 
void setup()
{
  Serial.begin(9600);
  pinMode(UVOUT, INPUT);
  pinMode(REF_3V3, INPUT);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64)
  display.clearDisplay();
  Serial.println("ML8511 example");
  
}
 
void loop()
{
  int uvLevel = averageAnalogRead(UVOUT);
  int refLevel = averageAnalogRead(REF_3V3);
  
  //Use the 3.3V power pin as a reference to get a very accurate output value from sensor
  float outputVoltage = 3.3 / refLevel * uvLevel;
  
  float uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0); //Convert the voltage to a UV intensity level
 
  Serial.print("output: ");
  Serial.print(refLevel);
 
  Serial.print("ML8511 output: ");
  Serial.print(uvLevel);
 
  Serial.print(" / ML8511 voltage: ");
  Serial.print(outputVoltage);
 
  Serial.print(" / UV Intensity (mW/cm^2): ");
  Serial.print(uvIntensity);
  Serial.println();
 
  display.setCursor(20,0);  //oled display
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.println("UV Ray Intensity");
  
  display.setCursor(20,20);  //oled display
  display.setTextSize(3);
  display.setTextColor(WHITE);
  display.println(uvIntensity);
  
  display.setCursor(20,45);  //oled display
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.println("mW/cm^2");
  display.display();
  delay(300);
  display.clearDisplay();
}
 
//Takes an average of readings on a given pin
//Returns the average
int averageAnalogRead(int pinToRead)
{
  byte numberOfReadings = 8;
  unsigned int runningValue = 0;
 
  for(int x = 0 ; x < numberOfReadings ; x++)
    runningValue += analogRead(pinToRead);
  runningValue /= numberOfReadings;
 
  return(runningValue);
}
 
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}


Code Explanation:

C++
1
UV_Voltage / uvLevel = 3.3 / refLevel

uvLevel is what we read from the OUT pin. refLevel is what we read on the 3.3V pin. Solving for UV_Voltage, we can get an accurate reading.

C++
1
2
3
4
float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}

Mapping the UV_Voltage to intensity is straight forward. No UV light starts at 1V with a maximum of 15mW/cm2 at around 2.8V. Arduino has a built-in map() function, but map() does not work for floats, so we have a simple mapFloat() function.

C++
1
float uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0);

The following line converts the voltage read from the sensor to mW/cm2 intensity.


Video Tutorial

UV Index Meter with ML8511 UV Sensor & Arduino
Watch this video on YouTube.

You can make this project using ESP32 as well. Check here: UV Index Meter with ESP32 & UV Sensor ML8511. Similalry if you want to measure the Light Intensity and Illuminance, you can use TEMT6000 Ambient Light Sensor.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleInterface BMP180 Pressure & Temperature Sensor with Arduino
Next Article Control LED on Inernet using Arduino & ENC28J60 Ethernet Module

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 1 Comment

1 Comment

  1. alok Pandey on April 12, 2021 1:29 PM

    hello,
    i found ML8511 sensor module( ML8511AFCZ05BL ) obsolete part on oem website.
    kindly suggest any other sensor which can measure UV-A intensity in mw/cm2

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 16, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • IoT Based PM & Air Quality Monitoring System using ESP32
    IoT Based PM & Air Quality Monitoring System using ESP32
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • Designing of MPPT Solar Charge Controller using Arduino
    Designing of MPPT Solar Charge Controller using Arduino
  • RS-485 Simplex Communication with Arduino & MAX485
    RS-485 Simplex Communication with Arduino & MAX485
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.