Advertisement
Guest User

Untitled

a guest
Mar 15th, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. //DRUCE C ASSIGNMENT 2
  2. //initializes/defines the output pin of the LM35 temperature sensor
  3. int outputpin= 0;
  4. //this sets the ground pin to LOW and the input voltage pin to high
  5.  
  6. void setup()
  7. {
  8. Serial.begin(9600);
  9.  
  10. // initialize digital pin 13,12,11,10,9,8 as an output.
  11. pinMode(13, OUTPUT);
  12. pinMode(12, OUTPUT);
  13. pinMode(11, OUTPUT);
  14. pinMode(10, OUTPUT);
  15. pinMode(9, OUTPUT);
  16. pinMode(8, OUTPUT);
  17. }
  18.  
  19. // main loop
  20. void loop()
  21. {
  22. int rawvoltage= analogRead(A1);
  23. float millivolts= (rawvoltage/1024.0) * 5000;
  24. float celsius= millivolts/10;
  25. Serial.print(celsius);
  26. Serial.print(" degrees Celsius, ");
  27. Serial.print((celsius * 9)/5 + 32);
  28. Serial.println(" degrees Fahrenheit");
  29. delay(1000);
  30.  
  31. //Condition 01 If the ambient temperature is between 0 and 5.5 degrees c .The program will turn on 1 led.
  32. if (celsius > 0 || celsius < 5.5)
  33. {
  34. digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
  35. }
  36.  
  37. //Condition 02 If temperature is between 5.5 and 15.5 degrees then 2 leds are switched on.
  38. if (celsius > 5.5 || celsius < 15.5)
  39. {
  40. digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
  41. digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
  42. }
  43.  
  44. //Condition 03 If temperature is between 15.5 and 20.5 degrees then 3 leds are switched on.
  45. if (celsius > 15.5 || celsius < 20.5)
  46. {
  47. digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
  48. digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
  49. digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
  50. }
  51.  
  52. //Condition 04 If the ldr is sensing lights are on and temperature is between 20.5 and 25.5 degrees then 4 leds are switched on and 1 fan is on.
  53. if (celsius > 20.5 || celsius < 25.5)
  54. {
  55. digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
  56. digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
  57. digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
  58. digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
  59. digitalWrite(8, HIGH); // turn the FAN on (HIGH is the voltage level)
  60. }
  61.  
  62. /*if (light > 49)
  63. {
  64. digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
  65. digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
  66. digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
  67. digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
  68. digitalWrite(8, HIGH); // turn the FAN on (HIGH is the voltage level)
  69. }
  70. */
  71.  
  72. //Condition 05 If lights are on and temperature is between 25.5 and 29.5 degrees then 5 leds are switched on and 1 fan is switched on.
  73. if (celsius > 25.5 || celsius < 29.5)
  74. {
  75. digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
  76. digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
  77. digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
  78. digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
  79. digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
  80. digitalWrite(8, HIGH); // turn the FAN on (HIGH is the voltage level)
  81. }
  82.  
  83. /*if (light > 49)
  84. {
  85. digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
  86. digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
  87. digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
  88. digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
  89. digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
  90. digitalWrite(8, HIGH); // turn the FAN on (HIGH is the voltage level)
  91. }
  92. */
  93.  
  94. //Condition 06 If temperature is between -5 and 0 then 5 leds are flashing at 5 hertz.
  95. if (celsius < 0)
  96. {
  97. digitalWrite(13, LOW); // turn the LED on (HIGH is the voltage level)
  98. digitalWrite(12, LOW); // turn the LED on (HIGH is the voltage level)
  99. digitalWrite(11, LOW); // turn the LED on (HIGH is the voltage level)
  100. digitalWrite(10, LOW); // turn the LED on (HIGH is the voltage level)
  101. digitalWrite(9, LOW); // turn the LED on (HIGH is the voltage level)
  102. delay (200);
  103. digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
  104. digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
  105. digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
  106. digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
  107. digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
  108. delay (200);
  109. }
  110.  
  111. //Condition 07 If temperature is above 29.5 degrees 5 leds are flashing at 15 hertz.
  112. if (celsius > 29.5)
  113. {
  114. digitalWrite(13, LOW); // turn the LED on (HIGH is the voltage level)
  115. digitalWrite(12, LOW); // turn the LED on (HIGH is the voltage level)
  116. digitalWrite(11, LOW); // turn the LED on (HIGH is the voltage level)
  117. digitalWrite(10, LOW); // turn the LED on (HIGH is the voltage level)
  118. digitalWrite(9, LOW); // turn the LED on (HIGH is the voltage level)
  119. delay (66.6);
  120. digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
  121. digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
  122. digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
  123. digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
  124. digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
  125. delay (66.6);
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement