当前位置:首页 > 科学研究 > 电子编程 > 正文内容

Arduino Project 039 - Ultrasonic Distance Display

RonWang11个月前 (12-04)电子编程668

Ultrasonic sensors measure distance by sending and receiving the ultrasonic wave. The ultrasonic sensor has a sender to emit the ultrasonic waves and a receiver to receive the ultrasonic waves. The transmitted ultrasonic wave travels through the air and is reflected by hitting the Object. Arduino calculates the time taken by the ultrasonic pulse wave to reach the receiver from the sender.

Ultrasonic sensor and technology informatio link : Arduino Project 038 - Simple Ultrasonic Range HC-SR04

In the code, the “duration” variable stores the time taken by the sound wave traveling from the emitter to the receiver. That is double the time to reach the object, whereas the sensor returns the total time including sender to object and object to receiver. Then, the time taken to reach the object is half of the time taken to reach the receiver. 

Liquide crystal display coding , circuit and Schematic detail you can link  : Arduino Project 023 - Liquid Crystal Displays - Hello World!!!

Project 39-- Ultrasonic Distance Display

Ultrasonic Distance Display Circuit

Ultrasonic Distance Display Schematic

Connect Arudino and Sensor Pinout

  • Connect pins 12,9,8,6 (D1- D4) from the display to pins 13,12,11,10 (respectively)of the Arduino.

  • Connect pins 11,7,4,2,1,10,5,3 (a,b,c,d,e,f,g) of the display to pins 2,3,4,5,6,7,8,9 (respectively) of the Arduino with one 330Ω resistor in line.

  • On the ultrasonic sensor connect to VCC to 5V power pin, GND to the ground pin, the Trigger pin to A1 and Echo pin to A0.


/* Coding Ron Wang
   Dec.4th 2024
   Autaba support for coding hardware
   Project 39 Ultrasonic Distance Displays
 */

#include "SevSeg.h"  // library for 7 segment display
SevSeg sevseg;      // initate 7 segment display
                    //ultrasonic sensor pins globar variables 
int trigPin = A1; 
int echoPin = A0;
int cm;             // variable to be read by display 
int interval;       //value from the trig and echo pins

void setup() {
Serial.begin (9600); // serial monotor comm rate
pinMode(trigPin, OUTPUT); // set to output 
pinMode(echoPin, INPUT); // set to input
// set up SevSeg library parmeters 
byte numDigits = 4; // number of digits on the display 
byte digitPins[] = {13,12,11,10}; // pin numbers for each digit 
byte segmentPins[] = {2,3,4,5,6,7,8,9}; // pins for each part of the 7 segment display
bool resistorsOnSegments = true;  // true if resistors are being used 
bool updateWithDelaysIn = true;  // delays used 
byte hardwareConfig = COMMON_ANODE;  // display type 
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments); 
sevseg.setBrightness(20);   // brightness level of the display
}

void loop() {
digitalWrite(trigPin, LOW); // send short signal on the trigpin
delayMicroseconds(5);
digitalWrite(trigPin, HIGH); // send signal for 10ms
delayMicroseconds(10);
digitalWrite(trigPin, LOW); // turn off signal after 10ms
interval = pulseIn(echoPin, HIGH); 
// read signal from trigpin
// determine distance by using the time from the trig and echo pins 
// divide interval by 2 then divide again by 29 
cm = (interval/2) / 29;
// print to serial monitor
Serial.print(cm);
Serial.print("cm");
Serial.println();
//print to 7 segment display 
sevseg.setNumber(cm); 
// print the value of cm to the display 
sevseg.refreshDisplay();
}


版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://www.parentscn.com/?id=296

标签: Arduino

相关文章

Arduino Programming Basic - If and Loop

Arduino Programming Basic - If and Loop

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写了10个例子,关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静...

Arduino Project 020 -  LED Dot Matrix Display - Beat Heart

Arduino Project 020 - LED Dot Matrix Display - Beat Heart

You’re going to use the same circuit, but with a slight variation in the code to create a multi-fram...

Arduino Project 004 - LED Interactive Traffic Lights

Arduino Project 004 - LED Interactive Traffic Lights

This time you are going to extend the previous project to include a set of pedestrian lights and a p...

Arduino Project 021 -  LED Dot Matrix Display - Scrolling Message

Arduino Project 021 - LED Dot Matrix Display - Scrolling Message

There are many different ways to drive LEDs. Using shift registers is one way and they have their a...

Arduino Programming Basic - Funcation

Arduino Programming Basic - Funcation

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写了10个例子,关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静...

C语言调试运行环境Pelles C的安装

C语言调试运行环境Pelles C的安装

C语言调试运行环境之TurboC一文介绍了在32位Windows系统下安装C语言运行环境之TubroC,但是由于TurobC只能在32位系统下运行,导致现在很多Windows10和Windows 11...