Ultrasonic Sensor TYWu HCSR 04 Picture HCSR 04

  • Slides: 17
Download presentation
Ultrasonic Sensor TYWu

Ultrasonic Sensor TYWu

HC-SR 04 • Picture

HC-SR 04 • Picture

HC-SR 04 • Specifications – power supply : 5 V DC – quiescent current

HC-SR 04 • Specifications – power supply : 5 V DC – quiescent current : <2 m. A – effectual angle: <15° – ranging distance : 2 cm – 500 cm – resolution : 0. 3 cm – 40 KHz ultrasonic signal

HC-SR 04 • There are 4 pins – VCC , Trig, Echo, GND •

HC-SR 04 • There are 4 pins – VCC , Trig, Echo, GND • Control – pull the Trig pin to high level for more than 10 us impulse , the module start ranging – finish ranging, If you find an object in front, Echo pin will be high level, and based on the different distance, – it will take the different duration of high level. – So we can calculated the distance easily : • Distance = High Level Duration*(Sonic: 340 m/s)/2

HC-SR 04 • Control

HC-SR 04 • Control

HC-SR 04 • Effectual Angle: <15°

HC-SR 04 • Effectual Angle: <15°

HC-SR 04 • Library – Ultrasonic. cpp and Ultrasonic. h • Ultrasonic. cpp #include

HC-SR 04 • Library – Ultrasonic. cpp and Ultrasonic. h • Ultrasonic. cpp #include "WProgram. h" #include "Ultrasonic. h" Ultrasonic: : Ultrasonic(int TP, int EP) { pin. Mode(TP, OUTPUT); pin. Mode(EP, INPUT); Trig_pin=TP; Echo_pin=EP; }

HC-SR 04 long Ultrasonic: : Timing() { digital. Write(Trig_pin, LOW); delay. Microseconds(2); digital. Write(Trig_pin,

HC-SR 04 long Ultrasonic: : Timing() { digital. Write(Trig_pin, LOW); delay. Microseconds(2); digital. Write(Trig_pin, HIGH); delay. Microseconds(10); digital. Write(Trig_pin, LOW); duration = pulse. In(Echo_pin, HIGH); // in microseconds return duration; }

HC-SR 04 long Ultrasonic: : Ranging(int sys) { Timing(); distacne_cm = duration / 29

HC-SR 04 long Ultrasonic: : Ranging(int sys) { Timing(); distacne_cm = duration / 29 / 2 ; // 34000 cm/s*us=0. 034=1/29 distance_inc = duration / 74 / 2; if (sys) return distacne_cm; else return distance_inc; }

HC-SR 04 • Ultrasonic. h #ifndef Ultrasonic_h #define Ultrasonic_h #include "WProgram. h" #define CM

HC-SR 04 • Ultrasonic. h #ifndef Ultrasonic_h #define Ultrasonic_h #include "WProgram. h" #define CM 1 #define INC 0

HC-SR 04 class Ultrasonic { public: Ultrasonic(int TP, int EP); long Timing(); long Ranging(int

HC-SR 04 class Ultrasonic { public: Ultrasonic(int TP, int EP); long Timing(); long Ranging(int sys); private: int Trig_pin; int Echo_pin; long duration, distacne_cm, distance_inc; }; #endif

HC-SR 04 • Test Example (Sketch) #include "Ultrasonic. h" Ultrasonic ultrasonic(12, 13); // TP:

HC-SR 04 • Test Example (Sketch) #include "Ultrasonic. h" Ultrasonic ultrasonic(12, 13); // TP: pin 12, EP: pin 13 void setup() { Serial. begin(9600); } void loop() { Serial. print(ultrasonic. Ranging(CM)); Serial. println(" cm"); }

LV-Max. Sonar®-EZ 1 • Pictures

LV-Max. Sonar®-EZ 1 • Pictures

LV-Max. Sonar®-EZ 1 • Overview – detects objects from 0 -inches to 254 -inches

LV-Max. Sonar®-EZ 1 • Overview – detects objects from 0 -inches to 254 -inches (6. 45 -meters) – 1 -inch resolution – The interface output formats included are pulse width output, analog voltage output, and serial digital output.

LV-Max. Sonar®-EZ 1 • AN – Outputs analog voltage with a scaling factor of

LV-Max. Sonar®-EZ 1 • AN – Outputs analog voltage with a scaling factor of (Vcc/512) per inch. A supply of 5 V yields ~9. 8 m. V/in. and 3. 3 V yields ~6. 4 m. V/in. The output is buffered and corresponds to the most recent range data.

LV-Max. Sonar®-EZ 1 • Test Example (Sketch) int ultra. An = 0; // select

LV-Max. Sonar®-EZ 1 • Test Example (Sketch) int ultra. An = 0; // select the input pin for the ultrasonic sensor int val = 0; // variable to store the value coming from the sensor int dist = 0; // variable to store the converted distance in inches // VDD Connect to 3. 3 V void setup() { Serial. begin(9600); // setup the serial port to send the values // back to the computer }

LV-Max. Sonar®-EZ 1 void loop() { val = analog. Read(ultra. An); // read the

LV-Max. Sonar®-EZ 1 void loop() { val = analog. Read(ultra. An); // read the value from the sensor Serial. println(val); // print the value to the serial port dist = (val*2. 1); // converts the analog value to distance in inches Serial. print(dist); // prints the distance in cm Serial. println(" cm"); // prints the distance in cm delay (500); // delays 0. 5 seccond in between readings }