/* This program will give us a temperature reading of the room/outside and will display it through the Serial Communication. If the temperature reaches a certain Fahrenheit temperature, it will activate the three fans and the larger fan on the air conditioner. You could adjust the parameters of the on/off time throughout the code. */ //TMP36 Pin Variables int sensorPin = A2; //the analog pin the TMP36's Vout (sense) pin is connected to. The resolution is 10 mV / degree centigrade with a. 500 mV offset to allow for negative temperatures const int Fans = 1; //assigns variable Fans to digital Pin 5 const int Fan = 10; //assigns variable Fan to digital pin 10 const int buttonPin = A0; //assigns the button to pin A0 int buttonPushCounter = 0; //counter for the number of button presses int buttonState = 0; //current state of the button int lastButtonState = 0; //previous state of the button int Ground2 = A3; //assigns pin A3 as a ground pin const int tempOn = 80; //change this value to the temperature you want to exceed double value = 0; /* setup() - this function runs once when you turn your Arduino on. We initialize the serial connection with the computer */ void setup() { Serial.begin(9600); //Start the serial connection with the computer to view the result open the serial monitor pinMode(Fans,OUTPUT); //Sets Digital Pin 5 as an output (Fans) pinMode(Fan,OUTPUT); //Sets Digital Pin 10 as an output for the larger fan pinMode(11, INPUT_PULLUP); //Activtes the internal input resistors of pin 11, which sets the pin to 5 Volts pinMode(13, OUTPUT); //Sets Digital pin to Output digitalWrite(13,LOW); //Sets Digital pin to Low or Ground pinMode(Ground2, OUTPUT); //Sets pin A3 as an Output digitalWrite(Ground2, LOW); //Sets pin A3 to Low or Ground pinMode(buttonPin, INPUT); //Sets button as the input pin } void loop() // run over and over again { int reading = analogRead(sensorPin); //getting the voltage reading from the temperature sensor float voltage = reading * 5.0 / 1024; // this stores the converted reading from the sensor pin into variable voltage as a float data type. converting that reading to voltage, for 3.3v arduino use 3.3 //Serial.print(voltage); // print out the voltage. //Serial.print(" volts"); // Display volts on a new line // now print out the temperature float tempC = (voltage - 0.5) * 100; //converting from 10 mv per degree wit 500 mV offset to degrees ((volatge - 500mV) times 100) Serial.print(tempC); //Display the temperature in Degrees Celsius Serial.println(" Degrees Celsius,"); //Display " Degrees Celsius," // now convert to Fahrenheight float tempF = (tempC * 9 / 5) + 32; // Convert Celsius to Fahrenheit Serial.print(tempF); //Display the temperature in Degrees Celsius Serial.println(" Degrees Fahrenheit"); //Display " Degrees Fahrenheit." delay(500); //waiting a second int buttonreading = analogRead(A0); Serial.println("A0 reading: " + buttonreading); if( (tempF >= tempOn )|| (buttonreading > 50)) //If the temperature exceeds tempOn or if the button exceeds the value of 50 then, { digitalWrite( Fan, 1 ); //turn the PC fan on analogWrite( Fans, 255 ); //turn the littlebits fans on } else //if the temperature is less than the tempOn, { digitalWrite( Fan, 0 ); //turn off the fan analogWrite( Fans, 0 ); //turn off the fan } }