Skip to content

Instantly share code, notes, and snippets.

@Alqueraf
Created June 3, 2018 19:57
Show Gist options
  • Save Alqueraf/6389b1bae11c503d34d36dcfc553c998 to your computer and use it in GitHub Desktop.
Save Alqueraf/6389b1bae11c503d34d36dcfc553c998 to your computer and use it in GitHub Desktop.
Code to showcase the use of a PIR sensor with a LED
const int LED = 13;
const int PIR = 5;
void setup() {
// Inicializar pin del LED como escritura
pinMode(LED, OUTPUT);
// Inicializar pin del PIR como lectura
pinMode(PIR, INPUT);
// "Calentamiento" de un minuto para PIR
for (int i = 0; i < 10; i++) {
// Hacemos que nuestro LED parpadee para mostrar que el circuito está funcionando
digitalWrite(LED, LOW);
delay(3000);
digitalWrite(LED, HIGH);
delay(3000);
}
}
void loop() {
// Leemos el valor del PIR
if (digitalRead(PIR) == HIGH) {
// Algo ha atravesado el campo de visión del PIR, encendemos el LED
digitalWrite(LED, HIGH);
delay(5000);
} else {
// Nada detectado, seguimos con el LED apagado
digitalWrite(LED, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment