Servo for Gripper

Hello everyone. I'm newbie here.

I planned to make a robotic arm controlled by a webserver. Almost all the codes are working perfectly except for the gripper. I made a code for the gripper and I don't think it match to what I really wanted. I wanted to control the gripper's servo through html button and make it move slowly by pressing the button once and make it stop by pressing it again and the same concept with the reverse of it. I need also to set its limit for the servo inorder to prevent it by destroying itself if ever forgotten to make it stop. By the way, I used a 180 servo.

If someone could help me. Any suggestion will be helpful. Thank you

xiaram:
If someone could help me. Any suggestion will be helpful. Thank you

The usual advice - post your Arduino code.

Without seeing your code we have no idea what is going on.

Have you looked at the servo sweep example that comes with the Arduino IDE?

...R

Robin2:
The usual advice - post your Arduino code.

Without seeing your code we have no idea what is going on.

Have you looked at the servo sweep example that comes with the Arduino IDE?

...R

Sorry for that. I made a code which I'll be able to set my upper and lower limits. But how it moved when I pressed the button is not what I wanted to be. Here is the code...

if (readString.indexOf("?buttonhold") >0){  //tell the arm to go down              
                {                                  
                  (pos=pos+30); //change value for larger increments
                  if(pos>90) (pos=90); //limit lower value                
                  servogriptwist.write(pos); // tell servo to go to position in variable 'pos'                   
                } 
           }
           if (readString.indexOf("?buttonrelease") >0){  //tell the arm to go up                
                {                  
                  (pos=pos-30); //change value for larger increments
                  if(pos<0) (pos=0); //limit upper value                  
                  servogriptwist.write(pos); // tell servo to go to position in variable 'pos'                                     
                } 
           }

xiaram:
Sorry for that. I made a code which I'll be able to set my upper and lower limits. But how it moved when I pressed the button is not what I wanted to be.

First, your code snippet seems to have two superfluous "}"
If these are legitimate they must belong to code you have not shown and may be the cause of the problem.

You have not told us what you want to happen and what actually happens. "not what I wanted" is no help.

AND you don't need to repeat the line servogriptwist.write(pos); Just put it once after the two IF statements

...R

Robin2:
First, your code snippet seems to have two superfluous "}"
If these are legitimate they must belong to code you have not shown and may be the cause of the problem.

You have not told us what you want to happen and what actually happens. "not what I wanted" is no help.

AND you don't need to repeat the line servogriptwist.write(pos); Just put it once after the two IF statements

...R

The code is working perfectly, I just don't know how to state in the code what I wanted.
I already stated what I wanted on my first post.

I wanted to control the gripper's servo through html button and make it move slowly by pressing the button once and make it stop by pressing it again and the same concept with the reverse of it. I need also to set its limit for the servo inorder to prevent it by destroying itself if ever forgotten to make it stop.

xiaram:
The code is working perfectly,

Then there is part of your code that is relevant but not included in your snippet.

Looking back to your first post, are you saying that you want the servo to keep moving even if you are not pressing the button. Press once - start moving and keep moving Press again - stop moving.

To do that you need to set a variable when the button is pressed. If the variable is true then the stepper moves. Another press of the button will set the variable back to false.

If you need more advice please post the entire code.

...R

Robin2:
Then there is part of your code that is relevant but not included in your snippet.

Looking back to your first post, are you saying that you want the servo to keep moving even if you are not pressing the button. Press once - start moving and keep moving Press again - stop moving.

To do that you need to set a variable when the button is pressed. If the variable is true then the stepper moves. Another press of the button will set the variable back to false.

If you need more advice please post the entire code.

...R

I think you're right. I'm looking to do the code but I couldn't figure it out. That's why I posted here if ever somebody could give suggestions or any code that is relevant to what I wanted.

Other duplicate threads are now locked.
I wish I could be bothered to merge them into one, but I really can't.

DO NOT CROSS-POST, IT WASTES TIME.

AWOL:
Other duplicate threads are now locked.
I wish I could be bothered to merge them into one, but I really can't.

DO NOT CROSS-POST, IT WASTES TIME.

I'm very sorry for my behavior. I'm just being desperate now knowing that our professor moved the date of the submission of my project sooner.
I will be more cautious on using the forum from now on. And again I'm very sorry.

xiaram:
I think you're right. I'm looking to do the code but I couldn't figure it out. That's why I posted here if ever somebody could give suggestions or any code that is relevant to what I wanted.

You need to give me more to work with.

I suggested this in Reply #5

To do that you need to set a variable when the button is pressed. If the variable is true then the stepper moves. Another press of the button will set the variable back to false.

Have you tried it? Do you understand what I mean?
If you don't understand then please explain what you don't understand so I know how to help you.

...R

Robin2:
I suggested this in Reply #5 Have you tried it? Do you understand what I mean?
If you don't understand then please explain what you don't understand so I know how to help you.

...R

I understand the logic there but I'm very poor in coding if you could give me a sample code to analyze with.

If I understand correctly, the logic is like this, shown as pseudo code since we're not going to write your code for a school assignment.

I envisage a "flag" called gripperLastSeenClosing, which we would initialise to "true", so that the first button push will be to open it.

Every even number push stops the servo if I understand? In the ButtonStateChange example you can see how to look for every 4th press, adapt that for every 2nd one.

// pseudo code

If press number is even, stop the gripper
Else
    If gripperLastSeenClosing is true, open the gripper and set gripperLastSeenClosing to false
      Else close the gripper and set gripperLastSeenClosing to true

.

Have a think along those lines....

That's all very off-the-top-of-my-head, seeing as it'as 8am on Saturday and I'm lying in bed.....

Some servo test code for incrementally moving a servo. You should be able to develop your servo code using the serial monitor, then port it to a web page setup.

// zoomkat 3-28-14 serial servo incremental test code
// using serial monitor type a character (s to increase or a 
// to decrease) and enter to change servo position 
// (two hands required, one for letter entry and one for enter key)
// use strings like 90x or 1500x for new servo position 
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include<Servo.h>
String readString;
Servo myservo;
int pos=1500; //~neutral value for continous rotation servo
//int pos=90;

void setup()
{
  myservo.attach(7, 400, 2600); //servo control pin, and range if desired
  Serial.begin(9600);
  Serial.println("serial servo incremental test code");
  Serial.println("type a character (s to increase or a to decrease)");
  Serial.println("and enter to change servo position");
  Serial.println("use strings like 90x or 1500x for new servo position");
  Serial.println();
}

void loop()
{
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }
  if (readString.length() >0) {
    if(readString.indexOf('x') >0) { 
      pos = readString.toInt();
    }

    if(readString =="a"){
      (pos=pos-1); //use larger numbers for larger increments
      if(pos<0) (pos=0); //prevent negative number
    }
    if (readString =="s"){
      (pos=pos+1);
    }

    if(pos >= 400) //determine servo write method
    {
      Serial.println(pos);
      myservo.writeMicroseconds(pos);
    }
    else
    {   
      Serial.println(pos);
      myservo.write(pos); 
    }
  }
  readString=""; //empty for next input
}

xiaram:
I understand the logic there but I'm very poor in coding if you could give me a sample code to analyze with.

You would learn a great deal more if you make an attempt at writing the code, no matter how poor you are at coding. Then we can help to improve it.

80% of coding is simply thinking about the steps needed to get something to happen. The other 20% is writing the code in the language for the applications.

...R