/*

Ahanix / XirallicBolts

Objectives:

1) Determine and activate if a remote start has been performed

2) Immediately turn off headlamps

3) Turn on heated seats and defrost, then turn headlamps back on

4) When the car is being driven, turn off passenger seat and defrost

Resistors for signal inputs:

15k 10k

12v Signal --\/\/\/\-+-\/\/\/\--- Ground

|_____________5v signal to Arduino

Known Problems:

Defrost LED will not turn on. As we are directly engaging the defrost

relay, there is no solution.

25-Pin Connector Pinout

1) +12v (Arduino) 9) Autolamp + 17) -- 25) Ground

2) +12v (Dashcam) 10) Autolamp - 18) High Beam +12v

3) -- 11) -- 19) High Beam Signal

4) Driver Seat 12) -- 20) High Beam Solenoid +

5) Passenger Seat 13) -- 21) High Beam Solenoid -

6) Defrost 14) -- 22) --

7) -- 15) Horn 23) --

8) -- 16) Brake Lamp 24) Ground

Todo:

Move high beam relay to its own daughterboard, give separate 9-pin connector.

Create dummy plug with just 9-pin to high beams and a jumper for autolamps.

*/

// Set a bunch of variables because I'm a terrible coder.

int HornTriggered = 0; // Has the horn been chirped?

int BrakeTriggered = 0; // Have the brakes been pressed?

int MonitorCycle = 0; // For the 'Watch for the horn' loop

int BrakeCycle = 0; // For the "Watch the brakes while idling' loop

int BrakeReading = 0; // Debug: The actual value detected on the brake circuit

int MonitorComplete = 0; // Only allow the cycle to run once

void setup() {

// Pin 5: Horn Input (Digital)

// Pin A0: Brake Lamp (Analog)

pinMode(7, OUTPUT); // Autolamp

pinMode(8, OUTPUT); // Driver Seat

pinMode(9, OUTPUT); // Passenger Seat

pinMode(10, OUTPUT); // Defrost relay

pinMode(11, OUTPUT); // Monitor cycle LED Yellow

pinMode(12, OUTPUT); // Horn triggered LED Red

digitalWrite(7, HIGH);

digitalWrite(8, HIGH); // No idea why these are reversed. Just rolling with it.

digitalWrite(9, HIGH);

digitalWrite(10, HIGH);

digitalWrite(11, LOW);

digitalWrite(12, LOW);

}

void loop() {

Serial.begin(115200);

Serial.write("



Hi!



");

if(MonitorComplete == 0){ // On boot, this is 0. After this first loop, it'll be 1.

Serial.write("

Beginning 10-second monitor for horn...");

digitalWrite(11, HIGH); // Yellow LED on

while(MonitorCycle < 1000){ // 10 seconds

Serial.write(digitalRead(

if(digitalRead(5) == LOW){

Serial.write("

>> HORN: Low signal condition detected!");

digitalWrite(7, LOW); // Autolamp Off

digitalWrite(12, HIGH); // Red LED on

HornTriggered = 1;

}

MonitorCycle++;

digitalWrite(13, !digitalRead(13));

delay(10);

}

digitalWrite(13, LOW);

Serial.write("

Monitor Complete.");

digitalWrite(11, LOW); // Yellow LED off

}

if(MonitorComplete == 1){

Serial.write("

On-boot monitor has already been completed. Waiting 1 minute then resetting");

delay(60000);

}

MonitorComplete = 1; // Comment me out to loop constantly

if(HornTriggered == 1){

Serial.write("



A remote start condition was detected.

Waiting 5 seconds and activating relays...");

delay(5000);

digitalWrite(8, LOW); // Driver seat ON

delay(500);

digitalWrite(8, HIGH); // Driver seat OFF

delay(250);

digitalWrite(9, LOW); // Passenger seat ON

delay(500);

digitalWrite(9, HIGH); // Passenger seat OFF

delay(2000);

digitalWrite(10, LOW); // Rear window defrost ON

delay(1750);

digitalWrite(7, HIGH); // Autolamp On

Serial.write("



Now monitoring A0 for the next fifteen minutes");

while(BrakeCycle < 12000){ // 15 minutes

if(analogRead(A0) > 900){

Serial.write("



>> BRAKE: High signal condition detected! | Expected value < 900 | Actual value: ");

BrakeReading = analogRead(A5);

Serial.println(BrakeReading);

Serial.write("



");

digitalWrite(9, LOW); // Seat Low

delay(100);

digitalWrite(9, HIGH);

delay(100);

digitalWrite(9, LOW); // Seat Off

delay(100);

digitalWrite(9, HIGH);

break;

}

delay(75);

BrakeCycle++;

}

digitalWrite(12, LOW); // Shut the red LED off

digitalWrite(10, HIGH); // Turn off the defrost regardless of why the Arduino is shutting down.

// Since it's directly controlling the relay, we can't just hand control

// back to the climate control module.

Serial.write("

15-minute monitor complete.");

}

if(HornTriggered == 0){

Serial.write("



Horn signal never detected.

Assuming normal key-in start was performed.");

}

Serial.write("



Resetting all the variables...");

HornTriggered = 0;

BrakeTriggered = 0;

BrakeCycle = 0;

MonitorCycle = 0;

Serial.write("

>>Resetting in 10 seconds...



");

delay(10000);