久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4344|回復: 1
收起左側

基于arduino的VL53L0X模塊的測速測距并且在藍牙和lcd上顯示

[復制鏈接]
ID:363596 發表于 2018-7-12 01:21 | 顯示全部樓層 |閱讀模式
OHMX8OKNV161O4DNLIC9U.jpg

單片機源程序如下:
  1. /* This example shows how to get single-shot range
  2. measurements from the VL53L0X. The sensor can optionally be
  3. configured with different ranging profiles, as described in
  4. the VL53L0X API user manual, to get better performance for
  5. a certain application. This code is based on the four
  6. "SingleRanging" examples in the VL53L0X API.

  7. The range readings are in units of mm. */

  8. /*
  9.   LiquidCrystal Library

  10. Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
  11. library works with all LCD displays that are compatible with the
  12. Hitachi HD44780 driver. There are many of them out there, and you
  13. can usually tell them by the 16-pin interface.

  14. This sketch prints "Hello World!" to the LCD
  15. and shows the time.

  16.   The circuit:
  17. * LCD RS pin to digital pin 12
  18. * LCD Enable pin to digital pin 11
  19. * LCD D4 pin to digital pin 5
  20. * LCD D5 pin to digital pin 4
  21. * LCD D6 pin to digital pin 3
  22. * LCD D7 pin to digital pin 2
  23. * LCD R/W pin to ground
  24. * LCD VSS pin to ground
  25. * LCD VCC pin to 5V
  26. * 10K resistor:
  27. * ends to +5V and ground
  28. * wiper to LCD VO pin (pin 3)

  29. Library originally added 18 Apr 2008
  30. by David A. Mellis
  31. library modified 5 Jul 2009
  32. example added 9 Jul 2009
  33. by Tom Igoe
  34. modified 22 Nov 2010
  35. by Tom Igoe

  36. This example code is in the public domain.

  37. http://www.arduino.cc/en/Tutorial/LiquidCrystal
  38. */

  39. #include <Wire.h>
  40. #include <VL53L0X.h>
  41. #include <LiquidCrystal.h>

  42. #define LED 7

  43. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);// initialize the library with the numbers of the interface pins

  44. VL53L0X sensor;

  45. int t = 0;
  46. int spd = 0;
  47. int distance;
  48. int updistance;
  49. /*int rectification;
  50. int rectification1;

  51. //int table[28] = {};  3cm~31cm*/


  52. // Uncomment this line to use long range mode. This
  53. // increases the sensitivity of the sensor and extends its
  54. // potential range, but increases the likelihood of getting
  55. // an inaccurate reading because of reflections from objects
  56. // other than the intended target. It works best in dark
  57. // conditions.

  58. //#define LONG_RANGE


  59. // Uncomment ONE of these two lines to get
  60. // - higher speed at the cost of lower accuracy OR
  61. // - higher accuracy at the cost of lower speed

  62. //#define HIGH_SPEED
  63. #define HIGH_ACCURACY


  64. void setup()
  65. {
  66.   pinMode(LED,OUTPUT);
  67.   Serial.begin(9600);
  68.   Wire.begin();

  69.   sensor.init();
  70.   sensor.setTimeout(500);

  71.    // set up the LCD's number of columns and rows:
  72.   lcd.begin(16, 2);

  73. #if defined LONG_RANGE
  74.   // lower the return signal rate limit (default is 0.25 MCPS)
  75.   sensor.setSignalRateLimit(0.1);
  76.   // increase laser pulse periods (defaults are 14 and 10 PCLKs)
  77.   sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
  78.   sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
  79. #endif

  80. #if defined HIGH_SPEED
  81.   // reduce timing budget to 20 ms (default is about 33 ms)
  82.   sensor.setMeasurementTimingBudget(20000);
  83. #elif defined HIGH_ACCURACY
  84.   // increase timing budget to 200 ms
  85.   sensor.setMeasurementTimingBudget(200000);
  86. #endif


  87.   lcd.clear();//clear lcd
  88.   lcd.setCursor(0, 0);//get location (it is ok outside screen)0-15 inside screen
  89.   lcd.print(" AHU      XIN GE");
  90.   lcd.setCursor(0, 1);//get location (it is ok outside screen)0-15 inside screen
  91.   lcd.print("distance sensor");
  92.   delay(6000);
  93.   
  94. }

  95. void loop()
  96. {


  97.   
  98. //********************************************************************get distance start***************************************************************
  99.   
  100.   updistance = distance;
  101.   distance = sensor.readRangeSingleMillimeters();//get distance
  102. //********************************************************************get distance end********************************************************************


  103. //********************************************************************distance rectify & LED start**************************************************************                                                               
  104.   distance = distance-32;
  105.   if(distance >= 21 && distance <= 55)
  106.   {
  107.      distance = distance* 0.6050 + 13.3228 ;//matlab a = 0.6050    b = 13.3228
  108.      digitalWrite(LED,!digitalRead(LED));
  109.   }
  110.   else if(distance > 55 && distance <= 276)
  111.   {
  112.     distance = distance*1.0312  - 7.2051;//  1.0312   -7.2051
  113.     digitalWrite(LED,LOW);//LED turn off
  114.   }
  115.   else if(distance >= 277 && distance <= 295)
  116.   {
  117.      distance = distance* 1.0436 -8.0835 ;//matlab a = 1.0436  b =   -8.0835
  118.      digitalWrite(LED,!digitalRead(LED));//led twinkle
  119.   }
  120.   else
  121.   {
  122.     digitalWrite(LED,HIGH);//LED turn on
  123.   }
  124.   

  125.   //distance = distance*1.0296 - 6.8681;//matlab a = 1.0296 ,b = -6.8681
  126. //********************************************************************distance rectify & LED end**************************************************************


  127. //********************************************************************show distance start***************************************************************
  128.   lcd.clear();//clear lcd
  129.   lcd.setCursor(0, 0);//get location (it is ok outside screen)0-15 inside screen
  130.   lcd.print("distance:");
  131.   lcd.print(distance);
  132.   lcd.setCursor(14, 0);
  133.   lcd.print("mm");
  134.   
  135.   Serial.print("Distance: ");
  136.   Serial.print(distance);
  137.   Serial.print("mm");
  138.   if (sensor.timeoutOccurred())
  139.   {
  140.     Serial.print(" TIMEOUT");
  141.     lcd.print("TIMEOUT");
  142.   }
  143.   Serial.print("\t");
  144. //********************************************************************show distance end****************************************************************


  145. //********************************************************************show times start***************************************************************
  146.   lcd.setCursor(0, 1);//get location (it is ok outside screen)0-15 inside screen
  147.   lcd.print("T:");
  148.   lcd.print(t);
  149.   
  150.   t++;
  151.   if(t == 1000)
  152.   {
  153.     t = 0;
  154.   }
  155. //********************************************************************show times end***************************************************************


  156. //********************************************************************show speed start***************************************************************
  157.   spd = (updistance - distance)/0.213;
  158.   lcd.setCursor(6, 1);
  159.   lcd.print("V:");
  160.   lcd.print(spd);
  161.   lcd.setCursor(12, 1);
  162.   lcd.print("mm/s");
  163.   Serial.print("  ");
  164.   Serial.print("speed:");
  165.   Serial.print(spd);
  166.   Serial.print("mm/s \n");
  167. //********************************************************************show speed end***************************************************************

  168.   
  169.   
  170. }
