Svetofor, transport signallari, svetoforlar yoki robotlar joylashgan signalizatsiya moslamalari


Yangi boshlanuvchilar uchun Arduino-da svetofor sxemasi


Download 265.31 Kb.
bet4/9
Sana27.01.2023
Hajmi265.31 Kb.
#1129692
1   2   3   4   5   6   7   8   9
Bog'liq
Piyodalar svetaforini vaqt bo\'yicha yonib o\'chishi dasturini ishlab

Yangi boshlanuvchilar uchun Arduino-da svetofor sxemasi
Birinchidan, Arduino mikrokontrollerining kodini tushunish va chorrahalarda svetoforlarning ishlash algoritmini tushunish uchun oddiy svetofor sxemasini tasodifiy non panelida yig'amiz. Haqiqiy hayotda yo'lda svetoforlarning ishlash rejimini tushunish uchun bolalar uchun bilish ham foydali bo'ladi. Yuqoridagi sxema bo'yicha LEDlarni Arduino-ga ulang va quyidagi eskizni taxtaga yuklang.
Yangi boshlanuvchilar uchun Arduino svetoforini hisoblash
Tugma bilan Arduino Uno-dagi svetofor
Ushbu misol bolalarga piyodalar o'tish joylarida svetoforlarning ishlashini tushunishga imkon beradi, bu erda tugma bosilganda ish rejimini almashtirish sodir bo'ladi. Ushbu ish algoritmi bilan dasturda while loopidan foydalanish kerak. Sxemaga soat tugmachasini qo'shing va tugma ulangan raqamli (analog) Pinda yuqori signal darajasida svetofor rejimini o'zgartiring.
Arduino-da soat tugmasi bilan svetofor sxemasi
Arduino-dagi svetofor uchun tugma bilan hisoblagich
// LED portlari uchun nomlar bering
#define RED1 2
#define ORG1 3
#define GRN1 4
#define RED2 6
#define ORG2 7
#define GRN2 8
#define KNP 10


// задержка между переключением светофора 3 сек
int pause = 3000;


void setup() {
pinMode(RED1, OUTPUT);
pinMode(ORG1, OUTPUT);
pinMode(GRN1, OUTPUT);
pinMode(RED2, OUTPUT);
pinMode(ORG2, OUTPUT);
pinMode(GRN2, OUTPUT);
pinMode(KNP, INPUT);
}


void loop() {
// первая фаза
digitalWrite(RED1, HIGH);
digitalWrite(ORG1, LOW);
digitalWrite(GRN1, LOW);
digitalWrite(RED2, LOW);
digitalWrite(ORG2, LOW);
digitalWrite(GRN2, HIGH);
// цикл while не начнется, пока не будет нажата кнопка
while (digitalRead(10) == HIGH) {
delay(pause);
// вторая фаза
digitalWrite(RED1, HIGH);
digitalWrite(ORG1, HIGH);
digitalWrite(GRN1, LOW);
digitalWrite(RED2, LOW);
digitalWrite(ORG2, HIGH);
digitalWrite(GRN2, LOW);
delay(pause);
// третья фаза
digitalWrite(RED1, LOW);
digitalWrite(ORG1, LOW);
digitalWrite(GRN1, HIGH);
digitalWrite(RED2, HIGH);
digitalWrite(ORG2, LOW);
digitalWrite(GRN2, LOW);
delay(pause);
// четвертая фаза
digitalWrite(RED1, LOW);
digitalWrite(ORG1, HIGH);
digitalWrite(GRN1, LOW);
digitalWrite(RED2, HIGH);
digitalWrite(ORG2, HIGH);
digitalWrite(GRN2, LOW);
delay(pause);
}
}
Kod uchun tushuntirishlar:
1. LED pinlari va soat tugmasi uchun nomlar berilgan;
2. while tsikli faqat tugma bosilganda amalga oshiriladi.
Arduino-da svetoforni qanday qilish kerak
Quyidagi kod yashil svetoforning miltillashini qo'shdi, aks holda bu sharhdagi birinchi eskizdan farq qilmaydi. Bunday loyihani amalga oshirishni istaganlar uchun biz barcha kerakli fayllarni bitta arxivga joylashtirdik. Havolada siz chorrahaning chizmasini CDR formatida (CorelDraw) va STL formatidagi 3D svetofor modelini yuklab olishingiz mumkin. Arduino svetoforining kodi quyida keltirilgan.
Arduino Uno / Nano-dagi svetoforlar uchun hisoblagich
// LED portlari uchun nomlar bering
#define RED1 2
#define ORG1 3
#define GRN1 4
#define RED2 6
#define ORG2 7
#define GRN2 8


