Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15287

GYML8511 UV Sensor with Arduino Uno Problem

$
0
0

Hi! I'm part of a group doing a project for a physics lab class that's trying to use a GYML8511 UV Sensor with an Arduino Uno board to measure UV Intensity. We've found a sample hookup and code in various places, but our code consistently returns values way outside the parameters. None of us have any previous experience with Arduinos or C/C++, so we're really stumped. Additionally, all the sample hookups and other projects use a 4 pin ML8511 sensor versus our 5 pin GYML8511 sensor, though they seem to be just different models of the same thing and our hookup is the exact same.

The code we're using:

//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);

  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);

  Serial.println();

  delay(100);
}

//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);  
}

//The Arduino Map function but for floats
//From: http://forum.arduino.cc/index.php?topic=3922.0
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;
}

We found this code on both Wikipedia (I know) and SparkFun, as well as most other projects we looked at to compare ours to.

This is the sensor hookup we're using:

And this is the sensor we're using:

Here's how ours is hooked up:

These are the values we keep receiving from our code:
UVAnalogOutput: 649 OutputVoltage: 3.17 UV Intensity: 17.11 mW/cm^2
UVAnalogOutput: 649 OutputVoltage: 3.17 UV Intensity: 17.11 mW/cm^2
UVAnalogOutput: 649 OutputVoltage: 3.17 UV Intensity: 17.11 mW/cm^2
UVAnalogOutput: 649 OutputVoltage: 3.17 UV Intensity: 17.11 mW/cm^2
UVAnalogOutput: 648 OutputVoltage: 3.16 UV Intensity: 17.07 mW/cm^2
UVAnalogOutput: 649 OutputVoltage: 3.17 UV Intensity: 17.11 mW/cm^2
UVAnalogOutput: 649 OutputVoltage: 3.17 UV Intensity: 17.11 mW/cm^2

From reading other forum posts here and comments on similar projects, it sounds like this is a common issue, but the only real solution we've seen anyone reach is that they had defective sensors. We're really struggling with this one, and if that's the solution, then we can work with that. We're just hoping to figure it out at all at this point!!

I know this is a long post, so thanks for your time!

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 15287

Trending Articles