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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4376|回復: 1
打印 上一主題 下一主題
收起左側

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

[復制鏈接]
跳轉到指定樓層
樓主


單片機源程序如下:
  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)
VL53L0X資料.rar (7.28 MB, 下載次數: 6)


評分

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

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
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 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 成人二区 | 精品婷婷 | 国产精品视频一区二区三区不卡 | 亚洲国产一区在线 | 亚洲精品国产综合区久久久久久久 | 欧美久久一区二区三区 | 欧美高清视频在线观看 | av一区二区在线观看 | 国产精品视频一区二区三 | 欧美精品欧美精品系列 | 久久久久国产一区二区三区 | 91大片| 精品免费国产 | av中文字幕在线观看 | 国产精品视频一区二区三区不卡 | 中文久久 | 中文字幕日韩欧美 | 久久久久久久夜 | 国产精品欧美一区二区三区不卡 | 亚洲二区在线 | 97色在线视频 | 中文字幕视频一区二区 | 羞羞视频网站 | 国产免费av网 | 亚洲精品av在线 | 一区二区三区在线免费看 | 国产不卡一区 | 国产精品伦理一区二区三区 | 亚洲乱码国产乱码精品精98午夜 | 99精品99久久久久久宅男 | 一区二区三区亚洲 | 日本不卡一区 | 日韩二区三区 | 精品中文字幕一区 | aaa一区 | 一区中文字幕 | 欧美精品久久久 | 精品视频一区二区三区在线观看 | 国产精品观看 | 婷婷成人在线 | 久久精品国产久精国产 |