// задержка между переключением светофора 3 сек
int pause = 3000;
int miganie = 500;


void setup() {
pinMode(RED1, OUTPUT);
pinMode(ORG1, OUTPUT);
pinMode(GRN1, OUTPUT);
pinMode(RED2, OUTPUT);
pinMode(ORG2, OUTPUT);
pinMode(GRN2, OUTPUT);
}


void loop() {
// первая фаза
digitalWrite(RED1, HIGH);
digitalWrite(ORG1, LOW);
digitalWrite(GRN1, LOW);
digitalWrite(RED2, LOW);
digitalWrite(ORG2, LOW);
digitalWrite(GRN2, HIGH);
delay(pause);
// мигание зеленого сигнала
digitalWrite(GRN2, LOW);
delay(miganie);
digitalWrite(GRN2, HIGH);
delay(miganie);
digitalWrite(GRN2, LOW);
delay(miganie);
digitalWrite(GRN2, HIGH);
delay(miganie);
digitalWrite(GRN2, LOW);
delay(miganie);
digitalWrite(GRN2, HIGH);
delay(miganie);
// вторая фаза
digitalWrite(RED1, HIGH);
digitalWrite(ORG1, HIGH);
digitalWrite(GRN1, LOW);
digitalWrite(RED2, LOW);
digitalWrite(ORG2, HIGH);
digitalWrite(GRN2, LOW);
delay(pause);
// третья фаза
digitalWrite(RED1, LOW);
digitalWrite(ORG1, LOW);
digitalWrite(GRN1, HIGH);
digitalWrite(RED2, HIGH);
digitalWrite(ORG2, LOW);
digitalWrite(GRN2, LOW);
delay(pause);
// мигание зеленого сигнала
digitalWrite(GRN1, LOW);
delay(miganie);
digitalWrite(GRN1, HIGH);
delay(miganie);
digitalWrite(GRN1, LOW);
delay(miganie);
digitalWrite(GRN1, HIGH);
delay(miganie);
digitalWrite(GRN1, LOW);
delay(miganie);
digitalWrite(GRN1, HIGH);
delay(miganie);
// четвертая фаза
digitalWrite(RED1, LOW);
digitalWrite(ORG1, HIGH);
digitalWrite(GRN1, LOW);
digitalWrite(RED2, HIGH);
digitalWrite(ORG2, HIGH);
digitalWrite(GRN2, LOW);
delay(pause);
}
1. kodni murakkablashtirmaslik uchun svetoforlar taxtaga juft bo'lib ulangan;
2. yashil signalning miltillash chastotasi miganie o'zgaruvchisida o'zgaradi;
3. Arduino uchun tugmachani hc-sr04 ultratovushli masofadan o'lchash moslamalari bilan almashtirish orqali svetofor loyihasini takomillashtirish mumkin.

1.3. Arduino-dagi svetofor


Ushbu darsda eng oson ishlang uchta LED-ning svetofori. U bunday sxema bo'yicha ish qilishi kerak.
1. Faqat qizil rangda porlaydi bizning kelajakdagi svetoforlarimiz.
2. Qizil yorug'lik signalini o'chirmang.
3. Yashil chiroq signalini o'chiring.
Shundan so'ng, biz svetoforning qizil signalidan tsiklni takrorlaymiz.
Dars uchun biz kerak bo'ladi:
Uchrashuvga uch marta ulang Arduino UNO.. Bizda shunday sxema bor.


Download 265.31 Kb.

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




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