找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索

【Arduino】168種傳感器系列實(shí)驗(yàn)(154)---ML8511紫外線傳感器

查看數(shù): 5976 | 評(píng)論數(shù): 28 | 收藏 0
關(guān)燈 | 提示:支持鍵盤翻頁(yè)<-左 右->
    組圖打開中,請(qǐng)稍候......
發(fā)布時(shí)間: 2020-4-14 13:27

正文摘要:

37款傳感器與模塊的提法,在網(wǎng)絡(luò)上廣泛流傳,其實(shí)Arduino能夠兼容的傳感器模塊肯定是不止37種的。鑒于本人手頭積累了一些傳感器和執(zhí)行器模塊,依照實(shí)踐出真知(一定要?jiǎng)邮肿觯┑睦砟,以學(xué)習(xí)和交流為目的,這里準(zhǔn)備 ...

回復(fù)

ID:763174 發(fā)表于 2021-4-19 19:19
親,焊接ML8511芯片的溫度應(yīng)該控制在什么范圍,該正向焊還是反向焊接呢
ID:513258 發(fā)表于 2020-12-26 11:17
  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料代碼+圖形編程+仿真編程)
  3.   實(shí)驗(yàn)一百五十四:ML8511紫外線傳感器模塊  模擬量輸出UV Sensor Breakou

  4.   實(shí)驗(yàn)接線
  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.   實(shí)驗(yàn)之二:串口顯示ML8511紫外線傳感器數(shù)值(帶3.3V基準(zhǔn)校準(zhǔn))
  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. }
復(fù)制代碼


ID:513258 發(fā)表于 2020-12-25 20:06
  1. /*
  2.   【Arduino】168種傳感器模塊系列實(shí)驗(yàn)(資料代碼+圖形編程+仿真編程)
  3.   實(shí)驗(yàn)一百五十四:ML8511紫外線傳感器模塊  模擬量輸出UV Sensor Breakou
  4.   接線
  5.   ML8511             arduino uno
  6.   VCC----------------------VCC
  7.   OUT----------------------A0
  8.   GND----------------------GND
  9.   實(shí)驗(yàn)之一:串口顯示ML8511紫外線傳感器數(shù)值
  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.     }
復(fù)制代碼


ID:513258 發(fā)表于 2020-5-19 20:32

謝謝鼓勵(lì)
ID:347384 發(fā)表于 2020-5-12 21:18
支持!!!!!!!!!!!!!

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表