kzim94
Published © GPL3+

Arduino Based Custom Exhaust Button

Custom button powered via Arduino controls aftermarket exhaust flaps!

IntermediateFull instructions provided4,272
Arduino Based Custom Exhaust Button

Things used in this project

Story

Read more

Schematics

Exhaust Schematic

Code

Exhaust Code

C/C++
//Program for opening and closing exhaust
//Version 1
//
//2.19.2021
//By: Ken Zimny

//==========================//
//Included Libraries
//==========================//

//EEPROM
#include <EEPROM.h>


//==========================//
//Definitions
//==========================//

//I/O pins
#define openRelay D2
#define closeRelay D1
#define exhaustButton D5


//==========================//
//Vars and Constants
//==========================//

//Debounce int
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin
int buttonReading;
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 70;    // the debounce time; increase if the output flickers

//exhaust open/close logic
bool exhaustState = 0;

//button pressed logic
bool buttonPressed = 0;

//OAT
const char* ssid = "";
const char* password = "";


void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  EEPROM.begin(512);
  pinMode(openRelay, OUTPUT);
  pinMode(closeRelay, OUTPUT);
  pinMode(exhaustButton, INPUT_PULLUP);

  //  EEPROM
  exhaustState = EEPROM.read(0);
}


void loop() {
  // put your main code here, to run repeatedly:

  //Read the exhaust button from the car
  if (digitalRead(exhaustButton) == LOW) {

    //reset the debouce
    if (digitalRead(exhaustButton) != lastButtonState) {
      lastDebounceTime = millis();
    }
    //debouuce the buttons
    if ((millis() - lastDebounceTime) > debounceDelay) {

      //Open or close the car exhaust
      if (exhaustState == 0 && buttonPressed == 0) {
        Serial.println ("Exhaust opening ");
        openExhaust();
        exhaustState = !exhaustState;
        EEPROM.write(0, exhaustState);
        EEPROM.commit();
        Serial.println ("Written to memory");
        buttonPressed = 1;
      }

      else if (exhaustState == 1 && buttonPressed == 0) {
        Serial.println ("Exhaust closing");
        closeExhaust();
        exhaustState = !exhaustState;
        EEPROM.write(0, exhaustState);
        EEPROM.commit();
        Serial.println ("Written to memory");
        buttonPressed = 1;
      }

    }
  }
  else {
    buttonPressed = 0;
  }
}

//Exhaust open/closed functions
void closeExhaust() {
  digitalWrite(closeRelay, HIGH); //active the close relay
  delay(2000);                    //wait 3 seconds to fully close the flaps
  digitalWrite(closeRelay, LOW);  //power off the relay
  delay(100);                     //delay added as pause between next button press
}

void openExhaust() {
  digitalWrite(openRelay, HIGH);  //active the close relay
  delay(2000);                    //wait 3 seconds to fully close the flaps
  digitalWrite(openRelay, LOW);   //power off the relay
  delay(100);                     //delay added as pause between next button press
}

Exhaust Code github

Credits

kzim94
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.