Go Back   EcoModder Forum > EcoModding > Aerodynamics
Register Now
 Register Now
 

Reply  Post New Thread
 
Submit Tools LinkBack Thread Tools
Old 03-09-2009, 09:41 PM   #1 (permalink)
Coasting Down the Peak
 
skyl4rk's Avatar
 
Join Date: Jun 2008
Location: M I C H I G A N
Posts: 514

Toyauto Pickup - '94 Toyota Pickup 2WD
90 day: 36.32 mpg (US)

Versa Base - '09 Versa Sedan 1.6 Base
Team Nissan
90 day: 41.69 mpg (US)
Thanks: 27
Thanked 42 Times in 35 Posts
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);
    
  }

__________________
Nissan Versa Aeromods
  Reply With Quote
Alt Today
Popular topics

Other popular topics in this forum...

   
Old 03-10-2009, 06:53 AM   #2 (permalink)
Engineering first
 
bwilson4web's Avatar
 
Join Date: Mar 2009
Location: Huntsville, AL
Posts: 843

17 i3-REx - '14 BMW i3-REx
Last 3: 45.67 mpg (US)

Blue Bob's - '19 Tesla Std Rng Plus
Thanks: 94
Thanked 246 Times in 157 Posts
And the reason you don't want to use the engine thermistor?

Bob Wilson
__________________
2019 Tesla Model 3 Std. Range Plus - 215 mi EV
2017 BMW i3-REx - 106 mi EV, 88 mi mid-grade
Retired engineer, Huntsville, AL
  Reply With Quote
Old 03-10-2009, 10:43 AM   #3 (permalink)
Dartmouth 2010
 
SVOboy's Avatar
 
Join Date: Nov 2007
Location: Hanover, NH
Posts: 6,447

Vegan Powa! - '91 Honda CRX DX
Team Honda
90 day: 66.52 mpg (US)
Thanks: 92
Thanked 122 Times in 90 Posts
Send a message via AIM to SVOboy Send a message via MSN to SVOboy Send a message via Yahoo to SVOboy
Looking forward to updates!
  Reply With Quote
Old 03-10-2009, 06:25 PM   #4 (permalink)
Coasting Down the Peak
 
skyl4rk's Avatar
 
Join Date: Jun 2008
Location: M I C H I G A N
Posts: 514

Toyauto Pickup - '94 Toyota Pickup 2WD
90 day: 36.32 mpg (US)

Versa Base - '09 Versa Sedan 1.6 Base
Team Nissan
90 day: 41.69 mpg (US)
Thanks: 27
Thanked 42 Times in 35 Posts
Quote:
Originally Posted by bwilson4web View Post
And the reason you don't want to use the engine thermistor?
good idea!
__________________
Nissan Versa Aeromods
  Reply With Quote
Old 03-10-2009, 07:45 PM   #5 (permalink)
Coasting Down the Peak
 
skyl4rk's Avatar
 
Join Date: Jun 2008
Location: M I C H I G A N
Posts: 514

Toyauto Pickup - '94 Toyota Pickup 2WD
90 day: 36.32 mpg (US)

Versa Base - '09 Versa Sedan 1.6 Base
Team Nissan
90 day: 41.69 mpg (US)
Thanks: 27
Thanked 42 Times in 35 Posts
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);
  }

__________________
Nissan Versa Aeromods
  Reply With Quote
Reply  Post New Thread


Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Paul & Sabrina's cheap DIY 144v motor controller MPaulHolmes Open ReVolt: open source DC motor controller 7381 08-02-2023 10:55 PM
Arduino controlled automatically actuated grill block Daox Aerodynamics 167 11-08-2016 11:23 AM
Hybrid PWM/Contactor controller turbo-boost bennelson Fossil Fuel Free 24 05-12-2011 10:26 AM
Neat gadget: Solar Auto Vent Daox EcoModding Central 2 10-14-2008 10:28 AM
Fun with Voltage Controller Heatsinks Dradus Fossil Fuel Free 14 05-02-2008 03:16 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