Motor Controller - Pot for forward and reverse

I'm designing a throttle for an electric motor installed on a boat and I'm planning to use an L298N H-Bridge Motor Driver, with an Arduino Uno.

I would like to use a throttle lever (fixed to a potentiometer) which will rotate through 180 degrees. With 180 to 90 degrees being reverse, 90 degrees being "off" , and 90 to 0 degrees being forward.

I understand I can use a potentiometer as an analog input into the arduino, but I'm not sure on how to achieve the reverse and forward action from only one potentiometer.

I don't want to include a button to switch to reverse in my device, it must be done through the single pot.

I haven't used arduino before so I'm not too clued up the code I would need to do this, although I have figured out the coding for wiring in a button to switch to reverse and using a pot to increase speed (which I don't want to do).

Any help would be much appreciated.

So many ways to do this...

One idea is to use a pot with the wiper sweeping from 0V to 5V with some dead room in the middle. The range 0 to 411 is used for reverse where 0 is fast and 411 is slow. The range 612 to 1023 is forward where 612 is slow and 1023 is fast.

      fast-rev   slow-rev| stop |slow-fwd   fast-fwd
0V----/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\-----5V
                           ^
                           |
                           |
                           A0
      0                  411    612                 1023

The real question is how to control the PWM signals to make the motor do what you want, and what to do about regenerative power which I think is a likely issue.

A regular potentiometer typically has 270 degrees of rotation. Since you want your throttle to use only 180 degrees, you need to compensate for this reduction in travel.

180/270=0.6667 so you end up with 67% of the Arduino’s 1023 analog counts or 682.

(1023-682)/2 gives us the offset at either end so if we use the middle range of the pot, you’ll see an approximate range of 170 to 852 counts for 180 degrees of travel. It is very simple to turn this into a more suitable set of numbers by using the map function like this:

 result = map(analogRead(A0,170,852,-255,255);

Where result will equal -255 at full reverse and 255 at full forward with of course zero in the middle. You’ll have to tweak the values of 170 and 852 for the exact pot you use.

Multiple post: Motor Controller - Pot for forward and reverse - Motors, Mechanics, Power and CNC - Arduino Forum