极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 17793|回复: 4

紫外线强度检测

[复制链接]
发表于 2018-10-9 09:47:58 | 显示全部楼层 |阅读模式
本帖最后由 wulisys 于 2018-10-9 22:40 编辑

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

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

UV指数,国际标准值


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


传感器接线很简单:
VCC-为电源正极输入口,接入3.3V-5V的电压;
GND-GND为电源负极输入口;
OUT-OUT为模拟信号输出口,链接MCU的I/O口;

数字7脚接了个按键,下拉电阻,按下第七脚高电平,切换“测量/自检”模式。

上代码:
  1. <p> //   紫外线传感器示例代码
  2. //   检测波长:200-370nm
  3. //   接线方式:
  4. //      VCC-5V
  5. //      GND-GND
  6. //      OUT-Analog pin 0

  7. #include <SPI.h>  
  8. #include <Wire.h>  
  9. #include <Adafruit_GFX.h>  
  10. #include <Adafruit_SSD1306.h>
  11. #define OLED_RESET 4  
  12. Adafruit_SSD1306 display(OLED_RESET);  
  13.   
  14. //#define LOGO16_GLCD_HEIGHT 16 //定义显示高度  
  15. //#define LOGO16_GLCD_WIDTH  16 //定义显示宽度

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

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

  27. void loop()
  28. {
  29.   int sValue;
  30.   String ss;
  31.   
  32.   //按下按键test变量取反一次(数字脚7)
  33.   if (digitalRead(7)) {
  34.     test=test*-1;}
  35.    
  36.   //判断test状态,切换测试和自检模式  
  37.   if (test==1) {
  38.   sValue = analogRead(0);//connect UV sensors to Analog 0  
  39.   } else
  40.   {
  41.     sValue=random(0,244);
  42.   }
  43.   ss=GetUVindex(sValue);  //取得UV指数,string类型</p><p>

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

  49. //以下OLED12864屏显示
  50.   display.clearDisplay();
  51.   //切记,OLED显示中不要有运算函数,会影响显示效果!
  52.   display.setTextSize(1);             //设置字体大小  
  53.   display.setTextColor(WHITE);        //设置字体颜色白色  
  54.   display.setCursor(0,0);             //设置字体的起始位置  
  55.   if (test==1){
  56.   display.println("UV index Test(xubin)");//输出字符并换行
  57.   } else
  58.   {
  59.    display.println("Self checking...");//输出字符并换行
  60.   }
  61.   display.println("");   
  62.   display.setTextSize(2);
  63.   display.print("UV:");
  64.   display.println(ss);
  65.   display.setTextSize(1);
  66.   display.println("");  
  67.   display.print("Value=");
  68.   display.println(sValue);
  69.   display.println("");
  70.   display.print("wavelength:200-370nm");  
  71.   display.display(); //显示以上
  72.   delay(300);      
  73. }

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

  95. </p>
复制代码






本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2018-10-9 11:11:13 | 显示全部楼层
哦哦,是模拟量的紫外线传感器,不错错,很有参考价值
我最近也看上了一个紫外线传感器,楼主的例子值得借鉴
回复 支持 反对

使用道具 举报

发表于 2018-10-12 14:33:50 | 显示全部楼层
然后测试结果呢? 比如全天的监测数据啥的。。。搞研究,装也要装的很专业才行啊。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-10-15 19:00:07 | 显示全部楼层
测实验室汞灯的紫外线强度只有0.6,非常安全,图片老是提示尺寸超过,其实才几百K的图片,就是穿不上来。
回复 支持 反对

使用道具 举报

发表于 2018-10-20 22:25:25 | 显示全部楼层
这传感器很有意思。学习了。关于探测光的传感器,可见光的传感器有哪些?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-27 02:51 , Processed in 0.046037 second(s), 21 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表