초음파 센서를 이용한 사고 회피 로봇

필요한 구성 요소
아두이노 우노
Arduino는 사용하기 쉬운 하드웨어 및 소프트웨어를 기반으로 하는 오픈 소스 전자 플랫폼입니다. Arduino 보드는 센서의 빛, 버튼의 손가락 또는 트위터 메시지와 같은 입력을 읽고 모터를 활성화하고 LED를 켜고 온라인에 무언가를 게시하는 출력으로 바꿀 수 있습니다. 이를 위해서는 아두이노 프로그래밍 언어(배선 기반)와 프로세싱 기반 아두이노 소프트웨어(IDE)를 사용한다.
HC-SR04 초음파 센서
초음파 센서 HC-SR04는 거리 측정 센서입니다. 40,000Hz(40kHz)의 초음파를 방출하여 공기를 통해 이동하고 물체나 장애물을 만나면 모듈로 되돌아옵니다. 이동 시간과 소리의 속도를 고려하여 거리를 계산할 수 있습니다.
기어 모터
속도를 낮추고 토크와 힘을 증가시키기 위한 기어박스가 있는 DC 모터입니다. 이러한 유형의 모터는 일반적으로 로봇 응용 분야에 사용됩니다.
IC L293D
IC L293D는 4.5~36볼트의 전압 범위에서 최대 600mA의 전류를 구동할 수 있는 듀얼 H-브리지 모터 드라이버 집적 회로입니다.

암호
#define trigPin 3
#define echoPin 2
int leftmotor = 4;
int leftmotor1 = 5;
int rightmotor = 6;
int rightmotor1 = 7;
void setup()
{
  Serial.begin(9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  //MOTORS
  pinMode(leftmotor, OUTPUT);// M1
  pinMode(leftmotor1, OUTPUT);// M2
  pinMode(rightmotor, OUTPUT);// M3
  pinMode(rightmotor1, OUTPUT);// M4
}
void loop() {
  int duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 58);
  if (distance < 10)
  {
    digitalWrite(leftmotor, HIGH);//FORWARD
    digitalWrite(leftmotor1, LOW);
    digitalWrite(rightmotor, HIGH);
    digitalWrite(rightmotor1, LOW);
  }
  if (distance >= 10)
  {
    digitalWrite(leftmotor, LOW);//BACKWARD
    digitalWrite(leftmotor1, HIGH);
    digitalWrite(rightmotor, LOW);
    digitalWrite(rightmotor1, HIGH);
    delay(2000);
    digitalWrite(leftmotor, LOW);//RIGHT
    digitalWrite(leftmotor1, HIGH);
    digitalWrite(rightmotor, HIGH);
    digitalWrite(rightmotor1, LOW);
    delay(2000);
  }
}
                Reference
이 문제에 관하여(초음파 센서를 이용한 사고 회피 로봇), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/ndrohith/accident-avoider-robot-using-ultrasonic-sensor-mmi텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)