Problem with UV sensor
-
After some research i've found out that my UVM-30A is outputting 0-1V (as stated in the datasheet). The analog input on my nano pro however, expect 0-5V to calculate the 0-1170 analog value that is used for the UV calculation in the sketch (see: http://www.mysensors.org/build/uv)
Right now i'm multiplying the input times 5 to correct the issue. But I was wondering whether it is the sketch or my nano pro who is wrong here..
-
I was scratching my head over this problem last year, but found a solution that works for me.....Try this.....
sensorVal = analogRead(sensorPin); //The pin the UV sensor is connected to
sensorVal = constrain(sensorVal, 0, 1180);
sensorValue = map (sensorVal, 0, 246, 0, 1180); //sensorValue is the number you
//are looking forThen I did a look up for the UV index as follows......
if (sensValue >= 0 && sensValue <= 226)
uvVal = 0;
else if (sensValue >= 227 && sensValue <= 317)
uvVal = 1;
else if (sensValue >= 318 && sensValue <= 407)
uvVal = 2;
else if (sensValue >= 408 && sensValue <= 502)
uvVal = 3;
else if (sensValue >= 503 && sensValue <= 605)
uvVal = 4;
else if (sensValue >= 606 && sensValue <= 695)
uvVal = 5;
else if (sensValue >= 696 && sensValue <= 794)
uvVal = 6;
else if (sensValue >= 795 && sensValue <= 880)
uvVal = 7;
else if (sensorValue >= 881 && sensorValue <= 975)
uvVal = 8;
else if (sensValue >= 976 && sensValue <= 1078)
uvVal = 9;
else if (sensValue >=1079 && sensValue <=1169)
uvVal = 10;
else if (sensValue >= 1170)
uvVal = 11;And now I get the values I expect!
Look at the map function on the arduino page to see how it works!Skywatch
-
@skywatch said:
if (sensValue >= 0 && sensValue <= 226)
uvVal = 0;
else if (sensValue >= 227 && sensValue <= 317)
uvVal = 1;
else if (sensValue >= 318 && sensValue <= 407)
uvVal = 2;
else if (sensValue >= 408 && sensValue <= 502)
uvVal = 3;
else if (sensValue >= 503 && sensValue <= 605)
uvVal = 4;
else if (sensValue >= 606 && sensValue <= 695)
uvVal = 5;
else if (sensValue >= 696 && sensValue <= 794)
uvVal = 6;
else if (sensValue >= 795 && sensValue <= 880)
uvVal = 7;
else if (sensorValue >= 881 && sensorValue <= 975)
uvVal = 8;
else if (sensValue >= 976 && sensValue <= 1078)
uvVal = 9;
else if (sensValue >=1079 && sensValue <=1169)
uvVal = 10;
else if (sensValue >= 1170)
uvVal = 11;trivial, but this can be simplified like this:
if (sensValue <= 226) uvVal = 0; else if (sensValue <= 317) uvVal = 1; else if (sensValue <= 407) uvVal = 2; else if (sensValue <= 502) uvVal = 3; else if (sensValue <= 605) uvVal = 4; else if (sensValue <= 695) uvVal = 5; else if (sensValue <= 794) uvVal = 6; else if (sensValue <= 880) uvVal = 7; else if (sensorValue <= 975) uvVal = 8; else if (sensValue <= 1078) uvVal = 9; else if (sensValue <=1169) uvVal = 10; else uvVal = 11;
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login