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 1: Line 1:
[[Image:HC-SR04+Nano.jpg|200px|thumb|right|HC-SR04 Ultrasonic Sensor on Arduino Nano breadboard]]

[http://www.dealextreme.com/p/133696 HC-SR04 Ultrasonic Sensor Distance Measuring Module]
[http://www.dealextreme.com/p/133696 HC-SR04 Ultrasonic Sensor Distance Measuring Module]



Revision as of 15:24, 10 August 2012

HC-SR04 Ultrasonic Sensor on Arduino Nano breadboard

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
// load the library for HC-SR04 http://iteadstudio.com/application-note/arduino-library-for-ultrasonic-ranging-module-hc-sr04/
// Remark: change the “WProgram.h” reference to “Arduino.h” in files "Ultrasonic.h" and "Ultrasonic.cpp" and everything will be fine


#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 Arduino pin 13

Ultrasonic ultrasonic(12,13);

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

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

  delay(100);

  Serial.print(ultrasonic.Timing()); // Distance = ((Duration of high level)*(Sonic :340m/s))/2
  Serial.println(" ms");

  delay(100);
}