Using a pot as a limit switch

So I'm working on a project that is using actuators to raise and lower parts of a bed. i want to use the pot on the actuator as a limit switch so i don't over extend or break the bed when everything is at home position. i do have limits switches in the code those are for servo motors that i have yet to add to the code.

any help would be greatly appreciated

// constants won't change. They're used here to set pin numbers:
const int HeadUpPin = 53;    
const int HeadDownPin = 52;    
const int FootUpPin = 51;     
const int FootDownPin = 50;     
const int TiltUpPin = 49;     
const int TiltDownPin = 48;    
const int BedUpPin = 47;     
const int BedDownPin = 46;    
const int RotateStandPin = 45;     
const int RotateBedPin = 44;     
const int Macro1Pin = 43;     
const int Macro2Pin = 42;     
const int RotateBedStopPin=41;
const int RotateStandStopPin=40;
const int BedHeadUpPin=39;
const int BedHeadDownPin=38;
const int BedFootUpPin=37;
const int BedFootDownPin=36;

const int HeadUpRelayPin =  35;      // the number of the Realy1 pin
const int HeadDownRelayPin =  34;      // the number of the Relay2 pin
const int FootUpRelayPin =  33;      // the number of the Relay3 pin
const int FootDownRelayPin =  32;      // the number of the Relay 4 pin
const int TiltUpRelayPin =  31;      // the number of the Realy 5 pin
const int TiltDownRelayPin =  30;      // the number of the Relay6 pin

// variables will change:
int HeadUpButtonState = 0;         // variable for reading the pushbutton status
int HeadDownButtonState = 0;         // variable for reading the pushbutton status
int FootUpButtonState = 0;         // variable for reading the pushbutton status
int FootDownButtonState = 0;         // variable for reading the pushbutton status
int TiltUpButtonState = 0;         // variable for reading the pushbutton status
int TiltDownButtonState = 0;         // variable for reading the pushbutton status

const int HeadSensorPin = A0;    // select the input pin for the potentiometer
const int FootSensorPin = A1;    // select the input pin for the potentiometer
const int TiltSensorPin = A2;    // select the input pin for the potentiometer

