Flowchart for detecting motor temperature and giving sound indiction.

In the above flowchart you can see how the system software works. First it checks for motor temperature and gives proper indication about it. Bellow is the working video of the system.
Arduino code
First we read sensor value from ADC.
// Read sensor value
int newValue = analogRead(A1);
Than we filter those value using median filter. Median Filter function code is given bellow. There were many software filter available like SMA(Simple mean average), LMA(Logarithmic mean average), median filter. SMA was still giving lots of error, so we have used median filter for processing sensor data. it was still giving some error. We are looking for more better software filter for processing sensor values.
/*Median Filter */
// Median filter function
int median(int *array, int size) {
int sorted[size];
// Copy array
for (int i = 0; i < size; i++) {
sorted[i] = array[i];
}
// Simple bubble sort
for (int i = 0; i < size - 1; i++) {
for (int j = 0; j < size - i - 1; j++) {
if (sorted[j] > sorted[j + 1]) {
int temp = sorted[j];
sorted[j] = sorted[j + 1];
sorted[j + 1] = temp;
}
}
}
After filtering the Raw ADC sensor data using median filter. We convert the filtered value to voltage. Code for which is given bellow.
int rawValue = filteredValue; float voltage = rawValue * 0.00323 ; // Convert to voltage const float Rref = 992.0; //1K ohm referance resistor // Calculate sensor resistance from voltage divider formula float Rt = Rref*( voltage / (3.307 - voltage));
After converting to voltage. We convert the voltage value to temperature using "Invert Callendar-Van Dusen" technique which has some constant in it. bellow is the code for it.
// Callendar-Van Dusen coefficients for standard PT1000 (α = 0.00385)
const float A = 3.9083e-3;
const float B = -5.775e-7;
const float R0 = 1000.0; // PT1000 resistance at 0°C
//Function for voltage to temperature convertion
float calculateTemperature(float Rt) {
float temp = -A + sqrt(A * A - 4 * B * (1 - Rt / R0));
temp = temp / (2 * B);
return temp;
}
After doing all the required processes we simply print this value in serial terminal and give appropriate buzzer indication based on algorithm shown in flowchart. bellow is the code for it.
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(10);
/*Median Filter Local Varibales*/
// Read sensor value
int newValue = analogRead(A1);
int filteredValue;
// Store new value in buffer
readings[index1] = newValue;
index1 = (index1 + 1) % windowSize;
// Check if buffer is full
if (index1 == 0) bufferFilled = true;
// Apply median filter only when buffer is filled
if (bufferFilled) {
filteredValue = median(readings, windowSize);
Serial.print("Raw: ");
Serial.print(newValue);
Serial.print(" Filtered: ");
Serial.println(filteredValue);
} else {
Serial.print("Raw: ");
Serial.print(newValue);
Serial.println(" (Warming up)");
}
//Serial Read Write
int rawValue = filteredValue;
float voltage = rawValue * 0.00323 ; // Convert to voltage
const float Rref = 992.0; //1K ohm referance resistor
float Res = (Rref*voltage)/(3.3-voltage);
// Calculate sensor resistance from voltage divider formula
float Rt = Rref*( voltage / (3.307 - voltage));
// Invert Callendar-Van Dusen to get temperature (for T ≥ 0°C)
float temp = calculateTemperature(Rt-20.0);
Serial.print("Raw ADC Value: ");
Serial.print(rawValue);
Serial.print(" => Voltage: ");
Serial.print(voltage, 3); // 3 decimal places
Serial.println(" V");
Serial.println(" Resistance");
Serial.println(Rt-20.0);
Serial.println(" Temperature");
Serial.println(temp);
//Buzzer program
if(Rt > 1174 and Rt < 1194){
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100); // wait for a 100 milisecond
for(int a = 0; a<5; a++){
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(100);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100);
}
}
else if(Rt >= 1194){
digitalWrite(LED_BUILTIN, LOW); // turn the LED off (Low is the voltage level)
delay(1000);
}
}