Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1.  
  2.     //TMP36 Pin Variables
  3.     int sensor1Pin = 1; // TMP36 inside
  4.     int sensor2Pin = 0; // TMP36 outside
  5.    
  6.     int fan = 8;        // the number of the fan vcc pin
  7.     int inPin = 7;      // the number of the input pin
  8.     int led = 13;       // the number of the output pin
  9.  
  10.     int state = LOW;      // the current state of the output pin
  11.     int reading;           // the current reading from the input pin
  12.     int previous = LOW;    // the previous reading from the input pin
  13.  
  14.           // the follow variables are long's because the time, measured in miliseconds,
  15.           // will quickly become a bigger number than can be stored in an int.
  16.     long time = 0;         // the last time the output pin was toggled
  17.     long debounce = 200;   // the debounce time, increase if the output flickers
  18.  
  19.     /*
  20.      * setup() - this function runs once when you turn your Arduino on
  21.      * We initialize the serial connection with the computer
  22.      */
  23.     void setup()
  24.     {
  25.       pinMode(inPin, INPUT_PULLUP);
  26.       pinMode(led, OUTPUT);
  27.       pinMode(fan, OUTPUT);
  28.       Serial.begin(115200);  //Start the serial connection with the computer
  29.                            //to view the result open the serial monitor                
  30.     }
  31.      
  32.     void loop()                     // run over and over again
  33.     {
  34.      //getting the voltage reading from the temperature sensor
  35.      int reading1 = analogRead(sensor1Pin);  
  36.      int reading2 = analogRead(sensor2Pin);
  37.      // converting that reading to voltage, for 3.3v arduino use 3.3
  38.      float voltage1 = reading1 * 5.0;
  39.      float voltage2 = reading2 * 5.0;
  40.      voltage1 /= 1024.0;
  41.      voltage2 /= 1024.0;
  42.      
  43.      // print out the voltage
  44.      //Serial.print(voltage1); Serial.println(" volts(s1)");
  45.      //Serial.print(voltage2); Serial.println(" volts(s2)");
  46.      
  47.      // now print out the temperature
  48.      float temperatureC1 = (voltage1 - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
  49.      float temperatureC2 = (voltage2 - 0.5) * 100 ;  //to degrees ((voltage - 500mV) times 100)
  50.      float temperatureDifference = temperatureC1 - temperatureC2;
  51.      Serial.print(temperatureC1);
  52.      Serial.print("   (IN) || (OUT)   ");
  53.      Serial.print(temperatureC2);
  54.      Serial.print("    sisalla ");
  55.      Serial.println(temperatureDifference);
  56.      delay(100);                                  
  57.      
  58.      reading = digitalRead(inPin);
  59.      if (reading == HIGH && previous == LOW && millis() - time > debounce) {
  60.         if (state == HIGH)
  61.         state = LOW;
  62.         else
  63.         state = HIGH;
  64.  
  65.         time = millis();    
  66.      }
  67.      digitalWrite(led, state);
  68.      
  69.      if (state == HIGH && temperatureC2 <= temperatureC1){            //  if
  70.        digitalWrite(fan, HIGH);                      //
  71.      } else {
  72.        digitalWrite(fan, LOW);                       //
  73.      }
  74.      
  75.      previous = reading;
  76.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement