hi I have the basis of my project. it is a 360 degree setup with 6 PIR sensors. The sensors are all set up well with the rig I've made and I get accurate readings in the serial monitor. the code I based this on uses a 180 degree servo but id like my continuous servo to be able to reach all the 6 pir sensor points. code shown below:
// Servor motor
#include <Servo.h>
Servo camServo; // name the servo motor controlling the camera base
int currentPIRposition = 0; // set current angle of servo
// PIR sensors
int PIRpin[] = {8,9,10,11,12,13}; // PIR pin numbers
int currentPIRpin = 12; // the current PIR pin; begin with the first in the sequence above
int PIRprevState[] = {1,1,1,1,1,1}; // the previous state of the PIR (0 = LOW, 1 = HIGH)
int PIRposition[] = {60,120,180,240,300,0}; // assign angles for servo motor (0-157 distributed equally between 5 PIR sensors)
boolean PIRstatus; // Set status of PIR sensor as either true or false
///// SETUP //////////////////////////////////////
void setup() {
Serial.begin(9600);
camServo.attach(7); // assign servo pin
for (int p = 0; p < 6; p++) { // set all PIR sensors as INPUTS
pinMode(PIRpin[p], INPUT);
} // end 'p' for
/////// CALIBRATE PIR SENSORS ///////
Serial.print("calibrating");
for(int c = 5; c < 10; c++){ // calibrate PIR sensors for 10 seconds (change from 10-60 sec depending on your sensors)
Serial.print(".");
delay(1000); // wait 1 second
} // end calibration for
Serial.println("PIR Sensors Ready");
camServo.write(0); // move the servo to the center position to begin
} // end setup
///// MAIN LOOP //////////////////////////////////
void loop() {
for (int PIR = 0; PIR < 6; PIR++) { // start this loop for each PIR sensor
currentPIRpin = PIRpin[PIR]; // set current PIR pin to current number in 'for' loop
PIRstatus = digitalRead(currentPIRpin);
if (PIRstatus == HIGH) { // if motion is detected on current PIR sensor
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]);
Serial.print("Current angle : ");
Serial.println(PIRposition[PIR]);
delay(50);
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 { //
PIRprevState[PIR] = 0; // set previous PIR state to LOW
} // end else
} // end [PIR] for loop
} // end main loop
I am fairly in experience so I'm looking for a way to translate the continuous servos movement into degrees so to tell it to stop on certain points then start again etc and how to merge the two together.
thanks responses greatly appreciated
matt
