HC-SR04 Ultrasonic Sensor Distance Measuring Module: Difference between revisions

From air
Jump to navigation Jump to search
No edit summary
No edit summary
Line 19: Line 19:
A lire
A lire
* http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1272177425
* http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1272177425

==Arduino==
[[Image:Arduino+HCSR04.jpg|thumb|200px|right|HCSR-04 with Arduino Nano]]
<pre>
#include "Ultrasonic.h"

// Sensor VCC pin connected to Arduino pin 5V
// Sensor GND pin connected to Arduino pin GND
// Sensor TRIG pin connected to Arduino pin 12
// sensor ECHO pin connected to pin 13

Ultrasonic ultrasonic(12,13);

void setup() {
Serial.begin(9600);
}

void loop()
{
Serial.print(ultrasonic.Ranging(CM));
Serial.println(" cm");
delay(100);
}

</pre>

Revision as of 06:35, 10 August 2012

HC-SR04 Ultrasonic Sensor Distance Measuring Module

- Model: HC-SR04
- Color: Blue + Silver
- Working voltage : 5V(DC)
- Static current: Less than 2mA.
- Output signal: Electric frequency signal, high level 5V, low level 0V.
- Sensor angle: Not more than 15 degrees.
- Detection distance: 2cm~450cm.
- High precision: Up to 3mm
- Mode of connection: VCC / trig(T) / echo(R) / GND
- Module Working Principle:
- Adopt IO trigger through supplying at least 10us sequence of high level signal
- The module automatically send eight 40khz square wave and automatically detect whether receive the returning pulse signal
- If there is signals returning, through outputting high level and the time of high level continuing is the time of that from the ultrasonic transmitting to receiving

A lire

Arduino

File:Arduino+HCSR04.jpg
HCSR-04 with Arduino Nano
#include "Ultrasonic.h"

// Sensor VCC pin connected to Arduino pin 5V
// Sensor GND pin connected to Arduino pin GND
// Sensor TRIG pin connected to Arduino pin 12
// sensor ECHO pin connected to pin 13

Ultrasonic ultrasonic(12,13);

void setup() {
  Serial.begin(9600);
}

void loop()
{
  Serial.print(ultrasonic.Ranging(CM));
  Serial.println(" cm");
  delay(100);
}