EcoModder.com

EcoModder.com (https://ecomodder.com/forum/)
-   Aerodynamics (https://ecomodder.com/forum/aerodynamics.html)
-   -   arduino - thermistor - servo vent controller (https://ecomodder.com/forum/showthread.php/arduino-thermistor-servo-vent-controller-7410.html)

skyl4rk 03-09-2009 09:41 PM

arduino - thermistor - servo vent controller
 
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);
   
  }


bwilson4web 03-10-2009 06:53 AM

And the reason you don't want to use the engine thermistor?

Bob Wilson

SVOboy 03-10-2009 10:43 AM

:thumbup: Looking forward to updates!

skyl4rk 03-10-2009 06:25 PM

Quote:

Originally Posted by bwilson4web (Post 91853)
And the reason you don't want to use the engine thermistor?

good idea!

skyl4rk 03-10-2009 07:45 PM

Another working version with potentiometer manual override and thermistor control stops at closed, quarter open, half open, three quarters open and full open.

ThermistorServo 1_02
Code:

// Thermistor controlled servo to open a vent based on thermistor values, quarter stops, pot manual override.
// This version seems to work. 
// Connect one or more servos with control pin to pin 2. Pos lead to 5V, neg lead to grd.
// Connect thermistor to analog pin 0: 5V - thermistor - apin 0 - 10k ohm - grd.
// Connect potentiometer sensor (middle pin) to analog pin 3. Connect one side to 5V and the other to grd.
// Adjust the min and max values for the thermistor and servo to adjust.
// There may be a need to "reverse" the servo or thermistor, use math or turn servo around.

// Configure servo throw and temperature cutin and cutout points

int refreshTime = 200; // ms, the time in between pulses, servo speed adjustment.
int thermMin = 970;  // thermistor control voltage, ("Temp") at which vent will start to open.
int thermMax = 990;  // thermistor control voltage ("Temp") at which vent will be 100% open.
int potMin = 100;  // potentiometer control voltage at which vent will start to open.
int potMax = 1000;  // potentiometer control voltage at which vent will be 100% open.
int pulseMin = 1000;  // us, Start point for servo, between 250 and 2300 microseconds for my Futaba FP-52B.
int pulseMax = 2000;  // us, End point for servo, must be higher than pulseMin.

// Beyond Here: Change with care

int servoPin = 2;    // control pin for servo motor
int thermPin = 0;    // thermistor analog input pin
int potPin = 3;      // potentiometer analog input pin

// variables to set stops for vent opening
int thermInput = 0;  // thermistor control voltage value
int thermRange = thermMax - thermMin;
int thermThird = (thermRange/3)+thermMin;
int thermTwoThirds = (2*(thermRange/3))+thermMin;
int pulseRange = pulseMax - pulseMin;
int pulse1 = pulseMin + (pulseRange/4);
int pulse2 = pulseMin + (2*(pulseRange/4));
int pulse3 = pulseMin + (3*(pulseRange/4));

// potentiometer variables
int potInput = 0;  // potentiometer control voltage value
int potInRange = 0;
int potRange = potMax - potMin;

// somewhat silly method to avoid decimal points
int potRatio = 0;
long potPlace = 0;
long potPlace100 = 0;
long potPct = 0;

// pulse generation variables
long pulseIncrease = 0;
long lastPulse = 0;
long pulse = 0;

void setup() {
  Serial.begin(9600);
  pinMode(servoPin, OUTPUT);  // Set servo pin as an output pin
}
 
void loop() {

  // thermistor control

  thermInput = analogRead(thermPin);  // read the analog input, 0 to 1023
  if(thermInput<thermMin){pulse=pulseMin;}
  if(thermInput>=thermMin && thermInput<thermThird){pulse=pulse1;}
  if(thermInput>=thermThird && thermInput<thermTwoThirds){pulse=pulse2;}
  if(thermInput>=thermTwoThirds && thermInput<thermMax){pulse=pulse3;}
  if(thermInput>thermMax){pulse=pulseMax;}

  // potentiometer control

  potInput = analogRead(potPin);  // read the analog input, 0 to 1023
  potInRange = potInput;
  if(potInput<potMin){potInRange=potMin+1;}
  if(potInput>potMax){potInRange=potMax;}
  potPlace = potInRange - potMin;
  potPlace100 = 100*potPlace;
  potPct = potPlace100/potRange;
  pulseIncrease = pulseRange*potPct;

  // potentiometer only controls when it is set within the Min and Max range
  // turn to either stop to let thermistor control

  if (potInput>potMin && potInput<potMax){ 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
  }

// \\//, skyl4rk 10-III-2009 ,\\//
 
// Print values to screen
    Serial.print("thermInput: ");
    Serial.print(thermInput);
    Serial.print("; potInput: ");
    Serial.print(potInput);
    Serial.print("; pulse: ");
    Serial.println(pulse);
  }



All times are GMT -4. The time now is 01:40 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Content Relevant URLs by vBSEO 3.5.2
All content copyright EcoModder.com