wulisys 发表于 2018-10-9 09:47:58

紫外线强度检测

本帖最后由 wulisys 于 2018-10-9 22:40 编辑

实验室里有汞灯,有的同学担心紫外线辐射,某宝上搜了下,买了个紫外线传感器做了个检测仪。
一直在论坛里逛,也分享点代码出来,没什么技术含量:lol

首先上传感器,不是广告啊!

UV指数,国际标准值


先上汞灯的测试结果吧,实际紫外线辐射可以忽略不计。


传感器接线很简单:
VCC-为电源正极输入口,接入3.3V-5V的电压;GND-GND为电源负极输入口;OUT-OUT为模拟信号输出口,链接MCU的I/O口;
数字7脚接了个按键,下拉电阻,按下第七脚高电平,切换“测量/自检”模式。
上代码:<p> //   紫外线传感器示例代码
//   检测波长:200-370nm
//   接线方式:
//      VCC-5V
//      GND-GND
//      OUT-Analog pin 0

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

//#define LOGO16_GLCD_HEIGHT 16 //定义显示高度
//#define LOGO16_GLCD_WIDTH16 //定义显示宽度

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
int test=1;

void setup()
{
Serial.begin(9600);// open serial port, set the baud rate to 9600 bps
   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);// initialize with the I2C addr 0x3D (for the 128x64)
// init done
pinMode(7,INPUT);
}

void loop()
{
int sValue;
String ss;

//按下按键test变量取反一次(数字脚7)
if (digitalRead(7)) {
    test=test*-1;}
   
//判断test状态,切换测试和自检模式
if (test==1) {
sValue = analogRead(0);//connect UV sensors to Analog 0
} else
{
    sValue=random(0,244);
}
ss=GetUVindex(sValue);//取得UV指数,string类型</p><p>

//以下串口输出
Serial.print("Value=");
Serial.print(sValue);//print the value to serial
Serial.print("UV=");
Serial.println(ss);

//以下OLED12864屏显示
display.clearDisplay();
//切记,OLED显示中不要有运算函数,会影响显示效果!
display.setTextSize(1);             //设置字体大小
display.setTextColor(WHITE);      //设置字体颜色白色
display.setCursor(0,0);             //设置字体的起始位置
if (test==1){
display.println("UV index Test(xubin)");//输出字符并换行
} else
{
   display.println("Self checking...");//输出字符并换行
}
display.println("");   
display.setTextSize(2);
display.print("UV:");
display.println(ss);
display.setTextSize(1);
display.println("");
display.print("Value=");
display.println(sValue);
display.println("");
display.print("wavelength:200-370nm");
display.display(); //显示以上
delay(300);      
}

//输出UV指数国际标准值1~11级,输出string类型
String GetUVindex(int value)
{
float uv;
if (Value<10) {uv=0;} else
if (Value>=10 && Value<=46) {uv=0+(Value-10)/36.0;} else
if (Value>=47 && Value<=65) {uv=1+(Value-47)/18.0;} else
if (Value>=66 && Value<=83) {uv=2+(Value-66)/17.0;} else
if (Value>=84 && Value<=103) {uv=3+(Value-84)/19.0;} else
if (Value>=104 && Value<=124) {uv=4+(Value-104)/20.0;} else
if (Value>=125 && Value<=142) {uv=5+(Value-125)/17.0;} else
if (Value>=143 && Value<=162) {uv=6+(Value-143)/19.0;} else
if (Value>=163 && Value<=180) {uv=7+(Value-163)/17.0;} else
if (Value>=181 && Value<=200) {uv=8+(Value-181)/19.0;} else
if (Value>=201 && Value<=221) {uv=9+(Value-201)/20.0;} else
if (Value>=222 && Value<=240) {uv=10+(Value-222)/18.0;} else
if (Value>241) {uv=12;}
char a[]="";
dtostrf(uv,2,1,a);
return(a)
}

</p>





wing 发表于 2018-10-9 11:11:13

哦哦,是模拟量的紫外线传感器,不错错,很有参考价值
我最近也看上了一个紫外线传感器,楼主的例子值得借鉴

迷你强 发表于 2018-10-12 14:33:50

然后测试结果呢? 比如全天的监测数据啥的。。。搞研究,装也要装的很专业才行啊。

wulisys 发表于 2018-10-15 19:00:07

测实验室汞灯的紫外线强度只有0.6,非常安全,图片老是提示尺寸超过,其实才几百K的图片,就是穿不上来。

catnull 发表于 2018-10-20 22:25:25

这传感器很有意思。学习了。关于探测光的传感器,可见光的传感器有哪些?
页: [1]
查看完整版本: 紫外线强度检测