找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

【Arduino】168种传感器系列实验(154)---ML8511紫外线传感器

查看数: 6318 | 评论数: 28 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2020-4-14 13:27

正文摘要:

37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备 ...

回复

ID:763174 发表于 2021-4-19 19:19
亲,焊接ML8511芯片的温度应该控制在什么范围,该正向焊还是反向焊接呢
ID:513258 发表于 2020-12-26 11:17
  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
  3.   实验一百五十四:ML8511紫外线传感器模块  模拟量输出UV Sensor Breakou

  4.   实验接线
  5.   ML8511 / Arduino
  6.   3.3V = 3.3V
  7.   OUT = A0
  8.   GND = GND
  9.   EN = 3.3V
  10.   Arduino 3.3V = Arduino A1

  11.   实验之二:串口显示ML8511紫外线传感器数值(带3.3V基准校准)
  12. */

  13. //Hardware pin definitions
  14. int UVOUT = A0; //Output from the sensor
  15. int REF_3V3 = A1; //3.3V power on the Arduino board

  16. void setup()
  17. {
  18.   Serial.begin(9600);

  19.   pinMode(UVOUT, INPUT);
  20.   pinMode(REF_3V3, INPUT);

  21.   Serial.println("MP8511 example");
  22. }

  23. void loop()
  24. {
  25.   int uvLevel = averageAnalogRead(UVOUT);
  26.   int refLevel = averageAnalogRead(REF_3V3);

  27.   //Use the 3.3V power pin as a reference to get a very accurate output value from sensor
  28.   float outputVoltage = 3.3 / refLevel * uvLevel;

  29.   float uvIntensity = mapfloat(outputVoltage, 0.99, 2.9, 0.0, 15.0);

  30.   Serial.print("MP8511 output: ");
  31.   Serial.print(uvLevel);

  32.   Serial.print(" MP8511 voltage: ");
  33.   Serial.print(outputVoltage);

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

  36.   Serial.println();

  37.   delay(100);
  38. }

  39. //Takes an average of readings on a given pin
  40. //Returns the average
  41. int averageAnalogRead(int pinToRead)
  42. {
  43.   byte numberOfReadings = 8;
  44.   unsigned int runningValue = 0;

  45.   for (int x = 0 ; x < numberOfReadings ; x++)
  46.     runningValue += analogRead(pinToRead);
  47.   runningValue /= numberOfReadings;

  48.   return (runningValue);
  49. }

  50. //The Arduino Map function but for floats
  51. //From: http://forum.arduino.cc/index.php?topic=3922.0
  52. float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
  53. {
  54.   return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
  55. }
复制代码


ID:513258 发表于 2020-12-25 20:06
  1. /*
  2.   【Arduino】168种传感器模块系列实验(资料代码+图形编程+仿真编程)
  3.   实验一百五十四:ML8511紫外线传感器模块  模拟量输出UV Sensor Breakou
  4.   接线
  5.   ML8511             arduino uno
  6.   VCC----------------------VCC
  7.   OUT----------------------A0
  8.   GND----------------------GND
  9.   实验之一:串口显示ML8511紫外线传感器数值
  10. */

  11. int ReadUVintensityPin = A0; //Output from the sensor

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

  18.     void loop()
  19.     {
  20.       int uvLevel = averageAnalogRead(ReadUVintensityPin);

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

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

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

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

  30.       Serial.println();
  31.       delay(100);
  32.     }

  33.     //Takes an average of readings on a given pin
  34.     //Returns the average
  35.     int averageAnalogRead(int pinToRead)
  36.     {
  37.       byte numberOfReadings = 8;
  38.       unsigned int runningValue = 0;

  39.       for(int x = 0 ; x < numberOfReadings ; x++)
  40.         runningValue += analogRead(pinToRead);
  41.       runningValue /= numberOfReadings;

  42.       return(runningValue);

  43.     }

  44.     //The Arduino Map function but for floats
  45.     float mapfloat(float x, float in_min, float in_max, float out_min, float out_max)
  46.     {
  47.       return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
  48.     }
复制代码


ID:513258 发表于 2020-5-19 20:32

谢谢鼓励
ID:347384 发表于 2020-5-12 21:18
支持!!!!!!!!!!!!!

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

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