Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define Temprature_Sensor_PIN 4
- #define Level_Sensor_LOW__PIN 34
- #define Level_Sensor_MED__PIN 35
- #define Level_Sensor_HIGH_PIN 36
- int LOW__Level_Status = 1;// 1 = no liquid detected
- int MED__Level_Status = 1;// 1 = no liquid detected
- int HIGH_Level_Status = 1;// 1 = no liquid detected
- // GPIO where the DS18B20 is connected to
- const int oneWireBus = Temprature_Sensor_PIN;
- // Setup a oneWire instance to communicate with any OneWire devices
- OneWire oneWire(oneWireBus);
- // Pass our oneWire reference to Dallas Temperature sensor
- DallasTemperature sensors(&oneWire);
- void setup() {
- Serial.begin(9600);
- pinMode(Level_Sensor_LOW__PIN, INPUT);
- pinMode(Level_Sensor_MED__PIN, INPUT);
- pinMode(Level_Sensor_HIGH_PIN, INPUT);
- sensors.begin();
- }
- void loop() {
- // Take 50 readings and calculate average for each sensor
- long lowSum = 0;
- long medSum = 0;
- long highSum = 0;
- int numReadings = 50;
- sensors.requestTemperatures();
- float temperatureC = sensors.getTempCByIndex(0);
- Serial.print(temperatureC);
- Serial.println("ΒΊC");
- for (int i = 0; i < numReadings; i++) {
- lowSum += analogRead(Level_Sensor_LOW__PIN);
- medSum += analogRead(Level_Sensor_MED__PIN);
- highSum += analogRead(Level_Sensor_HIGH_PIN);
- delay(10); // Small delay between readings
- }
- // Calculate averages
- LOW__Level_Status = lowSum / numReadings;
- MED__Level_Status = medSum / numReadings;
- HIGH_Level_Status = highSum / numReadings;
- // Print the averaged values
- Serial.print(LOW__Level_Status);
- Serial.print(" | ");
- Serial.print(MED__Level_Status);
- Serial.print(" | ");
- Serial.print(HIGH_Level_Status);
- Serial.println(" | ");
- if (LOW__Level_Status == 0 && MED__Level_Status == 0 && HIGH_Level_Status == 0) {
- Serial.println("Oil Level is HIGH ---> OK");
- }
- else if (LOW__Level_Status == 0 && MED__Level_Status == 0 && HIGH_Level_Status > 10) {
- Serial.println("Oil Level is Medium ---> Please Fill the Oil and Check For Leaks!!!");
- }
- else if (LOW__Level_Status == 0 && MED__Level_Status > 10 && HIGH_Level_Status > 10) {
- Serial.println("Oil Level is LOW ---> DANGER !!! Please Fill the Oil and Check For Leaks!!!");
- }
- else {
- Serial.println("Oil Level is Empty ---> DANGER !!! STOP THE CAR NOW!!!");
- }
- delay(1000);
- }//end of LOOP
Advertisement
Add Comment
Please, Sign In to add comment