Car exhaust dump project

Okay I want to program a electronic exhaust dump for my car to work with a single push button. These dumps come wired with a two position switch that you hold one way to (for approximately five seconds) to open it, and the same but the other position of the switch to close it. I am assuming not ever working with one of these that they cannot source 12v 500ma to the motor to open up the dump valve. So assuming I use relays on two of the outputs to trigger external source of voltage, can I make some sort of current sensing after the relay to know when the dump is open or closed and tell the output to stop trying to open or close (because the current spikes right when the motor starts and the motor maxes out) I would also need a delay because of the current spike right at the beginning of each cycle.

thanks guys!!!

electronic exhaust dump

Why do you want to do this?

I have a 600hp audi, it's to open up the exhaust to make the twin turbo's breath a little better. The lower amount of restriction for airflow at the track the better.

This code is for an UP/DOWN counter, but it works with two button and will allow you to do something when held for a certain amount of time.

const byte buttonPin1 = 2; // Up button
const byte buttonPin2 = 3; // Down Button
//const int ledPin =  11;

boolean buttonState1 = 0;
boolean lastReading1 = 0;
boolean buttonState2 = 0;
boolean lastReading2 = 0;
unsigned long onTime1 = 0, onTime2 = 0;
unsigned long interval = 1000;
unsigned long holdAmount = 5;
int count = 0, lastCount;

void setup() { 
  //pinMode(ledPin, OUTPUT);      
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);

  Serial.begin(115200);  
}

void loop()
{ 
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);

  // Count up
  if (buttonState1 == HIGH && lastReading1 == LOW) // is the button pressed (HIGH) ?
  {
    onTime1 = millis(); // record current time
    //Do an action when PRESSED
    count < 60 ? count++ : count = 0;
  }

  // Count Down
  if (buttonState2 == HIGH && lastReading2 == LOW) // is the button pressed (HIGH) ?
  {
    onTime2 = millis();// record current time
    //Do an action when PRESSED
    count > 0 ? count-- : count = 59;
  }

  //hold Up
  if (buttonState1 == HIGH && lastReading1 == HIGH) // is the button pressed (HIGH) and seen that it was previously pressed?
  { 
    if ((millis() - onTime1) >= interval ) // check if a certain amount of time has passed  
    {
      onTime1 = millis(); // update time
      //Do the action if the time passed is equal or greater than the interval
      count < 60? count += holdAmount : count = 0;
      lastReading1 = LOW; // update the last reading to prevent multiple executions of this IF statement
    } 
  }

  //Hold Down
  if (buttonState2 == HIGH && lastReading2 == HIGH)// is the button pressed (HIGH) and seen that it was previously pressed?
  { 
    if ((millis() - onTime2) >= interval )// check if a certain amount of time has passed  
    {
      onTime2 = millis();// update time
      //Do the action if the time passed is equal or greater than the interval
      count > 0 ? count -= holdAmount : count = 59;
      lastReading2 = LOW;// update the last reading to prevent multiple executions of this IF statement
    } 
  }

  //print to serial monitor (Optional)
  if(count != lastCount)
  {
   Serial.println(count);
   lastCount = count;
  }
  
  //update last states
  lastReading1 = buttonState1;
  lastReading2 = buttonState2;
}

How would I adapt that for a single push button?

Slight alteration.

const int buttonPin = 2;     
const int ledPin =  13;

bool 
  buttonState   = 0,
  lastReading   = 0,
  toggle        = false,
  released      = true;
  
unsigned long onTime=0;

void setup() 
{ 
  pinMode(ledPin, OUTPUT);      
  pinMode(buttonPin, INPUT);
  Serial.begin(115200);  
}

void loop()
{ 
  buttonState = digitalRead(buttonPin);

  //Button pressed
  if (buttonState == HIGH && lastReading == LOW) 
    onTime = millis(); // current time

  //Button held
  if (buttonState == HIGH && lastReading == HIGH) 
  { 
    if ((released == true) && (millis() - onTime) > 500 ) // half second hold time
    {
      toggle = !toggle; // on -> off :: off -> on
      digitalWrite(ledPin, toggle); // LED based on toggle variable
      lastReading = LOW;
      released = false; // button is still being held, so only do this statement once pre press
    } 
  }
  
  //Button released
  if(buttonState == LOW)
   released = true;
   
  lastReading = buttonState;
}

I just bought a Leonardo and a motor shield which says it has built in current sensing! I'm new to these so I am not too familiar with the whole thing. I did program a boebot back in high school which I know is much more simplified. I am not 100% sure how these shields work. Are the pin headers just pass through and it adds on the higher current motor driver outputs?

Please excuse my ignorance with this device, and thanks for your help man!

I don't know which shield you bought so you would need to do some research on it.

That's the shield I bought I would like to set up the current sensing as well if possible, and the current of the motor greatly increases as is reaches its limits (and also on start up, so a really short delay on current sensing would have to be implemented)

Function pins per Ch. A pins per Ch. B
Direction D12 D13
PWM D3 D11
Brake D9 D8
Current Sensing A0 A1

Using this chart, you should be able to write a simple code to control your motors.

And yes you can have current sensing, but I don't know the formula to convert the analog reading into the actual current. (You can look for that)