Difference between revisions of "Lesson 10--Microduino Ultrasonic Sensor Measures Distance"

From Microduino Wiki
Jump to: navigation, search
(Created page with "{{Language | 第十课--Microduino 超声波测距}} {| style="width: 800px;" |- | ==Objective== This lesson will show how to use the Microduino ultrasonic sensor to control b...")
 
 
(One intermediate revision by the same user not shown)
Line 24: Line 24:
 
'''Ultrasonic sensor'''
 
'''Ultrasonic sensor'''
 
[[File:第十课-超声波传感器.jpg|600px|center|thumb]]
 
[[File:第十课-超声波传感器.jpg|600px|center|thumb]]
'''Brief Introduction:'''
+
'''Brief Introduction:'''
 
Ultrasonic sensor is designed by the characteristics of ultrasonic. Ultrasound is a kind of mechanical wave of vibration frequency is higher than the sound wave, is generated by changing the chip vibration under the excitation of voltage. It has a higher frequency, shorter wavelengths, small diffraction phenomenon, especially good directivity, can become rays and directional transmission etc. Ultrasonic penetrating power of liquid and solid is very big, especially in sunshine opaque solid, it can penetrate tens of metres in depth. Ultrasonic encounter impurities or interface can produce significant reflection form into echo, touching the moving objects can produce doppler effect. So ultrasonic detection is widely used in industry, national defense, biomedicine etc.
 
Ultrasonic sensor is designed by the characteristics of ultrasonic. Ultrasound is a kind of mechanical wave of vibration frequency is higher than the sound wave, is generated by changing the chip vibration under the excitation of voltage. It has a higher frequency, shorter wavelengths, small diffraction phenomenon, especially good directivity, can become rays and directional transmission etc. Ultrasonic penetrating power of liquid and solid is very big, especially in sunshine opaque solid, it can penetrate tens of metres in depth. Ultrasonic encounter impurities or interface can produce significant reflection form into echo, touching the moving objects can produce doppler effect. So ultrasonic detection is widely used in industry, national defense, biomedicine etc.
  
'''Components:'''
+
'''Components:'''
 
Ultrasonic probe is mainly composed of piezoelectric wafer, can emit ultrasonic already, also can receive ultrasonic. Low power ultrasound probe for detecting effect. It has a lot of different structure, can be divided into straight probe (longitudinal wave), oblique probe (shear wave) and surface wave probe (surface wave), lamb wave sensor (lamb wave), double probe (a probe reflection, a probe receiving) etc.
 
Ultrasonic probe is mainly composed of piezoelectric wafer, can emit ultrasonic already, also can receive ultrasonic. Low power ultrasound probe for detecting effect. It has a lot of different structure, can be divided into straight probe (longitudinal wave), oblique probe (shear wave) and surface wave probe (surface wave), lamb wave sensor (lamb wave), double probe (a probe reflection, a probe receiving) etc.
  
Line 68: Line 68:
  
 
==Debug==
 
==Debug==
Step 1:Copy the upper code to IDE and compile
+
Step 1: Copy the upper code to IDE and compile
  
Step 2:Compile no error, then set up the circuit, as follows:
+
Step 2: Compile no error, then set up the circuit, as follows:
  
 
[[File:intermediateLesson10Connect1.jpg|600px|center|thumb]]
 
[[File:intermediateLesson10Connect1.jpg|600px|center|thumb]]
Line 79: Line 79:
 
Step 3: Run program
 
Step 3: Run program
  
Step 4:Put the hand in front of ultrasonic sensor, listening the sound of the buzzer.
+
Step 4: Put the hand in front of ultrasonic sensor, listening the sound of the buzzer.
  
 
==Result==
 
==Result==
Line 85: Line 85:
  
 
==Video==
 
==Video==
http://v.youku.com/v_show/id_XNjc1NjQxMjU2.html
 

Latest revision as of 08:06, 12 September 2016

Language: English  • 中文

Objective

This lesson will show how to use the Microduino ultrasonic sensor to control buzzer and measure distance. You'll know the ultrasonic control by this simple example.

Test object is the SRF-04 ultrasonic sensors with four pins: 5v power supply (Vcc), trigger control pin (Trig), the receiver (Echo), and the GND.


Equipment

IntermediateLesson10All1.jpg
IntermediateLesson10All2.jpg

Ultrasonic sensor

第十课-超声波传感器.jpg

Brief Introduction: Ultrasonic sensor is designed by the characteristics of ultrasonic. Ultrasound is a kind of mechanical wave of vibration frequency is higher than the sound wave, is generated by changing the chip vibration under the excitation of voltage. It has a higher frequency, shorter wavelengths, small diffraction phenomenon, especially good directivity, can become rays and directional transmission etc. Ultrasonic penetrating power of liquid and solid is very big, especially in sunshine opaque solid, it can penetrate tens of metres in depth. Ultrasonic encounter impurities or interface can produce significant reflection form into echo, touching the moving objects can produce doppler effect. So ultrasonic detection is widely used in industry, national defense, biomedicine etc.

Components: Ultrasonic probe is mainly composed of piezoelectric wafer, can emit ultrasonic already, also can receive ultrasonic. Low power ultrasound probe for detecting effect. It has a lot of different structure, can be divided into straight probe (longitudinal wave), oblique probe (shear wave) and surface wave probe (surface wave), lamb wave sensor (lamb wave), double probe (a probe reflection, a probe receiving) etc.

Schematic

第十课-Microduino超声波测距原理图.jpg

Program

Download program: https://github.com/Microduino/Microduino_Tutorials/tree/master/Microduino_Advanced/MicroduinoUltrasonicRanging

const int TrigPin = 3;
const int EchoPin = 2;
float cm;

void setup()
{
	Serial.begin(9600);
	pinMode(TrigPin, OUTPUT);
	pinMode(EchoPin, INPUT);
	pinMode(8,OUTPUT);
}
void loop()
{
	digitalWrite(8, LOW);
	digitalWrite(TrigPin, LOW); //Send a low level voltage pulse to TrigPin
	delayMicroseconds(2);
	digitalWrite(TrigPin, HIGH);
	delayMicroseconds(10);
	digitalWrite(TrigPin, LOW);

	cm = pulseIn(EchoPin, HIGH) / 58.0; //Echo time convert to cm
	cm = (int(cm * 100.0)) / 100.0; //Keep two decimal places
	if (cm>=2 && cm<=10)
		digitalWrite(8, HIGH);
}

Debug

Step 1: Copy the upper code to IDE and compile

Step 2: Compile no error, then set up the circuit, as follows:

IntermediateLesson10Connect1.jpg
IntermediateLesson10Connect2.jpg
第十课-Microduino超声波测距电路图.jpg

Step 3: Run program

Step 4: Put the hand in front of ultrasonic sensor, listening the sound of the buzzer.

Result

If there is an object in front of the ultrasonic sensor, and the distance of the object is larger than 2 cm, less than 10 cm, buzzer will sound. You can make an ultrasonic alarm based on this.

Video