Skip to content

Instantly share code, notes, and snippets.

@jakewins
Created September 21, 2013 09:45
Show Gist options
  • Save jakewins/6648977 to your computer and use it in GitHub Desktop.
Save jakewins/6648977 to your computer and use it in GitHub Desktop.
const int fanPin = 5; // The arduino connector that controls the motor relay
const int tempSensorPin = 1; // The arduino connector that is connected to our thermistor
const short targetTemperature = 15760; // 15760 from thermistor = 107C, or 224F
short currentTemperature;
void setup() {
// This sets the arduino up to talk to my laptop, to let it send temperature readings
Serial.begin(9600);
}
void loop() {
// Get the temperature from the thermistor
currentTemperature = (1023 * 16 - analogRead(tempSensorPin));
// Send temp reading to my laptop
Serial.println(currentTemperature);
if(currentTemperature < targetTemperature)
{
analogWrite(fanPin, 255); // Turn fan on
}
else
{
analogWrite(fanPin, 0); // Turn fan off
}
// Wait for 2000 milliseconds, 2 seconds
delay(2000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment