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 Name | Quantity | Purchase Links |
---|---|---|---|
1 | Arduino Nano Board | 1 | Amazon | AliExpress |
2 | ML8511 UV Sensor | 1 | Amazon | AliExpress |
3 | Potentiometer 10K | 1 | Amazon | AliExpress |
4 | 16x2 LCD Display | 1 | Amazon | AliExpress |
5 | 0.96" OLED Display | 1 | Amazon | AliExpress |
6 | Connecting Wires | 10 | Amazon | AliExpress |
7 | Breadboard | 1 | Amazon | AliExpress |
UV Sensor ML8511
Introduction:
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.
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:
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.
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.
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
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.
1 Comment
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