Due to the weather this past weekend I did not make much progress on adding aeromods to my car. However I played around with the arduino and wrote a script that seems like it will work to control a vent in the valence block by using a thermistor to sense radiator heat.
I have a thermistor from a grab bag of thermistors from American Science and Surplus. I set up the program to turn the servo when I hold the thermistor, the heat from my hand changes the resistance and through the programming moves the servo. Right now the servo moves proportionally to the heat applied to the thermistor. I might change it to a few stops, so the servo doesn't move back and forth with small changes in thermistor resistance.
The code is not real clean, I had trouble getting float variables to work in equations and just figured out a way to create some long variables to do the same thing without decimal points.
I need to add a manual override through a potentiometer.
Code:
// Thermistor controlled servo to open a vent.
// Connect one or more servos with control pin to pin 2, pos to 5V, neg to grd.
// Connect potentiometer sensor or thermistor to analog pin 0. (5V - thermistor - apin 0 - 10k ohm - grd).
// Adjust the min and max values (thermMin, pulseMin, thermMax, pulseMax) for the thermistor and servo to adjust.
// There may be a need to "reverse" the servo or thermistor, use math.
// Test the thermistor in hot water to determine control voltage level at desired temps.
// Next steps: might be better to make 5 steps, closed, 1/4 open, 1/2 open, 3/4 open, full open, this would make for less twitching of the servo.
// Need to add a potentiometer for manual override, need to add leds to show when vent is open.
int refreshTime = 200; // ms the time in between pulses, servo speed adjustment.
int thermMin = 980; // control voltage ("Temp") at which vent will start to open.
int thermMax = 990; // control voltage ("Temp") at which vent will be 100% open.
int pulseMin = 1000; // us, Start point for servo, in range of 250 to 2300 us for my Futaba FP-52B.
int pulseMax = 2000; // us, End point for servo, must be higher than pulseMin.
// change only with care
int servoPin = 2; // Control pin for servo motor
int thermPin = 0;
int thermInput = 0;
int thermInRange = 0;
int thermRange = thermMax - thermMin;
int thermRatio = 0;
int pulseRange = pulseMax - pulseMin;
long lastPulse = 0;
long thermPlace = 0;
long thermPlace100 = 0;
long thermPct = 0;
long pulseIncrease = 0;
long pulse = 0;
void setup() {
Serial.begin(9600);
pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
}
void loop() {
thermInput = analogRead(thermPin); // read the analog input, 0 to 1023
thermInRange = thermInput;
if(thermInput<thermMin){thermInRange=thermMin+1;}
if(thermInput>thermMax){thermInRange=thermMax;}
thermPlace = thermInRange - thermMin;
thermPlace100 = 100*thermPlace;
thermPct = thermPlace100/thermRange;
pulseIncrease = pulseRange*thermPct;
pulse = pulseMin + (pulseIncrease/100);
// pulse the servo again after refresh time
if (millis() - lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
// Print pulse and analogValue to screen
Serial.print("thermInput: ");
Serial.print(thermInput);
Serial.print("; thermInRange: ");
Serial.print(thermInRange);
Serial.print("; thermPct: ");
Serial.print(thermPct);
Serial.print("; pulse: ");
Serial.println(pulse);
}