Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //TMP36 Pin Variables
- int sensorPin = 5; //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
- void setup()
- {
- pinMode(A5, INPUT); //temperature input
- pinMode(2, OUTPUT); //blue led
- pinMode(3, OUTPUT); //green led
- pinMode(4, OUTPUT); //yellow led
- pinMode(5, OUTPUT); //orange led
- pinMode(6, OUTPUT); //red led
- }
- void loop() // run over and over again
- {
- //getting the voltage reading from the temperature sensor
- int reading = analogRead(sensorPin);
- // converting that reading to voltage, for 3.3v arduino use 3.3
- float voltage = reading * 5.0;
- voltage /= 1024.0;
- // now print out the temperature
- float temp = 100*voltage-50 ; //converting from 10 mv per degree wit 500 mV offset
- //to degrees ((voltage - 500mV) times 100)
- //int temp = 0;
- if (temp <= -17.7) { //turn blue led on if T below -17.7C or 0F
- digitalWrite(2, HIGH);
- digitalWrite(3, LOW);
- digitalWrite(4, LOW);
- digitalWrite(5, LOW);
- digitalWrite(6, LOW);
- }
- if (temp > -17.7 && temp <= -6.66667 ) { //turn green led on if T 0F to 20F
- digitalWrite(2, LOW);
- digitalWrite(3, HIGH);
- digitalWrite(4, LOW);
- digitalWrite(5, LOW);
- digitalWrite(6, LOW);
- }
- if (temp > -6.66667 && temp <= -3.888) { //turn yellow led on if T 20F to 25F
- digitalWrite(2, LOW);
- digitalWrite(3, LOW);
- digitalWrite(4, HIGH);
- digitalWrite(5, LOW);
- digitalWrite(6, LOW);
- }
- if (temp > -3.888 && temp <= -0.555556) { //turn orange led on if T 25F to 31F
- digitalWrite(2, LOW);
- digitalWrite(3, LOW);
- digitalWrite(4, LOW);
- digitalWrite(5, HIGH);
- digitalWrite(6, LOW);
- }
- if (temp > 0) { ////turn red led on if T above 32F
- digitalWrite(2, LOW);
- digitalWrite(3, LOW);
- digitalWrite(4, LOW);
- digitalWrite(5, LOW);
- digitalWrite(6, HIGH);
- tone (9,1000);
- }
- delay(10); // Delay a little bit to improve simulation performance
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement