int led = 13; // lampa ulangan pin
int sensor = 2; // harakat sensori ulangan pin
int state = LOW; // dastlabki holati harakat aniqlanmagan
int val = 0; // sensor holatini saqlash uchun o'zgaruvchi qiymat
void setup() {
pinMode(led, OUTPUT); // lampani chiqish sifatida ishga tushiring
pinMode(sensor, INPUT); // sensorni kirish sifatida ishga tushiring
Serial.begin(9600); // seriyani ishga tushiring
}
void loop(){
val = digitalRead(sensor); // sensor qiymatini o'qish
if (val == HIGH) { // sensor yuqori ekanligini tekshiring
digitalWrite(led, HIGH); // LEDni yoqing
delay(100);
if (state == LOW) {
Serial.println("Harakat aniqlandi domlajon!");
state = HIGH; // o'zgaruvchi holatini HIGH ga yangilash
}
}
else {
digitalWrite(led, LOW); // ledni ochirish
delay(200);
if (state == HIGH){
Serial.println("Harakat to'xtadi domlajon!");
state = LOW; //o'zgaruvchi holatini LOW holatiga yangilash
}
}
}