10-laboratoriya: Pezonurlatgich. Pezonurlatgichni boshqarish: tonni o‘zgartirish,
davomiligini o‘zgartirish
Ishdan maqsad: arduino muhutida dasturini tuzish va pezonurlatgichni
boshqarishni o’rganish, proteusda sxemalarini yi’g’ib ishga tushurish.
1-rasm. Arduino muhida dastur yozilgan holati.
2-rasm. Proteus muhutida bizga kerakli bo’lgan barcha elemtlarni yig’ib olamiz
Proteusda barcha elementlarni yi’g’ib bir biriga ulaganimizdan so’ng arduinoda
yozgan dastur kodimizning hex. fileni ko’rsatishimiz kerak bo’ladi.
3-rasm. Arduinoda yozgan dastur kodimizning he. Fileni ko’rsatish
4-rasm. Protes muhitida dasturimizni ishga tusgan holati.
Dastur kodi:
const int echoPin = 2; // Ultrasonik sensorning echo pinasi
const int pingPin = 3; // Ultrasonik sensorning trigger pinasi
void setup()
{
Serial.begin(9600); // Serial aloqani boshlash
pinMode(pingPin, OUTPUT); // chiqish pimi 3 ni ishga tushirish
pinMode(echoPin, INPUT); // kirish pimi 2 ni boshlash
}
void loop()
{
long duration, inches, cm;
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
duration = pulseIn(echoPin, HIGH); // pulsin funktsiyasi yordamida umumiy
vaqtni aniqlash
inches = microsecondsToInches(duration); // bog'lanish usuli
cm = microsecondsToCentimeters(duration); // bog'lanish usuli
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
long microsecondsToInches(long microseconds) // mikrosektsiyani dyuymgacha
yashirish usuli
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds) // mikrosektsiyani
santimetrgacha yashirish usuli
{
return microseconds / 29 / 2;
}
Dostları ilə paylaş: |