Rear steer sensing using throttle position sensor & Arduino

I don't own an Arduino yet and am completely new so please don't be too hard on me.

I have an offroad vehicle that has front and rear hydraulic steering. The front is controlled via a traditional steering wheel and an orbital steering valve. The rear is controlled via a 12-volt hydraulic solenoid valve. Push one button and the rear tires turn one way, the other button turns the tires the other way. There is no great way to know when the rear is perfectly centered though and no feature to automatically return it to center without driver input.

I am wanting to mount a 5v PWM throttle position sensor to a steering knuckle, read the output using the Arduino, and have the Arduino output either a left or right solenoid signal that will automatically bring the rear left or right back to center based on which direction it is offset at the moment user input is released. Ideally the system would also have a small knob / potentiometer? that adjusts center so that if components change over time the Home / center position can easily be tuned. There would also have to be an on / off switch so that the rear wasn't always trying to return to center if the user wanted it to stay put / be full manual.

Anyone have any advice as to where to start?

The attached sketch was written to control an actuator that is driven by a dc motor. There is a potentiometer that when centered results in close to 0 V on the motor. Turning the pot CCW causes the motor to turn one direction , turning the pot CW causes the motor to turn the opposite direction. The motor is controlled by a motor driver receiving a pwm signal. The MAP function converts the pot position into forward or reverse commands. Conditionals interpret PWM commands (<512 = REVERSE, >512 =FORWARD) and change the direction bits and then send value of the PWM command to the motor driver. Thus the motor driver direction bits are set to the direction necessary to retract the actuator and then the pwm command is sent to the motor driver. It’s possible that this sketch could be modified to work for your scenario. Note the STATE variables which effectively define forward or reverse, which for your case could be thought of as LEFT OR RIGHT.
Applying a PWM signal to a MOSFET (STP16NF06) controlling a hydraulic solenoid would result in progressive control of the solenoid
as opposed to simple ON/OFF.
Unless you can think of some reason why you shouldn’t pulse the solenoid it should work.
I would need more information about the solenoid valves.

// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!

#include <AFMotor.h>
int STATE =0;
int val=0;
AF_DCMotor motor(1);
int  pot =A0;
int  pot1 =A1;
int  pot2 =A2;
int  pot3 =A3;
int  pot4 =A4;
int  pot5 =A5;
void setup()
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
  // turn on motor

void loop()
  // uint8_t i;
   int val = analogRead(pot);
   Serial.print("pot= ");
   if (val>512)
       STATE =1;
   if (val<513)
       STATE =2;
   switch (STATE) 
    case 1:
      //do something when var equals 1
          val = map(val,513, 1023, 0, 255);
           Serial.print("val= ");
    case 2:
      //do something when var equals 2
          val = map(val, 512, 0, 0, 255);
          Serial.print("val= ");
      // if nothing else matches, do the default
      // default is optional

ACTUATOR_no_delay.ino (1.46 KB)

STP16NF06.pdf (318 KB)

Wow, that was a way more helpful first reply than I was expecting, thank you. :slight_smile:

The only reason I can see pulsing the valve being helpful would be if there was some sort of resolution issue in the sensor that resulted in quick movements not being interpreted correctly. In that case I guess you would want to pulse the solenoid as it nears center to get a more accurate stop point. But in reality simple ON / Off is faster which would be more desirable since the purpose would be to have the rear return to center as quickly as possible after a maneuver. Am I making sense here?

The PWM motor commands can be replaced with simple on/off relay (or mosfet) control commands. There are a few minor details you need to know about controlling inductive devices like relays or solenoids using transistors or mosfets, one of which is the need for a back-emf protective diode: You would need one or more (up to three) of these across the solenoid with the banded end at the + terminal of the solenoid. This would protect the mosfet or transistor from the reverse voltage when the magnetic field collapses on turn off. If you use a relay to control the solenoid then you would probably only need one or two of these. (If sparkfun had a higher rated diode you would only need one)

Can you draw a schematic by hand and post a photo of it ?

Happy to draw something up by hand and post it, but before I do I just want to clarify ... you are wanting a schematic of the current system without the proposed Arduino control, correct?

Another thing, which Arduino would be best suited for this? I want it to be as simple as possible and it will need to be able to be housed in some sort of weather-proof housing to protect it.


Along with a word description of desired modification.

Thanks. I'll get something drawn up tomorrow and post it.

I forgot to mention, I need the part # of the solenoid so I can look up the specs.

Sorry for the delay, here is a link the the valve:

I'm scribbling now ...

Very crude, but …

I can't find the current rating for the solenoid. Do you know how many mA it draws ? If know can you measure it with a meter ?
Also, I don't understand how the pot factors into this. If the switches are either ON or OFF and ONLY ONE can be ON at any given moment, then what is the purpose of the pot and how is it supposed to work ?

The pot would adjust ultimate 0 / center. So lets just say that the throttle sensor sweeps 0-5 volts with 2.5v being "center." In that case 2.5v means steer left to return and > 2.5v means steer right to return to center. But then lets say that I go out and ram into a large rock at 60mph and something in the system bends or deforms slightly and now 3 volts is center. If center wasn't adjustable the system would then always want to return to 2.5v and not be centered. At that point the pot would be used to "adjust" the value for center. This would also be useful for initial installation so that I didn't have to mess with trying to perfectly center the throttle sensor with the axle alignment. It wouldn't matter if I was a little off because I could just adjust center on the fly.

I have no specs on the solenoids yet. I will have to call the manufacturer during business hours for that.

I don't see any contacts on the solenoid. What is the connection between the switches in you drawing and the solenoid that does not appear to have any electrical contacts ( although it must, somewhere) . Please draw a schematic of the solenoid.

The contacts are inside that plastic housing on the top in the pic. You unscrew the metal name plate to access them. They are just 3 screw terminals, one positive that is switched between two negatives, one for each solenoid. the solenoids are fastened to a hydraulic spool valve that gets pulled one way or the other by the opposing solenoid when they are energized. Otherwise it is sprung closed in the center when neither are activated.

  int leftswitch = 3;
int rightswitch = 4;
int potwiper = A0;
int potposition = 0;

void setup()
  pinMode(leftswitch, OUTPUT);
  pinMode(rightswitch, OUTPUT);

void loop()
  potposition = analogRead(potwiper);
  if (potposition < 511)
     digitalWrite(leftswitch, HIGH);
  if (potposition > 512)
     digitalWrite(rightswitch, HIGH);

The device used to turn on the solenoid cannot be chosen until we have the specs on the current. It can be a relay or a Mosfet.
If it is a relay it is probably a good idea to put a snubber circuit on it to absorb the energy when switched on or off. A snubber circuit is a resistor and a cap that prevent the contacts from arcing.
This is probably the closest I can come to showing the actual schematic for the solenoid:

The 82 ohm resistor is a 2 or 3 W resistor. Snubbers are available as integrated packages but most people just buy the parts at Radioshack and put it on a small perfboard mounted on standoffs.

solenoid snubber.jpg