復制代碼

所有資料51hei提供下載:


測距.zip (97.1 KB, 下載次數: 16)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

回復

使用道具 舉報

ID:363596 發表于 2018-7-12 01:23 | 顯示全部樓層
* LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 * LCD D4 pin to digital pin 5 * LCD D5 pin to digital pin 4 * LCD D6 pin to digital pin 3 * LCD D7 pin to digital pin 2 * LCD R/W pin to ground * LCD VSS pin to ground * LCD VCC pin to 5V * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3)
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 9porny九色视频自拍 | 日韩电影在线一区 | 日韩免费高清视频 | 99精品国产一区二区三区 | 亚洲成年影院 | 亚州成人| 亚洲精品第一国产综合野 | 真人一级毛片 | 91av视频在线观看 | 成人性视频在线播放 | 久久久久九九九女人毛片 | 狠狠躁夜夜躁人人爽天天高潮 | 国产精品久久久久久吹潮 | 亚洲国产精品视频 | 国产精品1区 | 欧美日韩成人 | 九色91视频 | 黄色综合 | 精品国产伦一区二区三区观看说明 | 成人在线视频看看 | 91在线网| 欧美日韩一区精品 | 中文字幕在线观看成人 | 国产一二区视频 | 亚州视频在线 | 99精品久久久久 | 99久久影院 | 欧美一级大黄 | 亚洲精品一区二区在线观看 | 久久久免费电影 | 成人免费av在线 | 久久久女| 日韩 欧美 综合 | 最新中文字幕在线 | 久久国产美女视频 | 一区二区三区四区在线 | 成人激情视频免费观看 | 欧美成年黄网站色视频 | 国产精品综合一区二区 | h小视频 | 国产一区二区免费 |