본 제품은 초음파를 원리를 이용하여 거리측정기능이 있으며 측정거리는 2cm ~ 300cm입니다. 송신기, 수신기,
제어회로 일체형으로 구성되어 있습니다. 













 

HC-SR04


100uS 트리거 펄스 입력하면 모듈내부에서 8개의 40Khz 초음파 송신, 물체로 부터 반사신호 즉 echo 신호가 High 출력될때가지 시간검출후 측정거리 = (시간 * 340) / 2 로 거리를 산출
트리거 신호와 에코신호핀이 별도로 존재함



 

#define CM 1 //Centimeter
#define INC 0 //Inch
#define TP 8 //Trig_pin
#define EP 9 //Echo_pin 

void setup()
{
pinMode(TP,OUTPUT); // set TP output pin for trigger
pinMode(EP,INPUT); // set EP input pin for echo
Serial.begin(9600); // init serial 9600
Serial.println("-------------------Ultra_Demo_Start---------------------------------");
}
void loop()
{
long microseconds = TP_init(); // trigger and receive
Serial.print("microseconds = ");
Serial.println(microseconds);
long distacne_cm = Distance(microseconds, CM); // Calculating the distance
Serial.print("Distacne_CM = ");
Serial.println(distacne_cm); // printf the distance about CM
delay(3000);
}