Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TMP36 Pin Variables
- int sensor1Pin = 1; // TMP36 inside
- int sensor2Pin = 0; // TMP36 outside
- int fan = 8; // the number of the fan vcc pin
- int inPin = 7; // the number of the input pin
- int led = 13; // the number of the output pin
- int state = LOW; // the current state of the output pin
- int reading; // the current reading from the input pin
- int previous = LOW; // the previous reading from the input pin
- // the follow variables are long's because the time, measured in miliseconds,
- // will quickly become a bigger number than can be stored in an int.
- long time = 0; // the last time the output pin was toggled
- long debounce = 200; // the debounce time, increase if the output flickers
- /*
- * setup() - this function runs once when you turn your Arduino on
- * We initialize the serial connection with the computer
- */
- void setup()
- {
- pinMode(inPin, INPUT_PULLUP);
- pinMode(led, OUTPUT);
- pinMode(fan, OUTPUT);
- Serial.begin(115200); //Start the serial connection with the computer
- //to view the result open the serial monitor
- }
- void loop() // run over and over again
- {
- //getting the voltage reading from the temperature sensor
- int reading1 = analogRead(sensor1Pin);
- int reading2 = analogRead(sensor2Pin);
- // converting that reading to voltage, for 3.3v arduino use 3.3
- float voltage1 = reading1 * 5.0;
- float voltage2 = reading2 * 5.0;
- voltage1 /= 1024.0;
- voltage2 /= 1024.0;
- // print out the voltage
- //Serial.print(voltage1); Serial.println(" volts(s1)");
- //Serial.print(voltage2); Serial.println(" volts(s2)");
- // now print out the temperature
- float temperatureC1 = (voltage1 - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
- float temperatureC2 = (voltage2 - 0.5) * 100 ; //to degrees ((voltage - 500mV) times 100)
- float temperatureDifference = temperatureC1 - temperatureC2;
- Serial.print(temperatureC1);
- Serial.print(" (IN) || (OUT) ");
- Serial.print(temperatureC2);
- Serial.print(" sisalla ");
- Serial.println(temperatureDifference);
- delay(100);
- reading = digitalRead(inPin);
- if (reading == HIGH && previous == LOW && millis() - time > debounce) {
- if (state == HIGH)
- state = LOW;
- else
- state = HIGH;
- time = millis();
- }
- digitalWrite(led, state);
- if (state == HIGH && temperatureC2 <= temperatureC1){ // if
- digitalWrite(fan, HIGH); //
- } else {
- digitalWrite(fan, LOW); //
- }
- previous = reading;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement