Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  4.  
  5. int temprature = 0;
  6. int celsius = 0;
  7. int fahrenheit=0;
  8. int led1 = 10;
  9. int led2 = 9;
  10. int led3 = 8;
  11.  
  12. void setup()
  13. {
  14. lcd.begin(16, 2);
  15. lcd.print(celsius);
  16.  
  17. pinMode(A0, INPUT);
  18. Serial.begin(9600);
  19. pinMode(10, OUTPUT);
  20. pinMode(9, OUTPUT);
  21. pinMode(8, OUTPUT);
  22. }
  23.  
  24. void loop()
  25. {
  26. lcd.setCursor(1, 1);
  27.  
  28.  
  29.  
  30. temprature = 10;
  31.  
  32. celsius = map(((analogRead(A0) - 20) * 3.04), 0, 1023, -40, 125);
  33.  
  34. fahrenheit = ((celsius * 9) / 5 + 32);
  35. Serial.print(celsius);
  36. Serial.print(" C, ");
  37. Serial.print(fahrenheit);
  38. Serial.println(" F");
  39.  
  40. if (celsius < temprature)
  41. {
  42. digitalWrite(2, LOW);
  43. digitalWrite(3, LOW);
  44. digitalWrite(4, LOW);
  45. }
  46. if (celsius >= temprature && celsius < temprature + 10)
  47. {
  48. digitalWrite(2, HIGH);
  49. digitalWrite(3, LOW);
  50. digitalWrite(4, LOW);
  51. }
  52. if (celsius >= temprature + 10 && celsius < temprature + 20)
  53. {
  54. digitalWrite(2, HIGH);
  55. digitalWrite(3, HIGH);
  56. digitalWrite(4, LOW);
  57. }
  58. if (celsius >= temprature + 20 && celsius < temprature + 30)
  59. {
  60. digitalWrite(2, HIGH);
  61. digitalWrite(3, HIGH);
  62. digitalWrite(4, HIGH);
  63. }
  64. if (celsius >= temprature + 30)
  65. {
  66. digitalWrite(2, HIGH);
  67. digitalWrite(3, HIGH);
  68. digitalWrite(4, HIGH);
  69. }
  70. lcd.begin(16, 2);
  71. lcd.print(celsius);
  72. lcd.print("C");
  73. lcd.setCursor(0,1);
  74. lcd.print(fahrenheit);
  75. lcd.print("F");
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement