Hello everyone.
Ive started a rather long project to control my AC in my truck with a series of push buttons and LED indicators. The idea is to push one button that will cycle through specific outputs and control various relays connected to the AC fan, Temperature servo motor, and position servo motor. This is a show truck and the entire dash has been modified, leaving no room for the original AC controller.
I have 3 push buttons, one for the Fan speed selection, one for temperature, and one for position. As of now I have it all bench tested with no known issues at the moment, Though i am stuck adding the last feature.
The truck has a remote starter with 4 outputs that can be triggered from the key chain. I want to be able to select an output on the keychain that will send a negative pulse to the arduino, and then have the arduino do what i want. for example if i select AUX 2 on my keychain, i want the arduino to put the fan speed on high, temperature cold, and position forward, whereas if i select AUX 3 from my keychain i want fan speed high, temp hot, and position defrost.
My code:
const int FanSpeedButton = 2; // Fan speed control
const int TempButton = 3; // Temperature control
const int PositionButton = 4; // Position control
const int PositionForward = 13;
const int PositionDefrost = 12;
const int FanSpeed1 = A3;
const int FanSpeed2 = A2;
const int FanSpeed3 = A1;
const int FanSpeed4 = A0;
const int Temp1 = 5;
const int Temp2 = 6;
const int Temp3 = 7;
const int Temp4 = 8;
const int Temp5 = 9;
const int ACTrigger = 11; // Trigger for relay one to turn AC Compressor on
const int HotTrigger = 10; // Trigger for relay two to shut AC compressor off
const int RSCold = A4; // AUX 2 Input from remote starter for max cold
const int RSHot = A5; // AUX 3 Input from remote starter for max heat
int ButtonPushCounterFan = 0;
int ButtonStateFan = 0;
int lastButtonStateFan = 0;
int ButtonPushCounterTemp = 0;
int ButtonStateTemp = 0;
int LastButtonStateTemp = 0;
int ButtonPushCounterPosition = 0;
int ButtonStatePosition = 0;
int LastButtonStatePosition = 0;
void setup() {
pinMode(FanSpeedButton, INPUT);
pinMode(TempButton, INPUT);
pinMode(PositionButton, INPUT);
pinMode(PositionForward, OUTPUT);
pinMode(PositionDefrost, OUTPUT);
pinMode(FanSpeed1, OUTPUT);
pinMode(FanSpeed2, OUTPUT);
pinMode(FanSpeed3, OUTPUT);
pinMode(FanSpeed4, OUTPUT);
pinMode(Temp1, OUTPUT);
pinMode(Temp2, OUTPUT);
pinMode(Temp3, OUTPUT);
pinMode(Temp4, OUTPUT);
pinMode(Temp5, OUTPUT);
pinMode(ACTrigger, OUTPUT);
pinMode(HotTrigger, OUTPUT);
pinMode(RSCold, INPUT);
pinMode(RSHot, INPUT);
}
void loop()
{
ButtonStateFan = digitalRead(FanSpeedButton);
if (ButtonStateFan != lastButtonStateFan)
{
if (ButtonStateFan == HIGH) {
ButtonPushCounterFan++;
}
}
lastButtonStateFan = ButtonStateFan;
if (ButtonPushCounterFan == 1) {
digitalWrite(FanSpeed1, LOW);
} else {
digitalWrite(FanSpeed1, HIGH);
}
if (ButtonPushCounterFan == 2) {
digitalWrite(FanSpeed2, LOW);
} else {
digitalWrite(FanSpeed2, HIGH);
}
if (ButtonPushCounterFan == 3) {
digitalWrite(FanSpeed3, LOW);
} else {
digitalWrite(FanSpeed3, HIGH);
}
if (ButtonPushCounterFan == 4) {
digitalWrite(FanSpeed4, LOW);
} else {
digitalWrite(FanSpeed4, HIGH);
}
if(ButtonPushCounterFan >= 5) { // Resets counter
ButtonPushCounterFan=0;
}
ButtonStateTemp = digitalRead(TempButton);
if (ButtonStateTemp != LastButtonStateTemp)
{
if (ButtonStateTemp == HIGH) {
ButtonPushCounterTemp++;
}
}
LastButtonStateTemp = ButtonStateTemp;
if (ButtonPushCounterTemp == 0) {
digitalWrite(Temp1, LOW);
} else {
digitalWrite(Temp1, HIGH);
}
if (ButtonPushCounterTemp == 1) {
digitalWrite(Temp2, LOW);
} else {
digitalWrite(Temp2, HIGH);
}
if (ButtonPushCounterTemp == 2) {
digitalWrite(Temp3, LOW);
} else {
digitalWrite(Temp3, HIGH);
}
if (ButtonPushCounterTemp == 3) {
digitalWrite(Temp4, LOW);
} else {
digitalWrite(Temp4, HIGH);
}
if (ButtonPushCounterTemp == 4) {
digitalWrite(Temp5, LOW);
} else {
digitalWrite(Temp5, HIGH);
}
if ((ButtonPushCounterTemp >= 0)&&(ButtonPushCounterTemp <= 1)) {
digitalWrite(ACTrigger, LOW);
} else {
digitalWrite(ACTrigger, HIGH);
}
if ((ButtonPushCounterTemp >= 2)&&(ButtonPushCounterTemp <= 4)) {
digitalWrite(HotTrigger, LOW);
} else {
digitalWrite(HotTrigger, HIGH);
}
if(ButtonPushCounterTemp >= 5){
ButtonPushCounterTemp=0;}
ButtonStatePosition = digitalRead(PositionButton);
if (ButtonStatePosition != LastButtonStatePosition)
{
if (ButtonStatePosition == HIGH) {
ButtonPushCounterPosition++;
}
}
LastButtonStatePosition = ButtonStatePosition;
if (ButtonPushCounterPosition == 0) {
digitalWrite(PositionForward, LOW);
} else {
digitalWrite(PositionForward, HIGH);
}
if (ButtonPushCounterPosition == 1) {
digitalWrite(PositionDefrost, LOW);
} else {
digitalWrite(PositionDefrost, HIGH);
}
if(ButtonPushCounterPosition >= 2){
ButtonPushCounterPosition=0;}
}
What ive tried that doesnt exactly work, but gives an idea of what im trying to do:
if(RSCold == LOW) {
ButtonPushCounterFan=4;
}
if(RSHot == LOW) {
ButtonPushCounterFan=4;
ButtonPushCounterTemp=5;
ButtonPushCounterPosition=1;
}