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

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产精品成人久久久久 | 国产精品高清在线 | 蜜桃av一区二区三区 | 四虎最新视频 | 国产免费播放视频 | 国产中文字幕av | 在线日韩福利 | 天天操天天射综合 | 韩国电影久久 | 国内精品久久久久 | 久久一久久 | 91天堂 | 午夜影院在线观看免费 | 日韩欧美国产精品 | 国产精品久久久久久久久久 | 久久999| 国产精品不卡视频 | 中文字幕一区二区三区四区五区 | 国产精品激情小视频 | 国产第一页在线观看 | 亚洲欧美v | av网站推荐| 日韩成人免费视频 | 国产精品自产拍在线观看蜜 | 久久久久久国产精品免费免费 | 国产激情视频网 | 亚洲国产激情 | 99精品欧美| 青青久久| 国产日韩精品一区 | 亚洲综合色丁香婷婷六月图片 | 337p日本欧洲亚洲大胆 | 91中文字幕 | av一区在线观看 | 国产亚洲精品美女久久久久久久久久 | 成人在线播放 | 日韩不卡一二区 | 一级毛片在线播放 | 午夜影院在线观看 | 亚洲综合无码一区二区 | 操操日|