giving a 360 continuous servo positional awareness with a switch system

hi I have a model made where I have six PIR sensors connected to a continuous servo allowing the servo to move to the position of the sensor that is detecting motion. my plan is to have two live wires or contact points sticking up from the body onto the rotating plate the servo moves. As the plate spins a strip of metal will connect the two wires completing the circuit giving a 'HIGH' reading and thus letting the continuous servo know where the zero position is and from there I can communicate the 360 degree revolution on a 6 x 60 segment basis. I'm looking for help turning this into some kind of code if anyone has done anything similar in the past I have sensor element written and it detects well and shows in the serial moniter just need the high reading and servo side of things.

many thanks.
Matt

Yes, you can do that.

Personally, I'd use an optical sensor like the QRE113 as it's not subject to corrosion and fatigue on the bare wires.

do you know how to write the code to achieve this?

We'd need more details on your project to help out with any code. You mentioned 6 positions but only one position has a sensor. I hope you're not expecting a lot of accuracy on those other positions.

What is it for? Why does it move? What makes it decide to move or stand still?

Post the code you have, in code tags. Use the full editor, via the "preview" button and use the button that looks like </> to format your code properly.

OP talks about a servo so should be quite accurate, though I don't see why you would need to zero that servo. Aren't servo controls normally absolute?

Six sensors, each 60 degrees apart to cover the full 360 degree, then it's a matter of writing the correct angle to the servo and it's pointing there.

Unless that "continuous servo" works a bit different.

I have six PIR sensors connected to a continuous servo

So as soon as the servo begins to move the PIR sensor will think their is movement in it's field of view and trigger. I can't see this working.

How I see it the connection is electric rather than mechanical, i.e. the sensors don't move, the servo moves to point in the direction of which PIR triggered.

hi all ill clear a few things up and add photos of the project. The 6 PIR sensors are mounted on the stationary base the only bard that will revolve is the top plate this will be used to mount a DSLR or other wireless camera. my sensors all work and give readings using the code attached below the code is based on a project similar to mine but they were working in 180 degrees rather than the 360. I was hoping the mechanical switch between the stationary body and revolving top plate would allow me to map the continuous servos movement for 360 degrees giving it positional awareness in a sense as the stops have been removed. if this is the case then the servo top plate should recalibrate every time is passes and creates the contact and maintain its accuracy. I am aware that the end footage won't be brilliant but as a concept I can build on this later

// 360 camera mount ***//


// 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 = 8; // 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[] = {0,60,120,180,240,300}; // 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

this is a university product design project the first coding and electronics I have attempted. I am aware that it might be a little rough around the edges theory wise but if I get it working I can built on that later. thanks for the help
matt

attached photos

Hi,
Ops pictures;

I understand you have a continuous servo, not a 180deg type, so you can only tell the servo to got one way or the other , but not to a particular direction.
If you have a reference limit switch, to give you a start position, how will you know how far you are turning from that reference position?

Tom.... :slight_smile:

How about sticking a small magnet on that board and then attaching a hall effect sensor or reed contact on the other side. One as "zero reference" or one at each PIR location so you can use this to know when you're pointing in that direction.

I was planning on having this switch contact and then run the continuous servo for the number of microseconds specific to my servo for 6 segments of 60 from the point of contact. The servo from point zero will detect motion at say 180 know that is three 60s from 0 and move there and so on I could be wrong though?

That is known as dead reckoning and is a lot less successful than you might hope. The thing is that every time you start and stop your motor their is an acceleration up to the working speed, and it is hard to account for this. Also changing direction introduces hysteresis in the gears.

I also have a sail winch servo as another option but I’m struggling with the code for that it is a GWS S125 6T D Sail Winch Servo if anyone has any experience with this?

Hi,
Is this thread associated with this thread?

https://forum.arduino.cc/index.php?topic=511506.msg3486434#msg3486434

Tom... :slight_smile:

Yes that’s me @tomgeorge