当前位置:网站首页>智能垃圾桶(四)——树莓派pico实现超声波测距(HC-SR04)
智能垃圾桶(四)——树莓派pico实现超声波测距(HC-SR04)
2022-06-29 11:10:00 【光追雨】
没带树莓派3B+回来,索性就用了pico实现
一、pico引脚展示

二、HC-SR04原理介绍
(1)采用 IO 触发测距,给至少10us 的高电平信号;
(2)模块自动发送8 个40khz 的方波,自动检测是否有信号返回;
(3)有信号返回,通过IO 输出一高电平,高电平持续的时间就是
(4)超声波从发射到返回的时间.测试距离=(高电平时间*声速(340M/S))/2;

三、实物引脚

四、代码实现
from machine import Pin
import utime
# 超声波测距,单位:厘米
def getDistance(trigger, echo):
# 产生10us的方波
trigger.low()
utime.sleep_us(2)
trigger.high()
utime.sleep_us(10)
trigger.low()
while echo.value() == 0:
start = utime.ticks_us()
while echo.value() == 1:
end = utime.ticks_us()
d = (end - start) * 0.0343 / 2
return d
# 主程序
trigger = Pin(18, Pin.OUT)
echo = Pin(26, Pin.IN)
while True:
distance = getDistance(trigger, echo)
print("距离:{:.2f} cm".format(distance))
utime.sleep(1)
五、实物展示


参考博客点击蓝字
边栏推荐
- 2022广西省安全员C证考试试题及模拟考试
- 【高并发】缓存思路
- Take another picture of cloud redis' improvement path
- Oracle NetSuite 助力 TCM Bio,洞悉数据变化,让业务发展更灵活
- 普通用户使用vscode登录ssh编辑root文件
- 基于鲲鹏开发套件实现x86平台到Kunpeng平台的源码迁移【玩转华为云】
- 什么是外链和内链?
- 2022 Guangxi provincial safety officer C certificate examination questions and mock examination
- [HBZ sharing] the principle of reentrantlock realized by AQS + CAS +locksupport
- Qt学习15 用户界面与业务逻辑的分离
猜你喜欢

Meichuang was selected as one of the first member units of the "business security promotion plan" of the ICT Institute

Oracle NetSuite 助力 TCM Bio,洞悉数据变化,让业务发展更灵活

Self-Improvement! Junior college "counter attack" master of Zhejiang University, 3 SCI, and finally become a doctor of Tsinghua University!
![[VTK] MFC grid editor based on vtk8.2](/img/c5/d0f070ccb819fc682855319b7415e0.png)
[VTK] MFC grid editor based on vtk8.2

跟着官方学电机,BLDC两种控制策略,学到即赚到

喜报|海泰方圆通过CMMI-3资质认证,研发能力获国际认可

又一所“省会大学”,来了!

杰理之关于 TWS 配对方式配置【篇】

Discussion on QT learning 10 message processing in QT

自动化测试摸索之路---准备工作
随机推荐
地平线开发板配置网段
Oracle expands distributed cloud services to bring comprehensive public cloud services to more customers
哈希Hash竞猜游戏系统开发详解技术丨哈希竞猜游戏系统开发方案解析
2022广西省安全员C证考试试题及模拟考试
Object 类——万类之父
matlab fmincon 精度,fmincon与quadprog误差
Qt学习03 Qt的诞生和本质
Take another picture of cloud redis' improvement path
2022 amination process test question simulation test question bank and online simulation test
Deep understanding of volatile keyword
合约量化交易系统玩法开发 (现成案例分析)
Opencv4.0 installation of raspberry pie for Xiaobai
Qt学习06 窗口部件及窗口类型
自动化测试摸索之路---准备工作
服务数百万开发者,首届 Techo Day 腾讯技术开放日发布 7 款“轻量级”产品
[HBZ sharing] the principle of reentrantlock realized by AQS + CAS +locksupport
美创入选信通院“业务安全推进计划”首批成员单位
Nature | biosynthetic potential of global marine microbiome
QT learning 11 string classes in QT
ES6 数组方法