Components and supplies
HK19F-DC 3V-SHG
FQP30N06L
Arduino UNO
Project description
Code
Exhaust Code
c_cpp
1//Program for opening and closing exhaust 2//Version 1 3// 4//2.19.2021 5//By: Ken Zimny 6 7//==========================// 8//Included Libraries 9//==========================// 10 11//EEPROM 12#include <EEPROM.h> 13 14 15//==========================// 16//Definitions 17//==========================// 18 19//I/O pins 20#define openRelay D2 21#define closeRelay D1 22#define exhaustButton D5 23 24 25//==========================// 26//Vars and Constants 27//==========================// 28 29//Debounce int 30int buttonState; // the current reading from the input pin 31int lastButtonState = LOW; // the previous reading from the input pin 32int buttonReading; 33unsigned long lastDebounceTime = 0; // the last time the output pin was toggled 34unsigned long debounceDelay = 70; // the debounce time; increase if the output flickers 35 36//exhaust open/close logic 37bool exhaustState = 0; 38 39//button pressed logic 40bool buttonPressed = 0; 41 42//OAT 43const char* ssid = ""; 44const char* password = ""; 45 46 47void setup() { 48 // put your setup code here, to run once: 49 50 Serial.begin(9600); 51 EEPROM.begin(512); 52 pinMode(openRelay, OUTPUT); 53 pinMode(closeRelay, OUTPUT); 54 pinMode(exhaustButton, INPUT_PULLUP); 55 56 // EEPROM 57 exhaustState = EEPROM.read(0); 58} 59 60 61void loop() { 62 // put your main code here, to run repeatedly: 63 64 //Read the exhaust button from the car 65 if (digitalRead(exhaustButton) == LOW) { 66 67 //reset the debouce 68 if (digitalRead(exhaustButton) != lastButtonState) { 69 lastDebounceTime = millis(); 70 } 71 //debouuce the buttons 72 if ((millis() - lastDebounceTime) > debounceDelay) { 73 74 //Open or close the car exhaust 75 if (exhaustState == 0 && buttonPressed == 0) { 76 Serial.println ("Exhaust opening "); 77 openExhaust(); 78 exhaustState = !exhaustState; 79 EEPROM.write(0, exhaustState); 80 EEPROM.commit(); 81 Serial.println ("Written to memory"); 82 buttonPressed = 1; 83 } 84 85 else if (exhaustState == 1 && buttonPressed == 0) { 86 Serial.println ("Exhaust closing"); 87 closeExhaust(); 88 exhaustState = !exhaustState; 89 EEPROM.write(0, exhaustState); 90 EEPROM.commit(); 91 Serial.println ("Written to memory"); 92 buttonPressed = 1; 93 } 94 95 } 96 } 97 else { 98 buttonPressed = 0; 99 } 100} 101 102//Exhaust open/closed functions 103void closeExhaust() { 104 digitalWrite(closeRelay, HIGH); //active the close relay 105 delay(2000); //wait 3 seconds to fully close the flaps 106 digitalWrite(closeRelay, LOW); //power off the relay 107 delay(100); //delay added as pause between next button press 108} 109 110void openExhaust() { 111 digitalWrite(openRelay, HIGH); //active the close relay 112 delay(2000); //wait 3 seconds to fully close the flaps 113 digitalWrite(openRelay, LOW); //power off the relay 114 delay(100); //delay added as pause between next button press 115}
Exhaust Code github
Exhaust Code
c_cpp
1//Program for opening and closing exhaust 2//Version 1 3// 4//2.19.2021 5//By: 6 Ken Zimny 7 8//==========================// 9//Included Libraries 10//==========================// 11 12//EEPROM 13#include 14 <EEPROM.h> 15 16 17//==========================// 18//Definitions 19//==========================// 20 21//I/O 22 pins 23#define openRelay D2 24#define closeRelay D1 25#define exhaustButton D5 26 27 28//==========================// 29//Vars 30 and Constants 31//==========================// 32 33//Debounce int 34int buttonState; 35 // the current reading from the input pin 36int lastButtonState = 37 LOW; // the previous reading from the input pin 38int buttonReading; 39unsigned 40 long lastDebounceTime = 0; // the last time the output pin was toggled 41unsigned 42 long debounceDelay = 70; // the debounce time; increase if the output flickers 43 44//exhaust 45 open/close logic 46bool exhaustState = 0; 47 48//button pressed logic 49bool 50 buttonPressed = 0; 51 52//OAT 53const char* ssid = ""; 54const char* password 55 = ""; 56 57 58void setup() { 59 // put your setup code here, to run once: 60 61 62 Serial.begin(9600); 63 EEPROM.begin(512); 64 pinMode(openRelay, OUTPUT); 65 66 pinMode(closeRelay, OUTPUT); 67 pinMode(exhaustButton, INPUT_PULLUP); 68 69 70 // EEPROM 71 exhaustState = EEPROM.read(0); 72} 73 74 75void loop() { 76 77 // put your main code here, to run repeatedly: 78 79 //Read the exhaust button 80 from the car 81 if (digitalRead(exhaustButton) == LOW) { 82 83 //reset the 84 debouce 85 if (digitalRead(exhaustButton) != lastButtonState) { 86 lastDebounceTime 87 = millis(); 88 } 89 //debouuce the buttons 90 if ((millis() - lastDebounceTime) 91 > debounceDelay) { 92 93 //Open or close the car exhaust 94 if (exhaustState 95 == 0 && buttonPressed == 0) { 96 Serial.println ("Exhaust opening "); 97 98 openExhaust(); 99 exhaustState = !exhaustState; 100 EEPROM.write(0, 101 exhaustState); 102 EEPROM.commit(); 103 Serial.println ("Written 104 to memory"); 105 buttonPressed = 1; 106 } 107 108 else if (exhaustState 109 == 1 && buttonPressed == 0) { 110 Serial.println ("Exhaust closing"); 111 112 closeExhaust(); 113 exhaustState = !exhaustState; 114 EEPROM.write(0, 115 exhaustState); 116 EEPROM.commit(); 117 Serial.println ("Written 118 to memory"); 119 buttonPressed = 1; 120 } 121 122 } 123 } 124 else 125 { 126 buttonPressed = 0; 127 } 128} 129 130//Exhaust open/closed functions 131void 132 closeExhaust() { 133 digitalWrite(closeRelay, HIGH); //active the close relay 134 135 delay(2000); //wait 3 seconds to fully close the flaps 136 137 digitalWrite(closeRelay, LOW); //power off the relay 138 delay(100); //delay 139 added as pause between next button press 140} 141 142void openExhaust() { 143 digitalWrite(openRelay, 144 HIGH); //active the close relay 145 delay(2000); //wait 3 seconds 146 to fully close the flaps 147 digitalWrite(openRelay, LOW); //power off the relay 148 149 delay(100); //delay added as pause between next button press 150}
Downloadable files
Exhaust Schematic
Exhaust Schematic
Exhaust Schematic
Exhaust Schematic
Comments
Only logged in users can leave comments
kzim94
0 Followers
•0 Projects
Table of contents
Intro
4
0