I've got a Grove UV Sensor connected to a grove shield connected to an UNO. I've been getting readings but Im doubting the veracity of them given that the numbers are sometimes high at night or low in the day.
Here is the sketch:
float uvindex; // Store UV - UV Sensor
void setup(){
Serial.begin(9600);
}
void loop(){
SampleUV();
delay(15000);
}
void SampleUV(){
Serial.println("Sampling UV");
int sensorValue;
long sum=0;
for(int i=0;i<1024;i++)
{
sensorValue=analogRead(A0);
sum=sensorValue+sum;
delay(2);
}
sum = sum >> 10;
Serial.print("The UV voltage value:");
Serial.print(sum*4980.0/1023.0);
Serial.print(" mV");
delay(20);
Serial.print("UVIndex is: ");
uvindex = (307*(sum*4980.0/1023.0))/200; //mW/m2 -> W/m2
Serial.println(uvindex);
Serial.print("n");
}
Now its true that today was a cloudy day, but sunset is at 530pm, 1730hrs. It wouldnt be possible to get readings of 1479 and 1472 at 1741hrs and 1841hrs. This happens all the time. So Im wondering if anyone has had any experience with the Grove UV sensor.
I just took my sensor and moved it to the only thing on the Grove shield on the A0 pin. Its in a room with a skylight, a large 3mx3m window and another window.
The sketch is below and the results are as follows. Its night time right now:
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
float uvindex; // Store UV - UV Sensor
void setup() {
Serial.begin(9600);
delay(3000);
}
void loop() {
// Call both methods to see the difference
tzviForum();
delay(3000);
SampleUVAlarm();
delay(3000);
grovewiki();
delay(3000);
}
void tzviForum (){
int val=0;
val=analogRead(0); //reading the digital signal 0-1023
float mvolts = 0;
mvolts = val*4.9; // 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit
float illum = 0;
illum = mvolts/1000*307; //illumination intensity unit: mW/m2 for the combination strength of UV light with wavelength range: 240nm~370nm
Serial.print("TVZI Illum is:");
Serial.print(illum);
Serial.print(" mW/m2 - ");
Serial.print("250mW is about UV1");
Serial.println();
delay(20);
}
void grovewiki() {
int sensorValue;
long sum=0;
for(int i=0;i<1024;i++)// accumulate readings for 1024 times
{
sensorValue=analogRead(A0);
sum=sensorValue+sum;
delay(2);
}
long meanVal = sum/1024; // get mean value
Serial.print("Wiki Grove UV is:");
Serial.print((meanVal*1000/4.3-83)/21);// get a detailed calculating expression for UV index in schematic files.
Serial.print("\n");
delay(20);
}
//My UV Sketch
void SampleUVAlarm (){
int sensorValue;
long sum=0;
for(int i=0;i<1024;i++)
{
sensorValue=analogRead(A0);
sum=sensorValue+sum;
delay(2);
}
sum = sum >> 10;
Serial.print("SampleUVAlarm - voltage:");
Serial.print(sum*4980.0/1023.0);
Serial.print(" mV - ");
delay(20);
Serial.print("Grove UVIndex: ");
uvindex = (307*(sum*4980.0/1023.0))/200; //mW/m2 -> W/m2
Serial.println(uvindex);
}
That Groove board is a OPA333 UV sensors and a LMV358 OpAmp.
I must say that I'm not happy with that. If the OpAmp is a little wrong adjusted, the output can be anything.
I was already not happy with the code, but the hardware choice makes it worse.
Do you have a multimeter ? To compare the voltage that you measure at A0 with the voltage that the sketch shows ?
I don't have a UV sensor myself, so I don't know what values to expect.
At this moment, measuring the voltage from the sensor board is the only thing that I can think of. If that does not solve anything, then I don't know what to do
I put it in the sunlight this time and got some different numbers. So at least I know the numbers move appropriately. Here the sketch started in the shade and I moved it to the sun and you can see the jump in values.
TVZI Illum is:84.24 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:616.20
TVZI Illum is:84.24 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:272.61 mV - Grove UVIndex: 418.46
Wiki Grove UV is:649.43
TVZI Illum is:88.75 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:287.21 mV - Grove UVIndex: 440.87
Wiki Grove UV is:649.43
TVZI Illum is:88.75 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:287.21 mV - Grove UVIndex: 440.87
Wiki Grove UV is:649.43
TVZI Illum is:84.24 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:649.43
TVZI Illum is:90.26 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:277.48 mV - Grove UVIndex: 425.93
Wiki Grove UV is:671.57
TVZI Illum is:91.76 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:292.08 mV - Grove UVIndex: 448.35
Wiki Grove UV is:660.50
TVZI Illum is:90.26 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:292.08 mV - Grove UVIndex: 448.35
Wiki Grove UV is:660.50
TVZI Illum is:90.26 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:292.08 mV - Grove UVIndex: 448.35
Wiki Grove UV is:660.50
TVZI Illum is:88.75 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:287.21 mV - Grove UVIndex: 440.87
Wiki Grove UV is:649.43
TVZI Illum is:90.26 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:292.08 mV - Grove UVIndex: 448.35
Wiki Grove UV is:660.50
TVZI Illum is:90.26 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:287.21 mV - Grove UVIndex: 440.87
Wiki Grove UV is:649.43
TVZI Illum is:87.25 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:287.21 mV - Grove UVIndex: 440.87
Wiki Grove UV is:649.43
TVZI Illum is:90.26 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:292.08 mV - Grove UVIndex: 448.35
Wiki Grove UV is:660.50
TVZI Illum is:90.26 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:292.08 mV - Grove UVIndex: 448.35
Wiki Grove UV is:671.57
TVZI Illum is:91.76 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:296.95 mV - Grove UVIndex: 455.82
Wiki Grove UV is:671.57
TVZI Illum is:91.76 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:296.95 mV - Grove UVIndex: 455.82
Wiki Grove UV is:671.57
TVZI Illum is:91.76 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:296.95 mV - Grove UVIndex: 455.82
Wiki Grove UV is:671.57
TVZI Illum is:91.76 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:296.95 mV - Grove UVIndex: 455.82
Wiki Grove UV is:671.57
TVZI Illum is:93.27 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:296.95 mV - Grove UVIndex: 455.82
Wiki Grove UV is:671.57
TVZI Illum is:93.27 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:301.82 mV - Grove UVIndex: 463.29
Wiki Grove UV is:682.65
TVZI Illum is:93.27 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:301.82 mV - Grove UVIndex: 463.29
Wiki Grove UV is:682.65
TVZI Illum is:93.27 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:296.95 mV - Grove UVIndex: 455.82
Now I just need to know which should be the correct UV index number.
I just measured the voltage as suggested by Koepel. While the Serial Monitor was producing this:
TVZI Illum is:82.74 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:267.74 mV - Grove UVIndex: 410.98
Wiki Grove UV is:605.13
I took the + lead to the A0 pin on the UNO and the - lead to the GND pin. I got a solid steady reading of 280mV.
I tried the other pins just to make sure and the other analog pins read 900-1000mV against ground.
So I guess the voltage is correct as presented by SampleUVAlarm. If I use the relationship on the wiki page:
illumination intensity = 307 * Vsig
This means that 307 x 0.26774V = 82.196mW/m2. This is also pretty close to that reported by the SampleUVAlarm sketch. The only difference is in the UV index calculation. The SampleUVAlarm sketch reports it at 410.98 whereas the wiki sketch reports it as 605.13.
SampleUVAlarm apparently takes the 267.74mV, which would appear to be correct, and converts it to 410.98.
I just dont know if that value is correct because I cant compare it to the grovewiki formula.
On the wiki page there is a formula:
UV Index = illumination intensity / 200
If I plug in 82.196mW/m2 I get 0.41098, which is what SampleUVAlarm gives. That is no mystery since I originally got my formula from this page. But apparently it has since changed its content and now their formula yields an index of 605.13 which is quite different from the 410.98.
So yeah, if I change my current formula to match this new one, it will yield different results, but which one is correct...who knows?
At night, in darkness, the voltage is 267.74 mV (according to the sketch).
In sunlight, the voltage is 296.95 mV, that is only 30mV more. Perhaps the OpAmp is misconfigured, or the sensor board is faulty. Maybe the sensor itself is damaged.
According to the seeedstudio site, the output of the UV sensor should be zero when there is no UV light. So there should be no offset.
You measure 280mV, and the sketch shows 267.74 mV. That is close, but it should be more accurate.
It is probably because almost every calculation in the sketch is wrong.
I'm sorry, but I don't know how to get accurate values. The best thing that you can do is to throw this sensor away (or try to return it, because it is faulty), forget about it, and start all over with a new normal good UV sensor from Adafruit or Sparkfun. I'm very serious, get rid of this sensor.
No, those readings were during the day. Cloudy day yesterday when I got 267.74, the same today when it was sorta cloudy and it peaked at 301 in late day sunlight.
Although I just took the readings right now at night and they are 262.87.
Ok, I feel silly. I was reading the thread and it caught my attention where you (Koepel) asked where the sensor is and how its NOT supposed to be in direct sunlight. Where it wasnt in direct sunlight. Originally, it was in an acrylic box sticking out the side of my house wall. It was only really meant to read uvindex at noon, maybe 11a-1p, because im only interested in the max uv reading which is where the sun is directly overhead or thereabout. It could actually be in the morning around 10am, but 11-1p was a good enough window for me. My apt is next to another apt so that wall gets shade in the morning up until 11am and again after 1pm.
A couple of days ago when I took it down for investigating the readings because they were off, I had it in my studio which has a skylight, also of acrylic, and thats when i was getting readings of 82 illumination and 267mV.
So today I came home and it was nice and sunny, although it was 3pm. I took some readings in my studio thru the skylight and got the same as yesterday:
TVZI Illum is:85.75 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:277.48 mV - Grove UVIndex: 425.93
Wiki Grove UV is:627.28
TVZI Illum is:85.75 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:272.61 mV - Grove UVIndex: 418.46
then I decided to take it outside to the backyard, in direct sun, and I got these readings:
TVZI Illum is:822.85 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:4254.66 mV - Grove UVIndex: 6530.91
Wiki Grove UV is:11280.65
TVZI Illum is:1534.39 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:4960.53 mV - Grove UVIndex: 7614.41
Wiki Grove UV is:8844.33
TVZI Illum is:1277.15 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:3724.05 mV - Grove UVIndex: 5716.41
Wiki Grove UV is:926.28
TVZI Illum is:126.36 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:399.18 mV - Grove UVIndex: 612.74
Wiki Grove UV is:782.32
TVZI Illum is:688.97 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:627.98 mV - Grove UVIndex: 963.94
Wiki Grove UV is:1258.51
TVZI Illum is:168.48 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:501.41 mV - Grove UVIndex: 769.66
Wiki Grove UV is:3462.27
TVZI Illum is:1534.39 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:4824.22 mV - Grove UVIndex: 7405.18
Wiki Grove UV is:11280.65
TVZI Illum is:1534.39 mW/m2 - 250mW is about UV1
SampleUVAlarm - voltage:4960.53 mV - Grove UVIndex: 7614.41
So clearly the acrylic makes a difference. At the time of these readings, the weather.com UV index reading shows 6/10, which seems consistent with the Grove UVIndex of 5, 6 or even 7.
The only problem now is, which is the correct UVIndex reading, Grove UVIndex or Wiki Grove? As stated above Grove UVIndex is around 5-7, which is close to the weather.com reported of 6. The other Wiki Grove oscillated between 3-11, which is much less precise. NOTE: The drop in voltage or illumination in the middle of the readings was due to me fiddling with the positioning of the sensor.
The only problem now is, which is the correct UVIndex reading, Grove UVIndex or Wiki Grove?
I would suggest trying to determine where the WiKiGrove sensor station is located and taking a field trip.
I had to do the same with my BMP180... field trip to the local airport. Once you have one sensor calibrated, you can do your own calibration if you need to replicate the project.
I now track the published webportal results right on or no more difference than 0.01 InHg.
Well Im in Honduras so Im not sure it would be very feasible. But I get your point.
I did some googling and discovered that acrylic indeed is made to block out UV light and doesnt block it only if you buy special acrylic designed to specifically LET IN UV light.
So I have to redesign my acrylic box to fit my needs. Im thinking of drilling a hole on the top of the box, fixing the UV sensor right over the hole and covering it with some sort of small glass cup facing down, sealed with silicone to protect from rain.
So Ill do some testing today to determine how and which glass cups affect UV measurements.
I still have doubt if the Grove sensor can measure the UV from direct sunlight.
To measure direct sunlight, mostly a solar cell is used (for normal light of course), or else a sensor under a spherical cap that dims the sunlight and spreads the light nicely over the sensor. I tried to find how wheater stations measure the UV light with what sensor, but I could not find it.
Then there is also the problem of the offset. I think the Grove UV sensor should output 0V when there is no UV light.
Well I found an old picture frame with a glass cover of the perfect size. Tomorrow I'll take out a rectangle from the top of my acrylic box and deal the glass cover over it.
Well I'll test the glass over the uv sensor first to make sure before cutting up my acrylic box.