The process of making a enclosure for the device can be seen here.
In the begining, I tried to add the RGB led to this device, in order to have a red, green or blue color of light for night shooting. But when I found that one color of the RGB led won’t work if I use the servo and RGB led together. Now I realize that problem is I can’t have two independent PWM outputs on an ardunio. So to solve the problem, I have to add an micro controller to the Arduino to control them separately with different duty cycles.
The codes(Servo only) are here:
// Servor motor
#include <Servo.h>
Servo camServo; // name the servo motor controlling the camera base
// LED status lights
int LEDpin[] = {11,12,13}; // LED pin numbers
int currentLEDpin = 11; // the current LED pin; begin with the first in the sequence above
// PIR sensors
int PIRpin[] = {2,3,4}; // PIR pin numbers
int currentPIRpin = 2; // the current PIR pin; begin with the first in the sequence above
int PIRprevState[] = {1,1,1}; // the previous state of the PIR (0 = LOW, 1 = HIGH)
int PIRposition[] = {180,90,0}; // assign angles for servo motor (0-157 distributed equally between 5 PIR sensors)
int currentPIRposition = 0; // set current angle of servo
boolean PIRstatus; // Set status of PIR sensor as either true or false
void setup() {
Serial.begin(9600);
camServo.attach(7); // assign servo pin
for (int p = 0; p < 3; p++) { // set all PIR sensors as INPUTS
pinMode(PIRpin[p], INPUT);
} // end ‘p’ for
for (int l = 0; l < 3; l++) { // set all LEDs as OUTPUTS
pinMode(LEDpin[l], OUTPUT);
} // end ‘l’ for
} // end setup
void loop() {
for (int PIR = 0; PIR < 3; PIR++) { // start this loop for each PIR sensor
currentPIRpin = PIRpin[PIR]; // set current PIR pin to current number in ‘for’ loop
currentLEDpin=LEDpin[PIR]; // set current LED pin to current number in ‘for’ loop
PIRstatus = digitalRead(currentPIRpin);
if (PIRstatus == HIGH) { // if motion is detected on current PIR sensor
digitalWrite(currentLEDpin, HIGH); // turn corresponding LED on
if(PIRprevState[PIR] == 0) { // if PIR sensor’s previous state is LOW
if (currentPIRposition != currentPIRpin && PIRprevState[PIR] == 0) { // if high PIR is different than current position PIR then move to new position
camServo.write(PIRposition[PIR]);
currentPIRposition = currentPIRpin; // reset current PIR position to active [PIR] pin
PIRprevState[PIR] = 1; // set previous PIR state to HIGH
}
PIRprevState[PIR] = 1; // set previous PIR state to HIGH if the current position is the same as the current PIR pin
} // end PIRprevState if
} // end PIRstatus if
else { //
digitalWrite(currentLEDpin, LOW); //the led visualizes the sensors output pin state
PIRprevState[PIR] = 0; // set previous PIR state to LOW
} // end else
} // end [PIR] for loop
} // end main loop
Leave a comment