Arduino Shifter with Brake Swtch

This sketch is part of a gear selector for a car that uses a linear actuator to select the appropriate gear for an automatic transmission. The appropriate gear is selected using a dtsp toggle shift – move thru the gear in one direction and back.
Before a gear can be changed, i.e., go from Drive to Reverse etc. the brake switch via the brake pedal must be pushed down. The existing brake switch is normally closed, has 12 volts until the brake pedal is pushed down at which time the voltage goes to 0.
Using a feed from the brake switch, a 5 pin Bosch relay is used as input to the Arduino Uno to signal that the brake switch has gone from 12v to 0v at which time the toggle switch can change gears via the linear actuator.
I have tried numerous iterations of changing the sketch and/or the Bosch wiring to no avail.
Here is my sketch and the wiring diagram, which is really focused on the Bosch relay. Any help would be appreciated.
SHIFTER PIC.pdf (362.6 KB)

 #include <ezButton.h>

ezButton button1(A2);  
ezButton button2(A1);  
#define IN_PIN   4 
#define OUT_PIN  5 
#define POTENTIOMETER_PIN   A0 // the Arduino pin connected to the potentiometer of the actuator
int swcnt = 0;
int TargetPosition[7] = {77, 152, 202, 250, 302, 342, 382};
#define TOLERANCE  3
const int brksw  = 11;   //switch to make sure brake is pushed
int brkswState = HIGH;

void setup() {
  Serial.begin(9600);
  button1.setDebounceTime(50); // set debounce time to 50 milliseconds
  button2.setDebounceTime(50); // set debounce
  pinMode(IN_PIN, OUTPUT);
  pinMode(OUT_PIN, OUTPUT);
  pinMode(brksw, INPUT_PULLUP);
}
void UPDOWN() {
  button1.loop(); // MUST call the loop() function first
  button2.loop(); // MUST call the loop() function first

  int btn1State = button1.getState();
  int btn2State = button2.getState();
  brkswState = digitalRead(brksw);
  if (button1.isPressed() && brkswState == LOW) {
    swcnt++;
    if (swcnt > 6 ) {
      (swcnt = 6  );
    }
  }
  if (button1.isReleased()) {
    brkswState == HIGH;
  }
  if (button2.isPressed() && brkswState == LOW) {
    swcnt--;
    if (swcnt < 0) {
      (swcnt =  
      0 );
    }
  }
  if (button2.isReleased()) {
  brkswState = HIGH;
  }
}   
void loop() {
  UPDOWN();
  int stroke_pos = analogRead(POTENTIOMETER_PIN);
  if (stroke_pos < (TargetPosition[swcnt] - TOLERANCE)) {
    digitalWrite(IN_PIN, LOW);
    digitalWrite(OUT_PIN, HIGH);
  }
  else if (stroke_pos > (TargetPosition[swcnt] + TOLERANCE)) {
    digitalWrite(IN_PIN, HIGH);
    digitalWrite(OUT_PIN, LOW);
  }
  else
  {
    digitalWrite(IN_PIN, HIGH);
    digitalWrite(OUT_PIN, HIGH);
  }
  Serial.println(swcnt);
  Serial.print ("position  ");
  Serial.println(stroke_pos);
  Serial.print("target  ");
  Serial.println(TargetPosition[swcnt]);
}

What is expected to happen and what happens?

Why did you start a topic in the Uncategorised category of the forum when its description explicitly tells you not to ?

Your topic has been moved to a relevant category. Please be careful in future when deciding where to start new topics

1 Like

I would you to fry Arduinos, assuming you are connecting the coil pins, 87A and 30 directly to the Arduino. I do not have a clue as to what those numbers are. Your picture is missing a lot a annotated schematic would help a lot.

Standard relay pin numbers.

Yes, I found normally 30 is connected to 87a, energized it's 30 to 87.

Here just a switch.

I can't see what's wrong with the code, so @cdb0ewm shoukd say like @xfpd asks, what happens that is wrong or does not happen that is right.

The isPressed() calls are true once per press, I see no ping in setting anything with the isReleased() calls.

a7

those are the standard pins on a Bosch relay

You could just say what they do to save time. Already googled, so thanks.

a7

Yes I know that but what part of the relay do they connect to. I do not feel like spending the time to look it up. I also do not think the OP knows what the electrical system is like. Let me give the OP a hint:

As we know:Arduinos were designed for and are are intended for experimentation and learning, often with breadboards and loose wires that eventually break if vibrated. Most important, the boards are not protected against harsh, dirty or electrically noisy environments found in industrial, automotive and other commercial
applications. It is unreliable as it is not suitable for industrial, automotive and other commercial operation.

There is many good app notes such as AN2689 by ST on automotive electronics. reading it will help you a lot.
https://www.st.com/resource/en/application_note/cd00181783-protection-of-automotive-electronics-from-electrical-hazards-guidelines-for-design-and-component-selection-stmicroelectronics.pdf
Also take a look at these: Distilled Automotive Electronics Design | Analog Devices and
Transient Voltage Suppression in Automotive Applications
AEC-100 https://media.monolithicpower.com/mps_cms_document/w/e/Webinar_-_Fundamentals_of_AEC-

Temporarily take the brake inhibition out of the picture.

Either use a regular switch instead of the relay, or lie in the code and say the brake is pressed without bothering to digital read that input.

  brkswState = digitalRead(brksw);

  brkswState = LOW;   // forget the brake thing for now

a7

General use:

Specific use:

The current issue is that if you use the toggle switch to move the actuator it works if the brake is pushed or not. Its like it is disregarding the whole pushing of the brake

Backstreet rev head applications rarely do well ..........

Print the value you read from the brake input pin. Then figure out why brkswState is always LOW.

Use an ordinary switch on the brake input pin instead and see your code behaving.

Or say how your results are different.

a7

ok..thks I'll give it a try

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