โค้ด
int IRSensorPin = 6; // IR Sensor pin
int moterStatus = 10; // LED Motor status pin
int valIRSensor = 0;
boolean PIRActiveFlag = false; // flag of PIR Status
unsigned long time = millis();
void setup() {
pinMode(IRSensorPin, INPUT); // sets the pin as input
pinMode(moterStatus, OUTPUT); // sets the pin as output
}
void loop()
{
chkIRSensor();
delay(100);
}
//************ Start IR Sensor Controller *********//
void chkIRSensor() {
valIRSensor = digitalRead(IRSensorPin);
// Serial.print("valIRSensor = ");
// Serial.println(valIRSensor);
if (valIRSensor == 0) {
digitalWrite(moterStatus, HIGH);
delay(500);
digitalWrite(moterStatus, LOW);
while(digitalRead(IRSensorPin) == 0) {
//loop until valIRSensor == 0
}
} else {
digitalWrite(moterStatus, LOW); // สั่งให้ LED ดับ
// Serial.println("elseLoop"); // พิมพ์ค่าของตัวแปร valIRSensor
delay(100);
}
}
//************ End of IR Sensor Controller *********//
error
Arduino: 1.8.19 (Windows 10), Board: "Arduino Nano, ATmega168"
Sketch uses 1224 bytes (8%) of program storage space. Maximum is 14336 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 1015 bytes for local variables. Maximum is 1024 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x5f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x5f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x5f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x5f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x5f
Problem uploading to board. See https://support.arduino.cc/hc/en-us/sections/360003198300 for suggestions.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x5f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x5f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x5f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x5f
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x5f
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.