Kirish 2 1-bob. Elektr, gidravlik yoki pnevmatik yuritmalar 5


Yorug'lik sensori bo'lgan dasturga misol


Download 0.66 Mb.
bet11/11
Sana18.06.2023
Hajmi0.66 Mb.
#1594553
1   2   3   4   5   6   7   8   9   10   11
Bog'liq
71-20 Murtazayev Azizbek kurs ishi

Yorug'lik sensori bo'lgan dasturga misol
Ushbu misolda pardalar yorug'likka qarab ochiladi va yopiladi. Bizga IR qabul
qilgich kerak emas, lekin yorug'lik sensori (Troyka moduli) va potansiyometrni
(Troyka moduli) qo'shishimiz kerak.

// Servolar bilan ishlash uchun kutubxonani ulang


#include
// ishlatiladigan pinlar sonini aniqlang
// yorug'lik sensori
#define LIGHT_PIN A0
// yorug'likka sezgirlik
#define POT_PIN A5
// servo pin
#define SERV_PIN 3
// tweeter pin
#define BUZZER_PIN 4
// "harakat" turini aniqlangenum Command
{
CMD_NONE = 0,
CMD_OPEN = 1,
CMD_CLOSE = 2
};
// dastur boshida biz panjurlar ochiq yoki ochiq emasligini bilmaymiz
int cmd = CMD_NONE;
// doimiy aylanish servosini boshqarish uchun ob'ekt yaratish
Servo srv;
void setup()
{
// foydalanuvchiga biz uch martalik cho'qqi bilan boshlaganimiz haqida xabar bering
tone(BUZZER_PIN, 500, 100);
delay(200);
tone(BUZZER_PIN, 500, 100);
delay(200);
tone(BUZZER_PIN, 500, 100);
delay(200);
}
void loop()
{
int light = analogRead(LIGHT_PIN);
int lightSens = analogRead(POT_PIN);
Serial.print(light);
Serial.print("\t\t");
Serial.print(lightSens);
Serial.print("\t\t");
Serial.println(cmd);
if (light > lightSens && (cmd == CMD_OPEN || cmd == CMD_NONE)) {
srv.attach(SERV_PIN);
srv.write(120);
// pardalarning belgilangan ochilish/yopilish vaqtini kuting
delay(2000);
// doimiy aylanish servosini to'xtatishning eng oson yo'li
// undan ajrating srv.detach();
cmd = CMD_CLOSE;
} else if (light < lightSens && (cmd == CMD_CLOSE || cmd == CMD_NONE)) {
srv.attach(SERV_PIN);
// pardalarning belgilangan ochilish/yopilish vaqtini kuting
srv.write(30);
delay(2000);
// doimiy aylanish servosini to'xtatishning eng oson yo'li
// undan ajrating srv.detach();
cmd = CMD_OPEN;
}
}





Download 0.66 Mb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7   8   9   10   11




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling