steering of a drawbar

Hi,

I've a question about a program.
I'm programming a steering for a drawbar, but it have a zero stand.
when the drawbar comes to the zero stand, the drawbar will turn a little left and a little right, and so on.

But i thought there was something wrong in my code
Maybe someone can check my code and give me some advice.

this is the code:
Serial.begin(9600);
pinMode(hoeksensor1, INPUT);
pinMode(rechts, OUTPUT);
pinMode(links, OUTPUT);
pinMode(led, OUTPUT);
}

void loop(){
hoeksensor1 = analogRead(5);
Serial.println(hoeksensor1);

if(hoeksensor1 > 576){//stuurt naar rechts
delay(5);
digitalWrite(links, LOW);
digitalWrite(rechts, HIGH);
digitalWrite(led, HIGH);
}

if(hoeksensor1 < 567){//stuurt naar links
delay(5);
digitalWrite(links, HIGH);
digitalWrite(rechts, LOW);
digitalWrite(led, HIGH);
}

if(hoeksensor1 < 573){
if(hoeksensor1 > 570){
digitalWrite(links, LOW);
digitalWrite(rechts, LOW);
digitalWrite(led, LOW);
}
}
delay(5);
}

i hope someone had advice!

Thanks,

Geert-Jan

Sorry, but that is obviously not the code. Did you mess up copy/paste and why did you not put the code in code tags as requested in the stickies of this forum ?

In your Arduino IDE:
Select Tools->Auto Format
Do not proceed until Auto Format works without errors.
Click in the editor window
Press CTRL+A to select all text in the editor window
Press CTRL+C to copy the text

In the forum Editor
Click on the # icon above the window
Press CTRL-V to paste the text.

That being said, have you actually looked at the values returned from the analogRead()? If not, you might be surprised to see what sort of range you get when the drawbar is stationary. You will probably need to increase your deadband (the range of values for which you don't perform a links or rechts operation).

drawbar
zero stand

Maybe some explanation of the jargon would help (me anyway). To me a drawbar is found on a caravan and I have no idea what "zero stand" means.


Rob

Ohh, sorry, excuse me.
Because I'm a Dutchman and my English is a little bit bad.
Hope to forgive me :slight_smile: ?

But what is mean is a drawbar by a farmer. With this drawbar you can steer the trailer.
But its already resolved.

the only thing is that the returned value will vary from 550 to 554.
Is it normal?

So thanks to reply to me and i hope you understand me now better.

Geert-Jan

Your use of the word "drawbar" is perfectly correct. The problem is that you have not explained what you are trying to do.

What has an Arduino to do with a trailer? Is it a full sized farm trailer or a model?

What is producing the values 550 to 554?

...R

You're printing the return value from analogRead(). Yes it's normal for this to vary up and down a bit.

You haven't explained what the code is intended to achieve but from what you've said and based on what the code does currently I guess you're trying to use the input to decide whether to move something left or right, and then stop it when it reaches the correct position.

The logic isn't ideal for that. First, you have redundant if statements. Secondly, you don't apply any hysteresis or dead band.

I think some logic like this would work better:

if(hoeksensor1 > 576)
{
   // too far left, so move right
}
else if (hoeksensor1 > 567)
{
  // in the deadband, stop here
}
else 
{
    // too far right, move left
}

I'm not sure whether I have got the sense of left/right correct, and you have lots of magic values there which I don't understand what they mean, but hopefully this example gives you the idea how how you compare the value to work out which range it is in and take action based on that.

Thank you very much!

This is a good example, yes. But Arduino is only used to follow the path of the tractor. but its only an experiment.
But now I`m gona try this.

I think its now clear for me.

Geert-Jan