Ramon Alexandro Castaneda Cerdan
Created March 24, 2017

Hyperion - UV levels

An incredible and simple project that allows the user to detect the UV radiation levels and share them with the community.

BeginnerProtip1 hour146
Hyperion - UV levels

Things used in this project

Story

Read more

Schematics

hyperion_50zcFhD0Th.fzz

Code

UV Intensity Code

Arduino
#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;

int UVOUT = A0; //Output from the sensor
int REF_3V3 = A1; //3.3V power on the Arduino board

const int colorR = 204;
const int colorG = 255;
const int colorB = 229;

void setup()
{
  Serial.begin(9600);

  pinMode(UVOUT, INPUT);
  pinMode(REF_3V3, INPUT);

  Serial.println("ML8511 example");
  
 // set up the LCD's number of columns and rows:
 lcd.begin(16, 2);
    
 lcd.setRGB(colorR, colorG, colorB);

  lcd.print("UV INT (mW/cm^2):");

    delay(1000);
}

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

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();
  
  lcd.setCursor(0, 1);
  lcd.print(uvIntensity);

  delay(500);
}

Credits

Ramon Alexandro Castaneda Cerdan

Ramon Alexandro Castaneda Cerdan

1 project • 0 followers
I'm just an international student and science enthusiast that hopes to change the world.

Comments