# Motorised Pot - H Bridge with PID

Hi,
I've just started playing with some 10k motorised linear pots.

I have the analog read and motor control sorted with use of a h bridge.

I want to achieve the following:

Press button 1 and the potentiometer value is saved.

Press button 2 and the potentiometer returns to the saved value.

When the value is reached the program will have to exit the loop, otherwise the pot will be impossible to move if the controller is constantly trying to find a value.

I have had a look at the PID library but I have no idea how to modify it to control two outputs for one input.

I think I may be best off not using the library and just writing some code that controls the two direction outputs by pwm but I cannot find any example to help me get started.

I would have thought there would be some examples but cannot find any.

Anyone have any examples or ideas?

By two outputs, do you mean to the motor control inputs?

No sorry by outputs I mean the two direction outputs that control the h bridge circuit.

You don't need PID for this, although it may be a useful learning exercise.

Start with "P" control - work out which direction the pot needs to move and apply that direction signal to your motor controller (H bridge). Then work out how far away you are from the goal - apply a drive signal (PWM) proportional to this distance.

There is a minimum PWM value that will make the motor move. Anything smaller than this and it won't start to move, although it may keep moving if it was already moving. Make this the threshold for "close enough: stop."

Then if you really want PID, start adding the D terms - how quickly am I moving towards the goal, should I speed up or slow down? The I term is usually the most problematic and a huge proportion of PID controllers end up with set this to zero. This is based on time: "how long have I been away from my goal?"

When the value is reached the program will have to exit the loop, otherwise the pot will be impossible to move if the controller is constantly trying to find a value.

That makes sense... Once the position is found, you want it to stop and you want to be able to move it freely/manually without it fighting you, right?

Have you got a separate loop/function for button 2? You only want to enter that loop when you press button 2 and you want to exit as soon as it finds the position.