safwan092

Untitled

Oct 18th, 2025
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3.  
  4.  
  5. #define Temprature_Sensor_PIN 4
  6. #define Level_Sensor_LOW__PIN 34
  7. #define Level_Sensor_MED__PIN 35
  8. #define Level_Sensor_HIGH_PIN 36
  9.  
  10. int LOW__Level_Status = 1;// 1 = no liquid detected
  11. int MED__Level_Status = 1;// 1 = no liquid detected
  12. int HIGH_Level_Status = 1;// 1 = no liquid detected
  13.  
  14.  
  15. // GPIO where the DS18B20 is connected to
  16. const int oneWireBus = Temprature_Sensor_PIN;
  17. // Setup a oneWire instance to communicate with any OneWire devices
  18. OneWire oneWire(oneWireBus);
  19. // Pass our oneWire reference to Dallas Temperature sensor
  20. DallasTemperature sensors(&oneWire);
  21.  
  22.  
  23. void setup() {
  24. Serial.begin(9600);
  25. pinMode(Level_Sensor_LOW__PIN, INPUT);
  26. pinMode(Level_Sensor_MED__PIN, INPUT);
  27. pinMode(Level_Sensor_HIGH_PIN, INPUT);
  28. sensors.begin();
  29. }
  30.  
  31. void loop() {
  32. // Take 50 readings and calculate average for each sensor
  33. long lowSum = 0;
  34. long medSum = 0;
  35. long highSum = 0;
  36. int numReadings = 50;
  37. sensors.requestTemperatures();
  38. float temperatureC = sensors.getTempCByIndex(0);
  39. Serial.print(temperatureC);
  40. Serial.println("ΒΊC");
  41. for (int i = 0; i < numReadings; i++) {
  42. lowSum += analogRead(Level_Sensor_LOW__PIN);
  43. medSum += analogRead(Level_Sensor_MED__PIN);
  44. highSum += analogRead(Level_Sensor_HIGH_PIN);
  45. delay(10); // Small delay between readings
  46. }
  47.  
  48. // Calculate averages
  49. LOW__Level_Status = lowSum / numReadings;
  50. MED__Level_Status = medSum / numReadings;
  51. HIGH_Level_Status = highSum / numReadings;
  52.  
  53. // Print the averaged values
  54. Serial.print(LOW__Level_Status);
  55. Serial.print(" | ");
  56. Serial.print(MED__Level_Status);
  57. Serial.print(" | ");
  58. Serial.print(HIGH_Level_Status);
  59. Serial.println(" | ");
  60.  
  61. if (LOW__Level_Status == 0 && MED__Level_Status == 0 && HIGH_Level_Status == 0) {
  62. Serial.println("Oil Level is HIGH ---> OK");
  63. }
  64. else if (LOW__Level_Status == 0 && MED__Level_Status == 0 && HIGH_Level_Status > 10) {
  65. Serial.println("Oil Level is Medium ---> Please Fill the Oil and Check For Leaks!!!");
  66. }
  67. else if (LOW__Level_Status == 0 && MED__Level_Status > 10 && HIGH_Level_Status > 10) {
  68. Serial.println("Oil Level is LOW ---> DANGER !!! Please Fill the Oil and Check For Leaks!!!");
  69. }
  70. else {
  71. Serial.println("Oil Level is Empty ---> DANGER !!! STOP THE CAR NOW!!!");
  72. }
  73.  
  74. delay(1000);
  75.  
  76. }//end of LOOP
Advertisement
Add Comment
Please, Sign In to add comment