极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13590|回复: 2

1602IIC显示+SR04超声波 测量距离

[复制链接]
发表于 2015-12-17 22:16:29 | 显示全部楼层 |阅读模式
本帖最后由 水镜 于 2015-12-17 22:23 编辑

1602IIC显示+SR04超声波 测量距离
受到温度影响,10度以下,会多出1CM。换个高精度的不知会如何?

Compatible with the Arduino IDE 1.0
Library version1.1
#include Wire.h
#include LiquidCrystal_I2C.h
#include DistanceSRF04.h
LiquidCrystal_I2C lcd(0x27,16,2);   set the LCD address to 0x27 for a 16 chars and 2 line display
DistanceSRF04 Dist;
int distance;

void setup()
{
    lcd.init();                       initialize the lcd
    lcd.backlight();
    Serial.begin(9600);
    Dist.begin(2,3);   
}

void loop()
{
    distance = Dist.getDistanceCentimeter();
    Print a message to the LCD.
    lcd.setCursor(0,0);光标从这里开始
    lcd.print(Distance is );
    lcd.setCursor(0,1);换行后显示距离
    lcd.print(distance);
    delay(500); make it readable
    lcd.clear();
  
}


用到     LiquidCrystal_I2C.h 和    DistanceSRF04.h这二个库。
SR04 接数字口2、3,1602 IIC 接SCL SDA。
IDE 1.0环境,高版本会出问题。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2015-12-18 07:55:13 | 显示全部楼层
声速随温度有变化。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2015-12-18 10:06:33 | 显示全部楼层
做个加温试验,看看变化过程,哈哈。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-15 13:34 , Processed in 0.072757 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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