Automatic gearbox with 'while' code

Im trying to make automatic gearbox and basically have one variable reading for one input and have 5 existing conditions (gears). So would it be possible to make multiple while code way that based on imput it keeps on going gear or it lowers gear or raise gear? Input can divide in 3 levels and thats not hard. Im not just sure how to make multiple while conditions or is there even easier way to make this?

Thank you

T

You say "one input". What kind of input? Digital, analog, serial?

By "5 existing conditions (gears)" you mean you have 5 gears?

I would recommend a state machine. You rarely need while loops since the loop() function is called over and over again.

Here are some tutorials that might help:

State Machine

BlinkWithoutDelay

Arduino Multiple Things

Several Things at a Time

Analog input and yes 5 gears

IF these are REAL gears and you have something meshing with the teeth, how do you ensure the teeth are aligned before you change gears?

Yes those are real gears but I havent designed the gearbox. I have just speed censor which gives me information what gear when needs to on. shifting is mechanical so this is not anything new and superb.

Then I can guess you are not also designing synchro-mesh gears/clutches to force the gears into proper tooth synchornization. How many gear boxes have you worked with?

I would have a look at some of the existing shift systems available . If the shift is to be truly automatic you need to think about varying the shift point with engine load , downshifts for engine braking etc etc . Also momentarily disabling fuelling etc during shift .
Not a simple task , even assuming you have the mechanical side sorted .

Not clear whether this is a true auto box with planetary gears or a conventional box with a shifter clutch etc

There are also safety issues to think about - shifting into first at high speed ?

Dont worry guys I have working it already way Im satisfied with potentiometer. I just want to add feedback loop this code to make it fully auto. Its driven by electric motor and in code I have 6 different situation but it actually doesnt matter if reverse direction must be turned on manually.

void setup() {

  Serial.begin(9600);
  
  pinMode(22,OUTPUT);
  pinMode(23,OUTPUT);
  pinMode(24,OUTPUT);
  pinMode(25,OUTPUT);
  pinMode(26,OUTPUT);
  pinMode(27,OUTPUT);
  pinMode(28,OUTPUT);
  pinMode(29,OUTPUT);
  pinMode(30,OUTPUT);
  pinMode(31,OUTPUT);
  pinMode(32,OUTPUT);
  pinMode(33,OUTPUT);
  pinMode(34,OUTPUT);
  pinMode(35,OUTPUT);
  pinMode(36,OUTPUT);
  pinMode(37,OUTPUT);

  pinMode(A1, INPUT);
}

void loop() {

  int sensorValue = analogRead(A1);
  
  if (sensorValue <= 170.5 ) 
 {digitalWrite(22, HIGH);
  digitalWrite(23, LOW);
  digitalWrite(24, HIGH);
  digitalWrite(25, HIGH); 
  digitalWrite(26, LOW);
  digitalWrite(27, HIGH);
  digitalWrite(28, HIGH);
  digitalWrite(29, LOW);
  digitalWrite(30, HIGH);
  digitalWrite(31, HIGH);
  digitalWrite(32, LOW);
  digitalWrite(33, HIGH);
  digitalWrite(34, HIGH);
  digitalWrite(35, LOW);
  digitalWrite(36, HIGH);
  digitalWrite(37, HIGH);
 }
  if (sensorValue >= 170.6 && sensorValue < 341)
 {digitalWrite(22, HIGH);
  digitalWrite(23, HIGH);
  digitalWrite(24, LOW);
  digitalWrite(25, LOW); 
  digitalWrite(26, LOW);
  digitalWrite(27, HIGH);
  digitalWrite(28, HIGH);
  digitalWrite(29, HIGH);
  digitalWrite(30, LOW);
  digitalWrite(31, LOW);
  digitalWrite(32, LOW);
  digitalWrite(33, HIGH);
  digitalWrite(34, HIGH);
  digitalWrite(35, HIGH);
  digitalWrite(36, LOW);  
  digitalWrite(37, LOW);
 }
  if (sensorValue >= 341.1 && sensorValue < 511.5)
 {digitalWrite(22, HIGH);
  digitalWrite(23, HIGH);
  digitalWrite(24, LOW);
  digitalWrite(25, LOW);  
  digitalWrite(26, HIGH);
  digitalWrite(27, LOW);
  digitalWrite(28, LOW);
  digitalWrite(29, LOW);
  digitalWrite(30, HIGH);
  digitalWrite(31, HIGH);
  digitalWrite(32, HIGH);
  digitalWrite(33, LOW);
  digitalWrite(34, LOW);
  digitalWrite(35, HIGH);  
  digitalWrite(36, LOW);
  digitalWrite(37, LOW);
 } 
  if (sensorValue >= 511.6 && sensorValue < 682)
 {digitalWrite(22, LOW);
  digitalWrite(23, HIGH);
  digitalWrite(24, LOW);
  digitalWrite(25, LOW);  
  digitalWrite(26, HIGH);
  digitalWrite(27, LOW);
  digitalWrite(28, LOW);
  digitalWrite(29, HIGH);
  digitalWrite(30, LOW);
  digitalWrite(31, HIGH);
  digitalWrite(32, LOW);
  digitalWrite(33, HIGH);  
  digitalWrite(34, HIGH);
  digitalWrite(35, LOW);
  digitalWrite(36, HIGH);
  digitalWrite(37, HIGH);
 }
  if (sensorValue >= 682.1 && sensorValue < 852.5)
 {digitalWrite(22, LOW);
  digitalWrite(23, HIGH);
  digitalWrite(24, LOW); 
  digitalWrite(25, LOW);
  digitalWrite(26, HIGH);
  digitalWrite(27, LOW);
  digitalWrite(28, LOW);
  digitalWrite(29, HIGH);
  digitalWrite(30, LOW);
  digitalWrite(31, LOW);
  digitalWrite(32, HIGH); 
  digitalWrite(33, LOW);
  digitalWrite(34, HIGH);
  digitalWrite(35, LOW);
  digitalWrite(36, HIGH);
  digitalWrite(37, HIGH);
 }
  if (sensorValue >= 852.6 && sensorValue < 1023)
 {digitalWrite(22, LOW);
  digitalWrite(23, HIGH);
  digitalWrite(24, LOW);
  digitalWrite(25, LOW);
  digitalWrite(26, HIGH);
  digitalWrite(27, LOW);
  digitalWrite(28, LOW);
  digitalWrite(29, HIGH);
  digitalWrite(30, LOW);  
  digitalWrite(31, LOW);
  digitalWrite(32, HIGH);
  digitalWrite(33, LOW);
  digitalWrite(34, LOW);
  digitalWrite(35, HIGH);
  digitalWrite(36, LOW);
  digitalWrite(37, LOW);
 }}

I have opened couple of times car gearbox. In Pontiac Trans am there is issue in manual reverse gear what could be switched accidentaly in fast forward speed and I once opened that kind of gearbox. Second thing was Toyota Supra automatic transmission gear changer was damaged.

An int can NEVER have a fractional part.

What are the 16 outputs for? Is it displaying something on a 16-segment display?

Not sure what the 16 outputs do but you could make your code a lot more compact using arrays.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.