/*
This code is for interfacing an arduino mega to the modules of my
vehicle responsible for climate control. The blend door actuator is
a motor which controls the blend of hot and cold air and has a built
in potentiometer for a readout of it's position, and is attached to
an adafruit motor shield. Four solenoids attached using the circuit from
http://www.arduino.cc/playground/uploads/Learning/solenoid_driver.pdf
control the vent selection. A pwm signal is amplified by a board in
the car which controls the blower motor. Three 10K linear taper
potentiometers set the desired positions for each module.
*/
#include <AFMotor.h>
AF_DCMotor motor(4); //Blend Door Actuator
#define blowpwmPin 10 // digital pin [pwm] ouptutting control wave
#define sol1Pin 22 // digital pin connected to solenoid tier 1
#define sol2Pin 24 // digital pin connected to solenoid tier 2
#define sol3Pin 26 // digital pin connected to solenoid tier 3
#define sol4Pin 28 // digital pin connected to solenoid tier 4
int tempVal; // variable to read the value from the temperature pot
int ventVal; // variable to read the value from the vent pot
int blowVal; // variable to read the value from the blower pot
int bdaVal; // variable to read the value from the blend door pot
int pwmVal; // variable to store the math of blower potentiometer to pwm
void setup()
{
Serial.begin(9600);
pinMode(blowpwmPin, OUTPUT); //Pins default to Inputs unless otherwise specified
pinMode(sol1Pin, OUTPUT);
pinMode(sol2Pin, OUTPUT);
pinMode(sol3Pin, OUTPUT);
pinMode(sol4Pin, OUTPUT);
tempVal = 0; //Making sure the analog readings get a fresh start
ventVal = 0;
bdaVal = 0;
blowVal = 0;
pwmVal = 0;
}
void loop()
{
tempVal = map(analogRead(3), 0, 1023, 1, 9); //reads the analog pin, changes the value to a -
delay(50); //more manageable one and stores it the delays -
bdaVal = map(analogRead(5), 0, 1023, 0, 10); //are to give time for accurate readings
delay(50);
blowVal = map(analogRead(2), 0, 1023, 0, 10);
delay(50);
analogWrite(blowpwmPin, blowVal * 25.5); //PWM controls the Blower motor speed
pwmVal = blowVal * 25.5; //storing the PWM value for recall
ventVal = map(analogRead(1), 0, 1023, 0, 5);
delay(50);
Serial.println("Temperature Setting:"); //if the pc is hooked up to the arduino -
Serial.println(tempVal); //with a serial terminal open, the values -
Serial.println("Blend door position:"); //of the sensors are displayed on screen -
Serial.println(bdaVal); //for debugging purposes by these next few lines
Serial.println("Vents Setting:");
Serial.println(ventVal);
Serial.println("Blower Motor Setting:");
Serial.println(blowVal);
Serial.println("Blower PWM Frequency:");
switch (ventVal) { //these next lines are the control of the vents
case 0: // OFF
digitalWrite(sol1Pin, HIGH);
digitalWrite(sol2Pin, LOW);
digitalWrite(sol3Pin, HIGH);
digitalWrite(sol4Pin, HIGH);
break;
case 1: // MAX A/C
digitalWrite(sol1Pin, HIGH);
digitalWrite(sol2Pin, HIGH);
digitalWrite(sol3Pin, HIGH);
digitalWrite(sol4Pin, HIGH);
break;
case 2: // NORM A/C [PANEL]
digitalWrite(sol1Pin, LOW);
digitalWrite(sol2Pin, HIGH);
digitalWrite(sol3Pin, HIGH);
digitalWrite(sol4Pin, HIGH);
break;
case 3: // FLOOR
digitalWrite(sol1Pin, LOW);
digitalWrite(sol2Pin, LOW);
digitalWrite(sol3Pin, HIGH);
digitalWrite(sol4Pin, HIGH);
break;
case 4: // FLOOR/DEFROST
digitalWrite(sol1Pin, LOW);
digitalWrite(sol2Pin, LOW);
digitalWrite(sol3Pin, LOW);
digitalWrite(sol4Pin, HIGH);
break;
case 5: // DEFROST
digitalWrite(sol1Pin, LOW);
digitalWrite(sol2Pin, LOW);
digitalWrite(sol3Pin, LOW);
digitalWrite(sol4Pin, LOW);
break;
}
if (tempVal == bdaVal) //the following lines are a simple blend door PID
{
motor.run(RELEASE);
}
else if (bdaVal > tempVal)
{
motor.run(FORWARD);
motor.setSpeed(255);
delay(500);
}
else if (bdaVal < tempVal)
{
motor.run(BACKWARD);
motor.setSpeed(255);
delay(500);
}
delay(1000); //a second, exactly, for everything to catch up
}