fbpx
АРВАН ХОЁРДУГААР ДОЛОО ХОНОГ
АРВАН ГУРАВДУГААР ДОЛОО ХОНОГ
АРВАН ДӨРӨВДҮГЭЭР ДОЛОО ХОНОГ
АРВАН ТАВДУГААР ДОЛОО ХОНОГ
АРВАН ЗУРГААДУГААР ДОЛОО ХОНОГ
АРВАН ДОЛООДУГААР ДОЛОО ХОНОГ
АРВАН НАЙМДУГААР ДОЛОО ХОНОГ
Төсөл
2 of 3

Төсөл 3 Саад илрүүлэгч

Хэрэглэгдэхүүн:

  1. Ардиуно 1ш
  2. Туршилтын хавтан 1ш
  3. Баззер 1ш
  4. Хэт авиа мэдрэгч 1ш
  5. Утас

Зарчмын схем

Зарчмын схем

Программ

int const trigPin = 10;     // Defines the data pins of the ultrasonic
int const echoPin = 9;     
int const buzzPin = 2;      // Defines the buzzer pin
void setup()
{
pinMode(trigPin, OUTPUT);   // sets trig pin to have output pulses
pinMode(echoPin, INPUT);    // sets echo pin to be input and get the pulse width
pinMode(buzzPin, OUTPUT);   // sets buzz pin as output to control the sound
}
void loop()
{
int duration, distance;     // The Duration will be the input pulse width and distance will be the distance to the obstacle in centimeters
digitalWrite(trigPin, HIGH); // The output pulse with 1ms width on trigPin
delay(1);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);  // Measures the pulse input in the echo pin
distance = (duration/2) / 29.1;   // Distance is half the duration devided by 29.1 (from datasheet)
// if the distance is less than 0.5 meter and more than 0 (0 or less means over range)
if (distance <= 50 && distance >= 0) {
// It will trigger the Buzzer
digitalWrite(buzzPin, HIGH);
} else {
// Will no Sound
digitalWrite(buzzPin, LOW);
}
// Waits 50 milliseconds
delay(50);
}