Arduino Hareket Sensorlu Led Yakma

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
649 B
10
Indexable
Never
// C++ code
//

int ledPin = 13;
int sensorPin = 2;
int sensorState = LOW;
int sensorValue = 0;
void setup()
{
  pinMode(ledPin, OUTPUT);
  pinMode(sensorPin, INPUT);
  Serial.begin(9600);
}

void loop()
{
  sensorValue = digitalRead(sensorPin);
  if(sensorValue == HIGH)
  {
    digitalWrite(ledPin,HIGH);
    delay(150);
    
    if(sensorState == LOW)
    {
      Serial.println("Movement!!!!");
      sensorState == HIGH;
    }
  }
  else
  {
	digitalWrite(ledPin, LOW);
    delay(300);
    
    if(sensorState == HIGH)
    {
      Serial.println("Movement Down!!!!");
      sensorState == LOW;
    }
  }
}