Drive-By-wire pedal with a servo Please Help

drive by wire gas pedal from 06 nissan sentra
15lb force hobby servo
Roboduino Arduino board

I have the crazy project that i am using a drive by wire gas pedal (aka digital throttle) with a hobby servo. I am having a difficult time finding an answer to this problem. When i use the Arduino Knob Servo control, i cannot stop the servo from chattering. when i use a regular pot or this pedal, i have the same issue. I know what your thinking, you need an ecm for this pedal to work. not so, its just an oversized pot in the shape of a gas pedal. i am very new to all of this programming and all i really need to do is stop this servo from spazing out. any help will be appreciated. Thanks!

The DBW pedal should have 2 potmeters, with some ohms different, these 2 are used by the ECU, but how the ECU converts them i dont know.

this pedal has 2 pots in it. they are 2 regular everyday pots one is 5k ohm and the other is 10k ohm. i need to know how to make the servo to stop being erratic. this happens with any pot i hook to the roboduino

It would help to see your code posted. However it sounds like you are seeing normal variation (noise) in the raw A/D conversion from the pot. Depending on the quality of the pot, they can be a little noisy on there own.
It would most likely be better if you took say eight measurements in a row, added them together, and then divide by eight. This will act like a filter and should smooth out the analog reading you work from.


and you shouldn’t forget to ground any analog ins that are not in use. I had the problem when using a phototransistor some weeks ago, look at this:

Phototransistor output with all other analog ins unconnected:

Phototransistor output with all other analog ins grounded:

Pictures were taken with LogView, which is a nice little program to use once it’s setup correctly.
Hope I could help,


and you shouldn’t forget to ground any analog ins that are not in use.

Might a easier method be to set any unused analog inputs to digital output mode (and then set LOW) using their digital alias pin numbers (A0-A5 = D14-D19)?

Might be worth a try and save on external wiring requirements.


i am pretty new to the whole arduino scene. i only know BASIC and yet i forget alot of it. i havnt been able to find any simple easy to understand tuts on how to start programming this stuff. ive messed around with changing some things in the code that is included with the arduino but thats as far as i can get without crashing it.

my main concern right now is getting this servo to stop moving all over the place when the pot is set in one spot. i can get it to move back and forth with no problem but as soon as i stop, it keeps gittering back and forth. im using the simple code that came with arduino call Knob. Code posted below. I like the one idea where to take a multiple of readings and divide but i have no clue how to even go about setting that up.

#include <Servo.h>

Servo myservo;

int potpin = 0;
int val;

void setup()

void loop()
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);

int avgVal = 0;
int valCnt = 0;
int vals[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

void loop()
   // Get a value
   val = analogRead(potpin);

   // Put the value in an array
   vals[valCnt] = val;

   // If the array is full, start back at the beginning
   if(valCnt > 9)
      valCnt = 0;

   // Compute the average of the last 10 readings
   avgVal = 0;
   for(int i=0; i<10; i++)
      avgVal += vals[i];
   avgVal /= 10;

   // Map the average reading to the servo range
   val = map(avgVal, 0, 1023, 0, 179);

   // Set the servo based on the average reading

thanks for the code. how about using both pots inside this pedal? is there a way to setup both pots to control 1 servo and average between them or however it would work best?

How are you wiring up the pedal (or other pot) to the analog pin? Can you provide a quick diagram of it?

right now im only using one pot inside the pedal. For some reason, i cant get an image to post. Im using the basic knob control from arduinos site as the code. Middle pin on Analog 0 pin, +5v and gnd to outer pins. the servo is on digital pin 0. it seems to be smoother now with the new pedal connected. Theres nothing special about this pot. no pc boards or anything. its just a potentiometer in the shape of a gas pedal. i just didnt know if it would be more accurate with both pots connected or if i should be ok with just one.

i just didnt know if it would be more accurate with both pots connected or if i should be ok with just one.

No, using two pots to derive a single reading would just introduce more variations as the two pots cannot be expected to have perfect tracking. You are better off using averaging of multiple readings and getting an average from one pot.


@retrolefty: Thanks for the idea, why haven’t i thought about it myself…
I did a quick check in LogView and here are the results:

Voltage of all Analog Ins unconnected:

Voltage of all Analog Ins set to Digital Output and pulled low:

That will really save me the effort of always grounding all the remaining pis when only one is needed! Thank you!

Btw, here’s the sketch i used in case anyone wants do test it themselves:

void setup(){
  pinMode(14, OUTPUT);
  digitalWrite(14, LOW);
  pinMode(15, OUTPUT);
  digitalWrite(14, LOW);
  pinMode(16, OUTPUT);
  digitalWrite(14, LOW);
  pinMode(17, OUTPUT);
  digitalWrite(14, LOW);
  pinMode(18, OUTPUT);
  digitalWrite(14, LOW);
  pinMode(19, OUTPUT);
  digitalWrite(14, LOW);

void loop(){
  Serial.print(analogRead(0), DEC);
  Serial.print(analogRead(1), DEC);
  Serial.print(analogRead(2), DEC);
  Serial.print(analogRead(3), DEC);
  Serial.print(analogRead(4), DEC);
  Serial.print(analogRead(5), DEC);

Sounds like you’re wiring it up correctly. You should see less noise on the 5K pot than that 10K pot. But you may just have noisy pots. I was able to get a pretty clean signal on a 5K pot the other day when I was playing with the servo example code. It got a little jumpy when I used a 100K pot. Your servo itself may be jumpy. And any time you’re right at a value between two numbers the servo will bounce back and forth between the two. The only way to handle that is do averaging in your code. You can also put two low-value caps (.001-.1uf) across your pot to help quiet it down. But that will also slow down the response of the analog pin.

My gut says your pots are noisy.

You’re right. the test pot i was using was very noisy. it came out of an old radio. the pedal i am using is working flawlessly. no chatter or jitters. i want to take this time now to thank each and every one of you who has provided me information and/or code. im still so new at the whole programming thing so it will take me some time to get more advanced. Thanks again everyone!

Your code for pulling the analog pins low does not appear to be needed, unless what you posted was not what you were running.

You set each analog pin as an output pin, but then you pulled pin 14 low 6 times.

darn you’re right, the old copy paste problem… seems like just setting them as digital outs removes the noise as well, saves some lines of code.