int HeadValue = 0;  // variable to store the value coming from the sensor
int FootValue = 0;  // variable to store the value coming from the sensor
int TiltValue = 0;  // variable to store the value coming from the sensor
void setup() {


  //start serial connection
  Serial.begin(9600);

  // initialize the pushbutton pin as an input:
  pinMode(HeadUpPin, INPUT);
  pinMode(HeadDownPin, INPUT);
  pinMode(FootUpPin, INPUT);
  pinMode(FootDownPin, INPUT);
  pinMode(TiltUpPin, INPUT);
  pinMode(TiltDownPin, INPUT);
  // initialize the relay pin as an output:
  pinMode(HeadUpRelayPin, OUTPUT);
  pinMode(HeadDownRelayPin, OUTPUT);
  pinMode(FootUpRelayPin, OUTPUT);
  pinMode(FootDownRelayPin, OUTPUT);
  pinMode(TiltUpRelayPin, OUTPUT);
  pinMode(TiltDownRelayPin, OUTPUT);
}
void loop() {


  // read the value from the sensor:
  HeadValue = analogRead(HeadSensorPin);
  FootValue = analogRead(HeadSensorPin);
  TiltValue = analogRead(HeadSensorPin);  
  //print out the value of the pushbutton
  Serial.println(HeadValue);

  // read the state of the pushbutton values:
  HeadUpButtonState= digitalRead(HeadUpPin);
  HeadDownButtonState = digitalRead(HeadDownPin);
  FootUpButtonState= digitalRead(FootUpPin);
  FootDownButtonState = digitalRead(FootDownPin);
  TiltUpButtonState = digitalRead(TiltUpPin);
  TiltDownButtonState= digitalRead(TiltDownPin);


  
  // check if the pushbutton1 is pressed.
  // if it is, the buttonState is HIGH:
  // we also ensure tha the other button is not pushed to avoid conflict
  if (HeadUpButtonState == HIGH && HeadDownButtonState == LOW FootUpButtonState == LOW && FootDownButtonState == LOW TiltUpButtonState == LOW && TiltDownButtonState == LOW) {
    // turn relay1 on:
    digitalWrite(HeadUpRelayPin, HIGH);
  }
  // When we let go of the button, turn off the relay
  else if (digitalRead(HeadUpRelayPin) == HIGH) {
    // turn relay1 off:
    digitalWrite(HeadUpRelayPin, LOW);
  }

  // repeat the same procedure for the second pushbutton
  if (HeadUpButtonState == LOW && HeadDownButtonState == HIGH FootUpButtonState == LOW && FootDownButtonState == LOW TiltUpButtonState == LOW && TiltDownButtonState == LOW) {
    // turn relay2 on:
    digitalWrite(HeadDownRelayPin, HIGH);
  }
  // When we let go of the button, turn off the relay
  else if (digitalRead(HeadDownRelayPin) == HIGH) {
    // turn relay2 off:
    digitalWrite(HeadDownRelayPin, LOW);
  }
 // we also ensure tha the other button is not pushed to avoid conflict
  if (HeadUpButtonState == LOW && HeadDownButtonState == LOW FootUpButtonState == HIGH && FootDownButtonState == LOW TiltUpButtonState == LOW && TiltDownButtonState == LOW) {
    // turn relay1 on:
    digitalWrite(FootUpRelayPin, HIGH);
  }
  // When we let go of the button, turn off the relay
  else if (digitalRead(FootUpRelayPin) == HIGH) {
    // turn relay1 off:
    digitalWrite(FootUpRelayPin, LOW);
  }

  // repeat the same procedure for the second pushbutton
  if (HeadUpButtonState == LOW && HeadDownButtonState == LOW FootUpButtonState == LOW && FootDownButtonState == HIGH TiltUpButtonState == LOW && TiltDownButtonState == LOW) {
    // turn relay2 on:
    digitalWrite(FootDownRelayPin, HIGH);
  }
  // When we let go of the button, turn off the relay
  else if (digitalRead(FootDownRelayPin) == HIGH) {
    // turn relay2 off:
    digitalWrite(FootDownRelayPin, LOW);
  } 
// we also ensure tha the other button is not pushed to avoid conflict
  if (HeadUpButtonState == LOW && HeadDownButtonState == LOW FootUpButtonState == LOW && FootDownButtonState == LOW TiltUpButtonState == High && TiltDownButtonState == LOW) {
    // turn relay1 on:
    digitalWrite(TiltUpRelayPin, HIGH);
  }
  // When we let go of the button, turn off the relay
  else if (digitalRead(TiltUpRelayPin) == HIGH) {
    // turn relay1 off:
    digitalWrite(TiltUpRelayPin, LOW);
  }

  // repeat the same procedure for the second pushbutton
  if (HeadUpButtonState == LOW && HeadDownButtonState == LOW FootUpButtonState == LOW && FootDownButtonState == LOW TiltUpButtonState == LOW && TiltDownButtonState == HIGH) {
    // turn relay2 on:
    digitalWrite(TiltDownRelayPin, HIGH);
  }
  // When we let go of the button, turn off the relay
  else if (digitalRead(TiltDownRelayPin) == HIGH) {
    // turn relay2 off:
    digitalWrite(TiltDownRelayPin, LOW);
  }    

}

It's difficult to see what is driving what and when since the word Actuator doesn't appear anywhere in the code.

You seem to have 3 pots and you read them but then do nothing with the results (except print one of them with a misleading comment about "the value of the pushbutton").

Perhaps a description of your actuator(s) and relays together with a complete circuit diagram might help.

Steve

kd4tgc:
i want to use the pot on the actuator as a limit switch

What is preventing you?

Separately, the usual purpose of a limit switch is as a second line of defence in case the first part gets overrun. I would be tempted to use the potentiometer for normal use and also have limit switches that simply cut power to the motor without and intervention by the Arduino. You could write recovery code that the Arduino can apply after the limit switch has done its job.

...R

slipstick:
It's difficult to see what is driving what and when since the word Actuator doesn't appear anywhere in the code.

You seem to have 3 pots and you read them but then do nothing with the results (except print one of them with a misleading comment about "the value of the pushbutton").

Perhaps a description of your actuator(s) and relays together with a complete circuit diagram might help.

Steve

the actuators are 110VAC so they are switched by the relays.

And what about the 3 pots? They're not connected 110VAC are they? Will you please provide a circuit diagram of the system. You can see what you have...we can't.

Steve

here is the actuator wiring.

on the 110VAC side the

Red Wire goes to a relay
Black wire goes to relay

white common netural

on the pot

the red is 5v
the black is gnd
and the white is data going to the arduino

then i have 2 switches per actuator to make them move up and down.

I too would want to use mechanical limit switches hard wired to the motor - it provides a secondary independent safety loop in case the Arduino falls over .

Especially important if the motor or anything attached to it could be damaged .

@kd4tgc, you still have not answered my question about why you are having trouble using the potentiometer to indicate when the device is near its limits.

...R