Created
June 3, 2018 19:57
-
-
Save Alqueraf/6389b1bae11c503d34d36dcfc553c998 to your computer and use it in GitHub Desktop.
Code to showcase the use of a PIR sensor with a LED
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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