Hi, I'm working on a project using the ML8511 UV sensor and found this tutorial. Could anyone explain how to get the code mentioned in the tutorial and how it works?
https://learn.sparkfun.com/tutorials/ml8511-uv-sensor-hookup-guide/all
Hi, I'm working on a project using the ML8511 UV sensor and found this tutorial. Could anyone explain how to get the code mentioned in the tutorial and how it works?
https://learn.sparkfun.com/tutorials/ml8511-uv-sensor-hookup-guide/all
The code maintains a moving average reading by periodically reading the sensor and converts that moving average to a UV index.
The code is on the page you linked to. Just click "copy code" and paste it into a new sketch in your Arduino IDE.
PS: I've always found those UV index sensor projects to have an exceptionally high NSS-factor (No Shit, Sherlock). You squint at the little display because the light is so f*ing bright to see that it says "high UV". Well, NSS mate. I didn't need a UV sensor to work that one out.
You need also the following:
float outputVoltage = (averageAnalogPin(UV_PIN) * MAX_VOLT) / MAX_READ;
P.S.
MAX_READ is the maximum value returned from ad ( 1023 for example )
MAX_VOLT is the corresponding input voltage ( 5V for example )
You don't even need the mapfloat function you could use the predefined map function ( afterall uv index is an integer value ), but in this case you have to map the ad reading ( without voltage conversion )
ADDITION
Only one more thing: the below image shows the relation of output voltage to UV intensity in mW/cm2 ( not to UVI ), I modified the previous text
Thank you for the explanation! I’ll try the code in my project. I’m curious, do you think this sensor is accurate for measuring sunlight UV and useful for outdoor monitoring? Thanks again!
The maximum error will be around +/- 0.6%
FYI: you can compute the UV using the following formula instead of the mapfloat
float uvIntensity = (outputVoltage - 1.0) * 10.0 / 1.2;
The datasheet it quite 'scarce of data', only two graphs, no min/max, error...
The GUVA-S12SD ( which is another low cost uv diode ) in contrast, is much more informative, giving also long term figures.
So can't say nothing ( but 'a measure' is better than nothing ).
Only add that I searched for an integrated sensor that gives the uvi reading ( not that simple to compute for a consumer product ), and found that previous products publicized to measure uv index are now 'obsoleted' ( I think because the value they calculate is not-so reliable )
What is 1.0 , 10.0 and 1.2?
do you think ML8511 still relate to measure uv in this day?
What is 1.0 , 10.0 and 1.2?
It's from the equation that defines the ML8511 output. It's a simple straight line y=mx+b
where y is the voltage and x is the UV and m is the slope.
m=1.2V/10UV and b=1
Depends on what you need the data for. But let's say "yes". Making a significant increase in accuracy would constitute a massive jump in complexity, so I'd just go with what this sensor gives you and not worry about it.
Btw, one of the main determinants of how useful the data are will not be the sensor as such, but which direction you point it in and whether you use any materials to shield it from rain etc.
I just wanna measure the sun uv index than make a predict,
I just wanna measure the sun uv index than make a predict,
So what is the problem?
You have the module and the code, what else do you need?
As I said the uv index is not easily calculated.
The uv sensor ( or the array of sensors ) should have a response similar to the erithema curve shown below, for example it should have a response at 300nm that is 1000 times the response at 325nm and 10000 times the response at 400nm ( quite different from the response of the ML8511 ).
So strictly speaking you can't use the ml8511 to calculate uvi, but with certain assumptions it can be used to 'estimate' it.
isn't 1V to 2.8V?
and actualy how the manual formula for float uvIntensity?
I need manual formula from that code to explain in my presentation
Not sure to understand... but it is a line ( the relation shown in the graph )
y = uv intensity
x = voltage
solve equation:
y = mx + b
knowing that:
y1 = 0 with x1 =0.99
y2 = 15 with x2 =2.8
I gave it to you in post #5 and #10
It's just the equation of a straight line.
What don't you understand?