본문 바로가기

IOT(Arduino+Inventor)

초음파센서(SR_04)[4]

전기적인 파라메터

 

 

 

구동전압 : DC5v

구동 전류 :15mA

동작 주파수 :40HZ

최대 감지 거리: 400cm

최소 감지거리 : 2cm

측정 각도 : 15 도

트리거 입력신호 :10uS TTL

 

엡화면입니다.

 

 

아두이노 스케치 업로드 후 시리얼 포트에서 회로가 동작되는 확인합니다.

시리얼 모니터 화면입니다.

스케치

 

 

#include <SoftwareSerial.h>

#define TRIG 9
#define ECHO 8

long duration=0;
long distance=0;

SoftwareSerial mySerial(2,3);

void setup() {
  mySerial.begin(115200);
  Serial.begin(115200);
  pinMode(TRIG,OUTPUT);
  pinMode(ECHO,INPUT);
}

void loop() {
  digitalWrite(TRIG,LOW);
  delayMicroseconds(5);
  digitalWrite(TRIG,HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG,LOW);

  duration= pulseIn(ECHO, HIGH);
  // Convert the time into a distance
  distance = duration/58.0;
// inches = (duration/2) / 74; 
  
  mySerial.write(byte(distance));
  Serial.println(byte(distance));
  delay(1000); 
}

 

인벤터는 앞절 온도엡과 같습니다.

 

라벨 M만 추가하면됩니다.

'IOT(Arduino+Inventor)' 카테고리의 다른 글

서보 모터 제어[6]  (0) 2022.04.05
수은 기울기 센서[5]  (0) 2022.04.03
DHT11 온도 센서[3]  (0) 2022.03.29
RGB_LED 제어[2]  (0) 2022.03.27
RGB LED 제어[1]  (0) 2022.03.27