当前位置:网站首页>Ultrasonic distance meter based on 51 single chip microcomputer
Ultrasonic distance meter based on 51 single chip microcomputer
2022-07-04 14:28:00 【toyjis】
The project is based on HC-SR04 Range finder of ultrasonic sensor , Use digital tube to display distance . The ranging range is 2cm-400cm, Use timer 0 Interrupt setting the sensor measurement frequency , Every time 200ms Refresh the data once .
HC-SR04 It is a common ultrasonic sensor , It is often used in the ranging of smart cars , Avoiding obstacles , Blind crutches and other fields ; This module directly integrates the ultrasonic transmitter 、 Receiver and control circuit , You can work directly by plugging it in , There is no need to connect the drive circuit .
HC-SR04 How it works :
1、 Use a pin of the MCU to send at least 10us High level TTL Pulse signal to module Trig Pin , Used to trigger the operation of the module ( The code is embodied as the start ranging function ).
2、 After the module detects the trigger signal , Will automatically send 8 individual 40khz The square wave , Then automatically switch to monitoring mode , Monitor whether there is signal return .
3、 If a signal returns , By module Echo The pin will output a high level , The duration of the high level is the time from the ultrasonic wave is emitted to the time it returns ( The code is embodied in the function of getting distance ).
This design does not use a simple delay function , Instead, the timer interrupt is used to control the frequency of ranging , This ensures that the sensor has enough time to receive data 、 Processing data .
The simulation diagram of the system is as follows :
It's still drawn PCB Territory , This drawing is for in-line devices PCB, The patch device version will be added later , In this way, it can be made into a small range finder .
Part of the code is shown below , Code according to HC-SR04 Instructions for writing
int getdistance(void)
{
start();
while(!ECHO);
TR1=1;
while(ECHO);
TR1=0;
time=TH1*256+TL1;
TH1=0;
TL1=0;
s=(time*1.7)/100+1; // Measured cm
if(flag==1||(s>700))
{
flag=0;
s=0;
return s;
}
return s;
}
void main()
{
init();
while(1)
{
display(distance);
}
}
** Resources include :keilC The language code +Proteus Simulation schematic +ad Schematic diagram PCB+ Product specification **
边栏推荐
- Stm32f1 and stm32subeide programming example -max7219 drives 8-bit 7-segment nixie tube (based on GPIO)
- LiveData
- 数据埋点的一些问题和想法
- Compile oglpg-9th-edition source code with clion
- R语言使用lattice包中的bwplot函数可视化箱图(box plot)、par.settings参数自定义主题模式
- Detailed index of MySQL
- 商業智能BI財務分析,狹義的財務分析和廣義的財務分析有何不同?
- 利用Shap值进行异常值检测
- docker-compose公网部署redis哨兵模式
- Data center concept
猜你喜欢
The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese
leetcode:6110. 网格图中递增路径的数目【dfs + cache】
Detailed analysis of pytorch's automatic derivation mechanism, pytorch's core magic
第十七章 进程内存
WT588F02B-8S(C006_03)单芯片语音ic方案为智能门铃设计降本增效赋能
Scratch Castle Adventure Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
递增的三元子序列[贪心训练]
Leetcode 61: 旋转链表
MATLAB中tiledlayout函数使用
Detailed index of MySQL
随机推荐
An overview of 2D human posture estimation
Chapter 16 string localization and message Dictionary (2)
92.(cesium篇)cesium楼栋分层
NowCoder 反转链表
C # WPF realizes the real-time screen capture function of screen capture box
电商系统中红包活动设计
codeforce:C. Sum of Substrings【边界处理 + 贡献思维 + 灵光一现】
AI and Life Sciences
The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
R语言使用epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布
Matters needing attention in overseas game Investment Agency
实战解惑 | OpenCV中如何提取不规则ROI区域
Detailed index of MySQL
sql优化之explain
Sqlserver functions, creation and use of stored procedures
Excel快速合并多行数据
R语言使用epiDisplay包的followup.plot函数可视化多个ID(病例)监测指标的纵向随访图、使用stress.col参数指定强调线的id子集的颜色(色彩)
What is the difference between Bi financial analysis in a narrow sense and financial analysis in a broad sense?
关于miui12.5 红米k20pro用au或者povo2出现问题的解决办法
Leetcode t49: grouping of alphabetic words