Advertisement
Guest User

Untitled

a guest
May 8th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. //Display TM 1637
  2. #include <Arduino.h>
  3. #include <TM1637Display.h>
  4.  
  5. // Module connection pins (Digital Pins)
  6. #define CLK 2
  7. #define DIO 4
  8.  
  9. // The amount of time (in milliseconds) between tests
  10. #define TEST_DELAY 5000
  11.  
  12. const uint8_t SEG_DONE[] = {
  13. SEG_G, // -
  14. SEG_G, // -
  15. SEG_A | SEG_B | SEG_F | SEG_G, // o
  16. SEG_A | SEG_D | SEG_E | SEG_F | SEG_A, // C
  17. };
  18.  
  19. TM1637Display display(CLK, DIO);
  20.  
  21. // Define the analog pin where the LM35 is connected
  22. const int Input = A5;
  23. const int OUTPUT_PIN_12 = 12; //rele pompa parno
  24. const int OUTPUT_PIN_13 = 13; // diod pokazvasht temperatyra nad 50
  25. const int OUTPUT_PIN_8 = 8; // diod pokazvasht temperatyra pod 40
  26. const int INPUT_PIN_2 = 2; // diod pokazvasht bateriq nad 98%
  27. // Define the temperatures avalible
  28. const float temperatureArray[] = {
  29. 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  30. 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  31. 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
  32. 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
  33. 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
  34. 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
  35. 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  36. 80, 81, 82, 83, 84, 85
  37. };
  38. // Define the resistances for every degree from 10 degree to 85
  39. const float resistanceArray[] = {
  40. 9.25, 8.62, 8.40, 8.35, 8.20, 7.88, 7.00, 6.95, 6.80, 6.71, 6.45, 6.11, 6.00, 5.92, 5.48, 5.32,
  41. 5.09, 4.93, 4.70, 4.65, 4.50, 4.31, 4.13, 4.05, 3.80, 3.72, 3.52, 3.46, 3.30, 3.26, 3.12, 3.05,
  42. 2.97, 2.86, 2.73, 2.71, 2.52, 2.45, 2.32, 2.29, 2.29, 2.19, 2.05, 2.00, 1.99, 1.94, 1.88, 1.75,
  43. 1.72, 1.64, 1.62, 1.61, 1.58, 1.55, 1.51, 1.48, 1.45, 1.44, 1.41, 1.40, 1.39, 1.37, 1.35, 1.33,
  44. 1.30, 1.29, 1.28, 1.25, 1.23, 1.22, 1.19, 1.15, 1.13, 1.11, 1.08, 1.05
  45. };
  46. void setup() {
  47. // Initialize serial communication for debugging
  48. Serial.begin(9600);
  49. pinMode(LED_BUILTIN, OUTPUT);
  50. digitalWrite(LED_BUILTIN, LOW);
  51. pinMode(OUTPUT_PIN_12, OUTPUT);
  52. digitalWrite(OUTPUT_PIN_12, LOW);
  53. pinMode(OUTPUT_PIN_13, OUTPUT);
  54. digitalWrite(OUTPUT_PIN_13, LOW);
  55. pinMode(OUTPUT_PIN_8, OUTPUT);
  56. digitalWrite(OUTPUT_PIN_8, LOW);
  57. pinMode(INPUT_PIN_2, INPUT);
  58. }
  59. void loop() {
  60. Serial.println("Beginning of program");
  61. // Read the analog value from A5
  62. int rawValue = analogRead(Input);
  63.  
  64. // Convert the raw value to voltage (in millivolts)
  65. float voltage = rawValue*0.004883; // 5000 mV is 5V
  66. // Find the resistance from voltage
  67. float resistance = 10.0*(1023.0/(float)rawValue-1.0);
  68. delay(1000);
  69.  
  70. int temperature = 0;
  71.  
  72. for (int i = 0; i < 76; i++) {
  73. // Serial.print(i);
  74. // delay(100);
  75. if (resistanceArray[i] == resistance){
  76. temperature = temperatureArray[i];
  77. Serial.println(" Matched ohms");
  78. break;
  79. }
  80. if (resistance > 10){
  81. Serial.println("temperature too low");
  82. break;
  83. }
  84. if (resistance < 1.05){
  85. Serial.println("temperature too high");
  86. break;
  87. }
  88. if (resistance > resistanceArray[i+1]){
  89. temperature = temperatureArray[i];
  90. Serial.println("matched to nearby temperature");
  91. break;
  92. }
  93.  
  94.  
  95.  
  96.  
  97. }
  98. // Print the temperature to the Serial Monitor
  99.  
  100. Serial.print("rawValue ");
  101. Serial.println(rawValue);
  102. Serial.print("voltage ");
  103. Serial.println(voltage);
  104. Serial.print("resistance ");
  105. Serial.println(resistance);
  106. //Serial.println(resistance);
  107. Serial.print("Temperature (Celsius): ");
  108. Serial.println(temperature);
  109. delay(1000);
  110. if (temperature > 50){
  111. digitalWrite(OUTPUT_PIN_12, HIGH);
  112. digitalWrite(OUTPUT_PIN_13, HIGH);
  113. }
  114. else{digitalWrite(OUTPUT_PIN_12, LOW);
  115. digitalWrite(OUTPUT_PIN_13, LOW);
  116. }
  117. delay(1000);
  118. if (temperature < 40){
  119. digitalWrite(OUTPUT_PIN_8, HIGH);
  120. }
  121. else{digitalWrite(OUTPUT_PIN_8, LOW);
  122. }
  123. delay (1000);
  124. int inputValue = digitalRead(INPUT_PIN_2);
  125. if (inputValue == HIGH){
  126. Serial.println("Input Pin 2 'HIGH' - BATTERY MORE THAN 98%");
  127. }
  128. Serial.println("end");
  129. Serial.println("");
  130. // Delay for a moment to avoid rapid updates
  131. delay(5000);
  132. //kod za display test
  133. display.setBrightness(1);
  134. delay(TEST_DELAY);
  135. // --oC!
  136. display.setSegments(SEG_DONE);
  137. //show temperature on display
  138. display.showNumberDec(temperature, false, 2, 0);
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement