How to Incorporate a Set Point for Actuator

I have setup a system where two individual relays are connected to an actuator. Upon activating a button one relay will switch on extending the actuator reversely upon press the other button the other relay will activate retracting the actuator. I need the actuator to return to a desired set point upon releasing each button. Anyone have any idea how I could incorporate this into my code?

largeLinearManualButton.ino (2.67 KB)

No idea because I cannot see your program. No one can on a mobile or a pad when you attach it rather than posting it correctly using code tags, the </> icon.

Why did you abandon this thread, it looks like the same program and topic.

http://forum.arduino.cc/index.php?topic=594153

Perhaps you should read/review the posting rules: How to use this forum

WattsThat:
No idea because I cannot see your program. No one can on a mobile or a pad when you attach it rather than posting it correctly using code tags, the </> icon.

Why did you abandon this thread, it looks like the same program and topic.

Problem starting with Arduino Uno - #570719 - Uno Punto Zero - Arduino Forum

Perhaps you should read/review the posting rules: How to use this forum

Again mate I'm new to this, I don't really know what I'm doing yet as I haven learnt and I reposted as I couldn't find the original thread, it just so happened someone replied allowing me to find it again.

but here's the code if your going to help me thanks in advance!

<// constants won't change. They're used here to set pin numbers:
const int button1Pin = 2; // the number of the pushbutton1 pin
const int button2Pin = 4; // the number of the pushbutton2 pin
const int relay1Pin = 7; // the number of the Realy1 pin
const int relay2Pin = 8; // the number of the Relay2 pin

// variables will change:
int button1State = 0; // variable for reading the pushbutton status
int button2State = 0; // variable for reading the pushbutton status

const int sensorPin = 0; // select the input pin for the potentiometer
int sensorValue = 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(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
// initialize the relay pin as an output:
pinMode(relay1Pin, OUTPUT);
pinMode(relay2Pin, OUTPUT);
}

void loop(){

// read the value from the sensor:
sensorValue = analogRead(sensorPin);
//print out the value of the pushbutton
Serial.println(sensorValue);

// read the state of the pushbutton values:
button1State = digitalRead(button1Pin);
button2State = digitalRead(button2Pin);

// 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 (button1State == HIGH && button2State == LOW) {
// turn relay1 on:
digitalWrite(relay1Pin, HIGH);
}
// When we let go of the button, turn off the relay
else if (digitalRead(relay1Pin) == HIGH) {
// turn relay1 off:
digitalWrite(relay1Pin, LOW);
}

// repeat the same procedure for the second pushbutton
if (button1State == LOW && button2State == HIGH) {
// turn relay2 on:
digitalWrite(relay2Pin, HIGH);
}
// When we let go of the button, turn off the relay
else if (digitalRead(relay2Pin) == HIGH) {
// turn relay2 off:
digitalWrite(relay2Pin, LOW);
}
}//>

PS: your schematic is incomprehensible. You should draw that with paper and pencil, those fritzing things are useless. You’ve got one motor terminal connected to ground, 5V and A0. That is just going to kill your Arduino.

Time to start over.

Not knowing what you’re doing with an Arduino is quite understandable but it is no excuse for not reading the instructions you’ve been given.

Please edit your post and correct the code listing per the rules of the fourm.

Here becasue I'm a nice chap, is the OP's code in tags:

/*

Manual Linear Actuator Control using an Arduino and two pushbuttons
 
This demo shows how to do basic manual control of a large linear
actuator using an Arduino and two buttons. The first button extends
the actuator and the second retracts the actuator.
 
 
 The circuit:
 * RobotGeek Pushbutton - Digital Pin 2
 * RobotGeek Pushbutton - Digital Pin 4
 * RobotGeek Relay - Digital Pin 7 
 * RobotGeek Relay - Digital Pin 8 
 
Products Used in this demo:
 - http://www.robotgeek.com/linear-actuators
 - http://www.robotgeek.com/robotgeek-geekduino-sensor-kit
 - http://www.robotgeek.com/robotGeek-pushbutton
 - http://www.robotgeek.com/robotgeek-relay


 */

// constants won't change. They're used here to set pin numbers:
const int button1Pin = 2;     // the number of the pushbutton1 pin
const int button2Pin = 4;     // the number of the pushbutton2 pin
const int relay1Pin =  7;      // the number of the Realy1 pin
const int relay2Pin =  8;      // the number of the Relay2 pin

// variables will change:
int button1State = 0;         // variable for reading the pushbutton status
int button2State = 0;         // variable for reading the pushbutton status

const int sensorPin = 0;    // select the input pin for the potentiometer
int sensorValue = 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(button1Pin, INPUT);     
  pinMode(button2Pin, INPUT);    
  // initialize the relay pin as an output:
  pinMode(relay1Pin, OUTPUT);    
  pinMode(relay2Pin, OUTPUT);    
}

void loop(){
  
  
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin); 
  //print out the value of the pushbutton
  Serial.println(sensorValue);    
  
  // read the state of the pushbutton values:
  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);

  // 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 (button1State == HIGH && button2State == LOW) {     
    // turn relay1 on:    
    digitalWrite(relay1Pin, HIGH);  
  } 
  // When we let go of the button, turn off the relay
  else if (digitalRead(relay1Pin) == HIGH) {
    // turn relay1 off:
    digitalWrite(relay1Pin, LOW); 
  }
  
  // repeat the same procedure for the second pushbutton
  if (button1State == LOW && button2State == HIGH) {     
    // turn relay2 on:    
    digitalWrite(relay2Pin, HIGH);  
  } 
  // When we let go of the button, turn off the relay
  else if (digitalRead(relay2Pin) == HIGH) {
    // turn relay2 off:
    digitalWrite(relay2Pin, LOW); 
  }  
}

And the pic:

WattsThat:
PS: your schematic is incomprehensible. You should draw that with paper and pencil, those fritzing things are useless. You’ve got one motor terminal connected to ground, 5V and A0. That is just going to kill your Arduino.

Not to defend OP, but I'll guess the actual actuator (for which there is no Fritzy symbol, so he chose a normal motor?) has a feedback pot which is connected to A0. I see in the code, that A0 is read but the value doesn't seem to be used, except to be printed.

I reposted as I couldn't find the original thread, it just so happened someone replied allowing me to find it again.

Perhaps this thread should be abandoned in favour of the other one, where maybe there was some progress?

arduin_ologist:
Here becasue I'm a nice chap, is the OP's code in tags:

/*

Manual Linear Actuator Control using an Arduino and two pushbuttons

This demo shows how to do basic manual control of a large linear
actuator using an Arduino and two buttons. The first button extends
the actuator and the second retracts the actuator.

The circuit:

  • RobotGeek Pushbutton - Digital Pin 2
  • RobotGeek Pushbutton - Digital Pin 4
  • RobotGeek Relay - Digital Pin 7
  • RobotGeek Relay - Digital Pin 8

Products Used in this demo:

*/

// constants won't change. They're used here to set pin numbers:
const int button1Pin = 2;    // the number of the pushbutton1 pin
const int button2Pin = 4;    // the number of the pushbutton2 pin
const int relay1Pin =  7;      // the number of the Realy1 pin
const int relay2Pin =  8;      // the number of the Relay2 pin

// variables will change:
int button1State = 0;        // variable for reading the pushbutton status
int button2State = 0;        // variable for reading the pushbutton status

const int sensorPin = 0;    // select the input pin for the potentiometer
int sensorValue = 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(button1Pin, INPUT);   
  pinMode(button2Pin, INPUT);   
  // initialize the relay pin as an output:
  pinMode(relay1Pin, OUTPUT);   
  pinMode(relay2Pin, OUTPUT);   
}

void loop(){
 
 
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  //print out the value of the pushbutton
  Serial.println(sensorValue);   
 
  // read the state of the pushbutton values:
  button1State = digitalRead(button1Pin);
  button2State = digitalRead(button2Pin);

// 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 (button1State == HIGH && button2State == LOW) {   
    // turn relay1 on:   
    digitalWrite(relay1Pin, HIGH); 
  }
  // When we let go of the button, turn off the relay
  else if (digitalRead(relay1Pin) == HIGH) {
    // turn relay1 off:
    digitalWrite(relay1Pin, LOW);
  }
 
  // repeat the same procedure for the second pushbutton
  if (button1State == LOW && button2State == HIGH) {   
    // turn relay2 on:   
    digitalWrite(relay2Pin, HIGH); 
  }
  // When we let go of the button, turn off the relay
  else if (digitalRead(relay2Pin) == HIGH) {
    // turn relay2 off:
    digitalWrite(relay2Pin, LOW);
  } 
}




And the pic:


![Button Control Schematic_bb.jpg|3078x1944](upload://tlEdO27Tb5Os8BZ0afm4Y9q9nM.png)



Not to defend OP, but I'll guess the actual actuator (for which there is no Fritzy symbol, so he chose a normal motor?) has a feedback pot which is connected to A0. I see in the code, that A0 is read but the value doesn't seem to be used, except to be printed.

Perhaps this thread should be abandoned in favour of the other one, where maybe there was some progress?

Thank You arduin_ologist

There didn't seem to be as some people seem to be more interested in poking holes in my work rather than helping me, I thought this forum would be able to help me in this current project and improve myself for further projects but sadly it seems this isn't the case. If anyone does have any idea I would greatly appreciate their assistance as I am really struggling with this project.

P.S 'WattsThat' can I don't care for your unhelpful comments mate no need

lj1996nicho:
P.S 'WattsThat' can I don't care for your unhelpful comments mate no need

All s/he said was that you should read the rules and edit your code into tags, thus: [code] sketch goes here [/code]. Forums have rules for a reason; I've been in forums since before they were called forums, and there has to be some order.

But I think in the interests of sanity, you should chose which of your threads you want keep, and click Report to Moderator in the other one to ask for its deletion or locking. We'll all go bonkers trying keep track in two treads.

Your demo program only works because you are there watching the actuator and intuitively know when it has reached the limits of it's travel and can stop it and go the the other way.

You need to equip the actuator with sensors so your program has the same knowledge as you do. You need sensors to detect the end limits of the the actuator, and in your specific case, a sensor to tell your program when the midpoint is reached.

Paul

arduin_ologist:
All s/he said was that you should read the rules and edit your code into tags, thus: [code] sketch goes here [/code]. Forums have rules for a reason; I've been in forums since before they were called forums, and there has to be some order.

But I think in the interests of sanity, you should chose which of your threads you want keep, and click Report to Moderator in the other one to ask for its deletion or locking. We'll all go bonkers trying keep track in two treads.

Thank you mate, I didn't see the rules honestly before posting but I can appreciate there needs to be rules to ensure order. I will remove the older thread and keep this one. Cheers for being polite about it mate

Motors have no end point
Relays are on off only.
What it sounds like you are looking for is a feedback that can tell you where you are.
A linear pot might work
A rotary ecnoder with pulley and string might work.

dave-in-nj:
What it sounds like you are looking for is a feedback that can tell you where you are.
A linear pot might work
A rotary ecnoder with pulley and string might work.

Not to defend the OP's cross-posting, but in #3 of his/her other thread there's a link this actuator, which has a pot built in.

Those are not cheap, and OP will not want to trash the investment, but I wonder if the Firgelli actuators that work like servos (the -R series, iirc) might not make life several orders of magnitude simpler.

dave-in-nj:
Motors have no end point
Relays are on off only.
What it sounds like you are looking for is a feedback that can tell you where you are.
A linear pot might work
A rotary ecnoder with pulley and string might work.

Depending on the situation, limit switches could also be used (and would be super easy to implement)

Power_Broker:
Depending on the situation, limit switches could also be used (and would be super easy to implement)

Altho it seems the actuator has a pot built in, going off OP's other thread. Also he wants to use a
button to centre the thing and might not be as easy to fit a switch mid way and or chanve its pos one day if needed.

Hi
The OP wants the actuator to got to centre when the buttons are released.
This should not be difficult to do with that actuator and its position pot.
Halfway will correspond to a voltage out of the pot of about half the voltage across the the entire pot.

What are the part numbers of your relays, the ones in your fritzy are SPST, but I assume you are using SPDT.
The motor is capable of drawing 5A, so I wonder what relay it is that can be driven directly from the Uno and switch a decent set of contacts.

The fritzy also refers to a motor shield, but you show no connections.

Can I suggest you please post a copy of your circuit as a picture of a hand drawn circuit in jpg, png?

Tom.... :slight_smile:

TomGeorge:
Hi
The OP wants the actuator to got to centre when the buttons are released.
This should not be difficult to do with that actuator and its position pot.
Halfway will correspond to a voltage out of the pot of about half the voltage across the the entire pot.

What are the part numbers of your relays, the ones in your fritzy are SPST, but I assume you are using SPDT.
The motor is capable of drawing 5A, so I wonder what relay it is that can be driven directly from the Uno and switch a decent set of contacts.

The fritzy also refers to a motor shield, but you show no connections.

Can I suggest you please post a copy of your circuit as a picture of a hand drawn circuit in jpg, png?

Tom.... :slight_smile:

You are exactly right mate, that is exactly what I want ! Due to the lack of components available in the software I have used to draw up the schematic, I used some to represent what id used.
Think its a good idea if I get an actual picture of of the actual components.

Just draw the circuit by hand and take a pic with your phone...

Hi,
You are best to shy away from using Fritzy, it is a pictorial method of circuit representation and as you have found, it is easy to end up with a rats nest of coloured lines.

Hand drawing a proper schematic is better in the long run, you have all the component symbols in your head and a multitasking drawing device in your hand.

Tom... :slight_smile:

I really wish I had one of those actuators to play with, but commercial grade alas doesn't come at hobby prices.

Is there such a thing as a hobby grade (read as: cheap) linear actuator with a feedback pot?

I will try later on to code this up with a couple of leds to simulate the motor going one way or the other, and turn a pot by hand as if it was actually moving.

But OP the first thing you need to do is study the state change detect example so you can tell when your button is newly released.

Then when you detect a new release of one of the buttons you need to compare the current value of the pot to the setpoint value in a while(), and while the values are not the same (or within a few points of deadband I guess) you need to drive the motor the right way towards the setpoint. When the values are the same (or withing the few points deadband) stop the motor.

Hello I have completed a sketch of the circuit, hope this isn't too complicated.