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.

Grab any potentiometer you can get your hands on. (Not a "logarithmic" type.) Plug it into the Arduino's 5V, ground and an analog input.

Load up the example sketch ReadAnalogVoltage from 01. Basics. Change the Serial.print() so that it prints the sensorValue instead of voltage.

Run the sketch, open up Serial Monitor and see what you get.

The middle of the pot travel should give a value like 512. Anything bigger than 512 can be considered to be "forwards" and anything smaller can be "backwards". The difference between your value and 512 is how hard to push the motor.

Note that your physical installation will mean that the true middle won't be at 512. So this is a configuration that will change over the life of your project. Make it a "constant" and put that declaration at the top of your code. Use that named constant anywhere you would have used "512".

Here's the full tutorial for that example: https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage

IE something like this:

  boolean direction = value < 512;
  int speed = abs (value - 512);
  boolean deadband = speed < 20 ;  // define a definite sized deadband for off.

Deadbands are very useful for this sort of control, otherwise you have to fiddle around to get something
precisely in the middle...

Multiple post: Motor Controller - Pot for forward and reverse - Microcontrollers - Arduino Forum