当前位置:网站首页>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 **
边栏推荐
- R语言ggplot2可视化:gganimate包创建动态折线图动画(gif)、使用transition_reveal函数在动画中沿给定维度逐步显示数据
- opencv3.2 和opencv2.4安装
- R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graph, and uses the by parameter to specify the groupin
- Oppo find N2 product form first exposure: supplement all short boards
- The mouse wheel of xshell/bash/zsh and other terminals is garbled (turn)
- The implementation of OSD on rk1126 platform supports color translucency and multi-channel support for Chinese
- Nowcoder rearrange linked list
- Sqlserver functions, creation and use of stored procedures
- sql优化之查询优化器
- 测试流程整理(3)
猜你喜欢
随机推荐
The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?
Remove duplicate letters [greedy + monotonic stack (maintain monotonic sequence with array +len)]
Gorm read / write separation (rotation)
Popular framework: the use of glide
Chapter 17 process memory
架构方面的进步
LifeCycle
Why should Base64 encoding be used for image transmission
docker-compose公网部署redis哨兵模式
商业智能BI财务分析,狭义的财务分析和广义的财务分析有何不同?
第十六章 字符串本地化和消息字典(二)
Test process arrangement (3)
Leetcode 61: rotating linked list
Fs4059c is a 5V input boost charging 12.6v1.2a. Inputting a small current to three lithium battery charging chips will not pull it dead. The temperature is 60 ° and 1000-1100ma is recommended
迅为IMX6Q开发板QT系统移植tinyplay
MATLAB中tiledlayout函数使用
Golang uses JSON unmarshal number to interface{} number to become float64 type (turn)
Ml: introduction, principle, use method and detailed introduction of classic cases of snap value
AI and Life Sciences
Compile oglpg-9th-edition source code with clion



![递增的三元子序列[贪心训练]](/img/92/7efd1883c21c0e804ffccfb2231602.png)



![去除重複字母[貪心+單調棧(用數組+len來維持單調序列)]](/img/af/a1dcba6f45eb4ccc668cd04a662e9c.png)

