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
}
}