Finished the fly by wire throttle control

I made a fly by wire throttle controller for four engines at a TAFE NSW, vocational institute Grafton. Attached is the schematic and link to a video on you-tube. It took me a lot of hours to work the software out to be smooth, consistent, and quick in response. In the end it is very simple, yet performs quite complexly.

int potpin = A0;
int tps = A1;
int val1;
int val2;
int val3;
int led = 13;

void setup() {

TCCR2B = TCCR2B & 0b11111000 | 0x01; //sets PWM to 32 KHz
digitalWrite(led, HIGH); //turns LED in front panel on, letting you know the Arduino is running
}

void loop() {

val1 = analogRead(potpin); //reads POT position
val2 = analogRead(tps); //reads TPS position
val1 = map(val1, 1023, 0, 0, 1023); //sets POT Value between 0 and 1023, actually reverses the pot
val2 = map(val2, 862, 59, 0, 1023); //sets TPS Value between 0 and 1023

while(val2 < val1) { //routine if POT is ahead of TPS
if (val2 < 340) {
analogWrite(3, 60); //writes a PWM signal of 60 to pin 3 for first 3rd of throttle opening to smooth out low throttle settings
}
if (val2 > 339 && val2 < 680) {
analogWrite(3, 90); //write a PWM signal of 90 to pin 3 for middle 3rd of throttle positioning, this speeds up throttle response
}
if (val2 > 679) {
analogWrite(3, 120); //write a PWM signal of 120 to pin 3 for remainer of throttle positioning, this speeds up throttle response even faster
} //by limiting the PWM to an out put of 120, it regulates the output voltage to a maximum of 5 volts from the TIP120 attached
val1 = analogRead(potpin); //reads inputs for comparison in while loop
val2 = analogRead(tps);
val1 = map(val1, 1023, 0, 0, 1023);
val2 = map(val2, 862, 59, 0, 1023);
}

while(val2 > val1) { //routine if TPS is ahead of POT
analogWrite(3, 0); //sends a 0 to Pin 3 to turn off motor
val1 = analogRead(potpin); //reads inputs for comparison in while loop
val2 = analogRead(tps);
val1 = map(val1, 1023, 0, 0, 1023);
val2 = map(val2, 862, 59, 0, 1023);
}
}

2 Likes

I just realized the diode goes before the Electrolytic cap on the 12v input, the diode is the reverse polarity protection, if it came after the cap, it would protect the Arduino, but the cap would explode,lol. I only drew it this way in the schematic, I built it correctly. Also, do not leave out the diode across the motor terminals, i tried it without it and let the smoke out of a TIP120.
Charley

1 Like

I just realized by studying my code, that if I would have used a logarithmic potentiometer I could have eliminated even more of the code, oh well, live and learn:)
Charley

1 Like