Servo Code – Bill Byrd

This question comes from Bill Byrd:

Question

“The problem is that my servo doesn’t respond in any way to the potentiometer. I know the servo wiring is fine because it responds to the manual inputs. I know the pot is fine because I can actually jab a wire into A0 and measure the voltage change on my multi-meter. 
It had to be my code. But alas, I can find no errors. As a last resort, I searched the web for another sketch. This would rule out any hardware faults. It worked. I now have a servo controlled by the pot.”
//learning servos
//have not been able to get this to work

int myServo = 9;

//pin A0 has a pot attached, this pot will control servo
int Pin_potentiometer = A0;

//holds reading from pot
int Potentiometer_Value;

//We will be adjusting the voltage pulse to the servo
//this variable controls the length in time of the pulse
//int pulseWidth = 640;//640 left
//int pulseWidth = 1435;//1435 is center poz for my futaba servo
int pulseWidth = 2230;//2230 right

//in mike's final sketch, only the 2230 is un-commented

void setup() {
pinMode(myServo, OUTPUT);
pinMode(Pin_potentiometer, INPUT);
}

void loop() {

//sample the analog pin
Potentiometer_Value = analogRead(Pin_potentiometer);

//map raw value to the range we need to control servo with pot
pulseWidth = map(Pin_potentiometer, 0, 1023, 640, 2230);//per my futaba
digitalWrite(myServo, HIGH);
delayMicroseconds(pulseWidth);
digitalWrite(myServo, LOW);

delayMicroseconds(20000 - pulseWidth);//dwell time

delay(80);
}

Your Challenge

Take  a look at Bill’s code, and see if you can find what might be up…

Hint

Take a close look at this line of code:
  
  //map raw value to the range we need to control servo with pot
  pulseWidth = map(Potentiometer_Value, 0, 1023, 640, 2230);//per my futaba

Solution

My thoughts…

[fvplayer src=”https://vimeo.com/343056056″ transcript=”auto” splash=”https://i.vimeocdn.com/video/792102059_1280x720.jpg?r=pad” caption=”Servo Code – Bill Byrd”]

Your Thoughts

Has this type of switch-er-roo ever happened to you?

Leave a Comment