Notice
Recent Posts
Recent Comments
250x250
Creative Code
10_ultrasonic(초음파 거리재기) 본문
728x90
const int trig_pin =11;
const int echo_pin =12;
void setup() {
// put your setup code here, to run once:
pinMode(trig_pin,OUTPUT);
pinMode(echo_pin,INPUT);
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trig_pin,LOW);
delayMicroseconds(2);
digitalWrite(trig_pin,HIGH);
delayMicroseconds(10);
digitalWrite(trig_pin,LOW);
long duration = pulseIn(echo_pin,HIGH);
long distance = (duration/2)/29.1;
Serial.print(distance);
Serial.println( "cm");
delay(300);
}
728x90
'Arduino(C,C++)' 카테고리의 다른 글
12_timer1_piezo (0) | 2023.08.14 |
---|---|
11_timer1_led (0) | 2023.08.14 |
09_tone (0) | 2023.08.11 |
08_joystick (0) | 2023.08.11 |
07_Analog_Read-(2) 조명센서밝기에 따른 led밝기 조절 (0) | 2023.08.11 |