Skip to content

Instantly share code, notes, and snippets.

@esmarr58
Created November 15, 2017 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esmarr58/abde6f079d94a4d9783e25756df3504b to your computer and use it in GitHub Desktop.
Save esmarr58/abde6f079d94a4d9783e25756df3504b to your computer and use it in GitHub Desktop.
int ledPin = 13; // choose pin for the LED
int inputPin = 2; // choose input pin (for Infrared sensor)
int val = 0; // variable for reading the pin status
void setup()
{
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare Infrared sensor as input
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment