Paso 9: Completo software para el sensor de PIR
Después de asegurarse de que todas las cosas trabajan, podemos programar el software completo. He utilizado un módulo de sueño agradable para ahorrar energía de la batería, aquí está la biblioteca Sleep_n0m1.
El software es bastante sencillo:
-en la inicialización, el indicador luminoso parpadeará 10 veces
-después de este momento, el sensor PIR es totalmente operativo
-Cuando el sensor PIR detecta un cambio, despertará el Arduino Arduino dará la señal de enfoque a la cámara (1 segundo), y se espera 0,5 segundos y luego dar la señal de obturador (0,5 segundos)
-cámara tomará una foto.
******************************************************************************************
#include Sleep_n0m1.h
Milisegundos de la activación de la señal
const int FOCUS_TIME = 1000;
const int SHUTTER_TIME = 500;
Pines de salida digital
const int FOCUS_LED = 7;
const int SHUTTER_LED = 6;
Digital pins
const int PIR_IN = 8;
Digital hacia fuera pernos (a transistores MOS-FET)
const int FOCUS_ON = 4;
const int SHUTTER_ON = 9;
Sueño sueño;
Una vez establecida
void setup() {}
pinMode (FOCUS_LED, salida);
pinMode (SHUTTER_LED, salida);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, alto);
pinMode (FOCUS_ON, salida);
pinMode (SHUTTER_ON, salida);
digitalWrite (FOCUS_ON, bajo);
digitalWrite (SHUTTER_ON, bajo);
pinMode (PIR_IN, entrada);
Delay(2000);
encendido LED rojo, verde y ámbar
de 10 veces - 1er tiempo
digitalWrite (FOCUS_LED, LOW);
Delay(500);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, bajo);
Delay(500);
digitalWrite (SHUTTER_LED, alto);
digitalWrite (FOCUS_LED, LOW);
digitalWrite (SHUTTER_LED, bajo);
Delay(1000);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, alto);
2 º tiempo
digitalWrite (FOCUS_LED, LOW);
Delay(500);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, bajo);
Delay(500);
digitalWrite (SHUTTER_LED, alto);
digitalWrite (FOCUS_LED, LOW);
digitalWrite (SHUTTER_LED, bajo);
Delay(1000);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, alto);
//****************3
digitalWrite (FOCUS_LED, LOW);
Delay(500);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, bajo);
Delay(500);
digitalWrite (SHUTTER_LED, alto);
digitalWrite (FOCUS_LED, LOW);
digitalWrite (SHUTTER_LED, bajo);
Delay(1000);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, alto);
//****************4
digitalWrite (FOCUS_LED, LOW);
Delay(500);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, bajo);
Delay(500);
digitalWrite (SHUTTER_LED, alto);
digitalWrite (FOCUS_LED, LOW);
digitalWrite (SHUTTER_LED, bajo);
Delay(1000);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, alto);
//****************5
digitalWrite (FOCUS_LED, LOW);
Delay(500);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, bajo);
Delay(500);
digitalWrite (SHUTTER_LED, alto);
digitalWrite (FOCUS_LED, LOW);
digitalWrite (SHUTTER_LED, bajo);
Delay(1000);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, alto);
//****************6
digitalWrite (FOCUS_LED, LOW);
Delay(500);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, bajo);
Delay(500);
digitalWrite (SHUTTER_LED, alto);
digitalWrite (FOCUS_LED, LOW);
digitalWrite (SHUTTER_LED, bajo);
Delay(1000);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, alto);
//****************7
digitalWrite (FOCUS_LED, LOW);
Delay(500);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, bajo);
Delay(500);
digitalWrite (SHUTTER_LED, alto);
digitalWrite (FOCUS_LED, LOW);
digitalWrite (SHUTTER_LED, bajo);
Delay(1000);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, alto);
//****************8
digitalWrite (FOCUS_LED, LOW);
Delay(500);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, bajo);
Delay(500);
digitalWrite (SHUTTER_LED, alto);
digitalWrite (FOCUS_LED, LOW);
digitalWrite (SHUTTER_LED, bajo);
Delay(1000);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, alto);
//****************9
digitalWrite (FOCUS_LED, LOW);
Delay(500);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, bajo);
Delay(500);
digitalWrite (SHUTTER_LED, alto);
digitalWrite (FOCUS_LED, LOW);
digitalWrite (SHUTTER_LED, bajo);
Delay(1000);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, alto);
10 tiempo y más
digitalWrite (FOCUS_LED, LOW);
Delay(500);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, bajo);
Delay(500);
digitalWrite (SHUTTER_LED, alto);
digitalWrite (FOCUS_LED, LOW);
digitalWrite (SHUTTER_LED, bajo);
Delay(1000);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, alto);
}
void loop() {}
sleep.pwrDownMode(); modo sleep set
sleep.sleepInterrupt(0,RISING); (interrumpir el número 0 (o pin 2), interrumpir el estado de levantamiento)
doFocus();
doShot();
Delay(1000);
}
Enviar señal de foco
void doFocus() {}
digitalWrite (FOCUS_LED, LOW);
digitalWrite (FOCUS_ON, alto);
retardo (FOCUS_TIME);
digitalWrite (FOCUS_ON, bajo);
digitalWrite (FOCUS_LED, alto);
Delay(200);
}
Envío de señal del obturador
void doShot() {}
digitalWrite (SHUTTER_LED, bajo);
digitalWrite (SHUTTER_ON, alto);
retardo (SHUTTER_TIME);
digitalWrite (SHUTTER_ON, bajo);
digitalWrite (SHUTTER_LED, alto);
Delay(100);
color ámbar
digitalWrite (FOCUS_LED, LOW);
digitalWrite (SHUTTER_LED, bajo);
Delay(1000);
digitalWrite (FOCUS_LED, alto);
digitalWrite (SHUTTER_LED, alto);
}