View Single Post
Old 01-16-2017, 10:38 AM   #92 (permalink)
Daox
Administrator
 
Daox's Avatar
 
Join Date: Dec 2007
Location: Germantown, WI
Posts: 11,203

CM400E - '81 Honda CM400E
90 day: 51.49 mpg (US)

Daox's Grey Prius - '04 Toyota Prius
Team Toyota
90 day: 49.53 mpg (US)

Daox's Insight - '00 Honda Insight
90 day: 64.33 mpg (US)

Swarthy - '14 Mitsubishi Mirage DE
Mitsubishi
90 day: 56.69 mpg (US)

Daox's Volt - '13 Chevrolet Volt
Thanks: 2,501
Thanked 2,588 Times in 1,555 Posts
In fact, I have the initial code written. Its nothing fancy at all, just enough to get things working with a tiny bit of troubleshooting / indication built in.

Code:
/* Grill Block Controller
 *  Program watches the engine coolant temperature sensor
 *  voltage output. It opens and closes the grill block
 *  according to the set temperatures.
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

// Pin declaration
int tempPin = 0;  // analog pin to read temperature sensor voltage from ECU
int ledPin = 13;  // led indicator light to show if grill block is open or closed (on = open)

// Variable declaration
int temp = 0;   // variable to store the engine coolant temperature
boolean blockOpen = false;  // variable to store grill block position
int closeTemp = 128;  // variable to store the temperature at which the block closes
int openTemp = 110;   // variable to store the temperature at which the block opens
int closeDeg = 0;   // variable to store the degrees the servo will rotate to when grill block is closed
int openDeg = 125;  // variable to store the degrees the servo will rotate to when grill block is open


void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo.write(closeDeg);  // default the grill block to closed position
  pinMode(tempPin, INPUT);  // set tempPin as an input
  pinMode(ledPin, OUTPUT);  // set ledPin as an output
  digitalWrite(ledPin, LOW);  // turn off led indicator
}


void loop() {

  temp = analogRead(tempPin); // read the engine coolant temperature

  if (temp >= openTemp && blockopen == false)  // if engine temp is above open point and grill block is currently closed
    {
        myservo.write(openDeg);  // open grill block to openDeg setting
        blockopen = true; // set new block position
        analogWrite(ledPin, HIGH);  // turn on ledPin to indiate that grill block is open
    }

  if (temp <= closeTemp && blockopen == true) // if engine temp is below close point and grill block is currently open
    {
      myservo.write(closeDeg);  // close grill block to closeDeg setting
      blockopen = false; // set new block position
      analogWrite(ledPin, LOW);   // turn off ledPin to indicate that grill block is closed
    }
}
__________________
Current project: A better alternator delete
  Reply With Quote
The Following 2 Users Say Thank You to Daox For This Useful Post:
BamZipPow (01-16-2017), t vago (01-17-2017)