Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. //TMP36 Pin Variables
  2. int sensorPin = A3; //the analog pin the TMP36's Vout (sense) pin is connected to
  3. //the resolution is 10 mV / degree centigrade with a
  4. //500 mV offset to allow for negative temperatures
  5. int blue = 4;
  6. int red = 3;
  7. int green = 2;
  8. /*
  9. * setup() - this function runs once when you turn your Arduino on
  10. * We initialize the serial connection with the computer
  11. */
  12. void setup()
  13. {
  14. Serial.begin(9600); //Start the serial connection with the computer
  15. //to view the result open the serial monitor
  16. pinMode(blue, OUTPUT);
  17. pinMode(red, OUTPUT);
  18. pinMode(green, OUTPUT);
  19. }
  20.  
  21. void loop() // run over and over again
  22. {
  23. //getting the voltage reading from the temperature sensor
  24. int reading = analogRead(sensorPin);
  25.  
  26. // converting that reading to voltage, for 3.3v arduino use 3.3
  27. float voltage = reading * 5.0;
  28. voltage /= 1024.0;
  29.  
  30. // print out the voltage
  31. Serial.print(voltage); Serial.println(" volts");
  32.  
  33. // now print out the temperature
  34. float temperatureC = (voltage - 0.5) * 10 ; //converting from 10 mv per degree wit 500 mV offset
  35. if(temperatureC <= 25 && temperatureC < 23) {
  36. digitalWrite(green, HIGH);
  37. digitalWrite(red, LOW);
  38. digitalWrite(blue, LOW);
  39. }
  40. else if(temperatureC > 25) {
  41. digitalWrite(green, LOW);
  42. digitalWrite(red, HIGH);
  43. digitalWrite(blue, LOW);
  44. }
  45. else {
  46. digitalWrite(green, LOW);
  47. digitalWrite(red, LOW);
  48. digitalWrite(blue, HIGH);
  49. }
  50.  
  51.  
  52. //to degrees ((voltage - 500mV) times 100)
  53. Serial.print(temperatureC); Serial.println(" degrees C");
  54.  
  55. // now convert to Fahrenheit
  56. float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  57. Serial.print(temperatureF); Serial.println(" degrees F");
  58.  
  59. delay(1000); //waiting a second
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement