< >
Home » Arduino光线传感器 » Arduino光线传感器-UV Sensor V1.0-ML8511紫外线传感器

Arduino光线传感器-UV Sensor V1.0-ML8511紫外线传感器

外观

外观

概述

  • 该模块采用了通用的ML8511 UV传感器原件,可以用来检测室内或室外的紫外线密度。
  • 通过将光电流转化成电压的原理来检测UV强度,同时非常适合被被外部电路所采用。
  • 该模快还具备省电模式可达0.1uA,适合在智能可穿戴和手机等设备上使用。

应用

  • 紫外线等级监视器
  • 环境监测仪、气象站
  • DIY紫外线互动装置

技术规格

  • 工作电压:DC 5V
  • 工作温度:-20~70°C
  • 敏感区域:UV-A,UV-B
  • 敏感波长: 280-390nm
  • 模块尺寸:30 x 22mm

连接示意图

连接图
紫外线传感器连接示意图

ML8511 UV等级图表

等级表
ML8511 UV等级图表

  • 从图表上可以看到紫外线输出电压映射到等级是一条直线,从1.0V开始,最大是2.8V(15mW/cm2)。
  • Arduino虽然有一个内置的函数map() function,但是map()是不能工作在浮点型的。这里要感谢Arduino社区开源奉献者才有了下面的一个简单的mapfloat()函数,方便我们使用。
//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;
}
  • 下面是将传感器读到的电压值转换成mW/cm2等级:
float uvIntensity = mapfloat(outputVoltage, 0.99, 2.8, 0.0, 15.0); //Convert the voltage to a UV intensity level

示例代码

/***************************************************
 * UV Sensor v1.0-ML8511
 * <....>
 ***************************************************
 * This example reads UV intensity from UV Sensor v1.0-ML8511.
 * 
 * Created 2014-9-23
 * By Phoebe <phoebe.wang@dfrobot.com>
 * Modified 2014-9-23
 * By Phoebe phoebe.wang@dfrobot.com>
 * 
 * GNU Lesser General Public License.
 * See <http://www.gnu.org/licenses/> for details.
 * All above must be included in any redistribution
 ****************************************************/

/***********Notice and Trouble shooting***************
 * 1.Connect ML8511 UV Sensor to Arduino A0
   <http://wiki.dfrobot.com.cn/index.php/%E6%96%87%E4%BB%B6:SEN0175_Diagram.png>
 * 2.This code is tested on Arduino Uno, Leonardo, Mega boards.
 ****************************************************/


int ReadUVintensityPin = A0; //Output from the sensor

void setup()
{
  pinMode(ReadUVintensityPin, INPUT);
  Serial.begin(9600); //open serial port, set the baud rate to 9600 bps
  Serial.println("Starting up...");
}

void loop()
{
  int uvLevel = averageAnalogRead(ReadUVintensityPin);

  float outputVoltage = 5.0 * uvLevel/1024;
  float uvIntensity = mapfloat(outputVoltage, 0.99, 2.9, 0.0, 15.0);

  Serial.print("UVAnalogOutput: ");
  Serial.print(uvLevel);

  Serial.print(" OutputVoltage: ");
  Serial.print(outputVoltage);

  Serial.print(" UV Intensity: ");
  Serial.print(uvIntensity);
  Serial.print(" mW/cm^2");

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

你可以用一个紫外LED灯或者在阳光下测试你的传感器,赶紧来测试看看你的周围的紫外线等级吧~

本文整理于DFRobot wiki

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: none