Making a system to monitor machinery and report anomalies for pre-failure detection

Hi, this is my first post. I received my Uno R3 two days ago and have a "mega kit" of sensors and attachments on its way. I ran my first "blinking led" program last night as I am just learning, while the last time I did any programming was 40 years ago during first year university, I used Pascal back then and remember almost nothing of it, though I passed that subject. I am now an automotive electrician working in a large factory maintaining pallet robots and electric forklifts.

Over the years I have toyed with the occasional Arduino sensor to make a high speed photography sound-flash trigger - but have never previously coded an Arduino.
Now I have a project in mind and a reason to learn to program an Arduino.
My mission: To make a device that monitors the sound of a large area of machinery in the factory to replicate a technician "listening for a worn bearing etc.". So far I have been advised to use the ArduinoFFT library to break the sound into the various frequencies. I've attached an image to show my line of thinking.... the Arduino will record the sound for maybe 10-15 minutes, even an hour or two would be fine, and set the red line - all the maximum peaks of the various frequencies - and save that as the "zero" setting. Then it needs to keep listening for an increase in volume of any of the frequencies [which may be an indication of a failing bearing or similar], but it must only trigger an alert if that sound is constantly above the red line for 15 minutes, to avoid being triggered by a passing vehicle or machinery being water-blasted by workers etc. In the image I whistled during the recording to create a spike.
To start with and test the system I may just set it to bring on a green LED when it has set the threshold and then a red LED if it detects an anomaly, eventually I may try setting it to email me a warning when it detects the increase in activity.
I appreciate any direction on how to approach this project so as to take the shortest path. Thanks in advance. :slight_smile:

Suggest that you first use a laptop computer and microphone to prove that your proposed monitoring system is going to work.

Realisitically to monitor a large area without generating false positives will require the system to know what equipment is currently running, how hard each piece of equiment is working and the mains voltage. If your factory isn't already setup to gather this information then that is a major project to begin with.

Currently you can buy a Wifi webcam/microphone combination for less than $50.
One per machine would give you localised monitoring which arguably would be more useful than large area monitoring.

Thanks for the suggestions. I don't quite see why the system would need to know what voltage the machines are as it will have no bearing on the sound being monitored as it will be a constant. All the machines work at a pretty constant load, conveying vegetables into a factory production line. My thoughts are that I could even set it to monitor the sound for an entire day, or even a week as long as it is when there are no faults present, to set a reliable maximum volume for each frequency. Over such a long period it will have picked up the maximum load of each piece of equipment. After saving the maximum peaks of each frequency it is just a matter of it monitoring and reporting when a particular peak has been exceeded constantly for a set time period, 15 minutes, or even an hour, for example. The longer the time set, the more likely it will be due to the machinery generating more noise than it should. My final project will be an Arduino so I don't want to expend more time and effort on a laptop program when I could jjust go straight to Arduino, also for less than $50.

No it won't, there is only 2K of memory on an Arduino Uno and classic nano, and that is for variable storage and stack return addresses. So the most you can record for is about 2 to 3 seconds of Audio.

I stated that incorrectly, though my limited knowledge may still show that you are correct: It will "listen to" the noise for "an hour" while establishing the maximum peaks of each frequency and keeping a record of them. With the research I have done I have decided to order an SD card shield for it to save that "pattern" after an hour, before it then starts 'listening' to the noise again. If it detects a noise in a frequency that is louder then any of those recorded maximums it will generate an alert if that volume is exceeded consistently for (15 minutes).
I would like it to email me the frequency and volume so I could then use a device to measure for that frequency and see where it is loudest. Does that sound feasible?

I have no idea how reliable ChatGpt is but I will share the first half of its answer to my question:

I would like to program an Arduino to monitor the noise of several machines for 15 minutes and set the maximum volume of each frequency and then keep listening for any increase in sound of any of the frequencies that lasts for more than 10 minutes so it can send an alert that the machinery is failing

ChatGPT

To program an Arduino to monitor the noise of several machines, you will need to:

  1. Collect and Process Sound Data: Use a microphone to collect sound data from the machines.
  2. Frequency Analysis: Perform a frequency analysis (e.g., FFT) to identify the different frequencies and their volumes.
  3. Initial Calibration: Record the maximum volume for each frequency over an initial period (15 minutes).
  4. Continuous Monitoring: Continuously monitor the sound levels and compare them to the initial maximum volumes.
  5. Detect Changes: Detect if any frequency exceeds its initial maximum volume for more than 10 minutes.
  6. Send Alerts: Send an alert if such a condition is detected.

Here is a step-by-step outline to help you achieve this:

Components Needed

  1. Arduino Board: e.g., Arduino Uno
  2. Microphone Module: e.g., KY-038 or similar
  3. SD Card Module: To store initial calibration data
  4. WiFi/Bluetooth Module: To send alerts (optional, for remote alerts)
  5. Power Supply

Libraries Required

  1. FFT Library: For frequency analysis
  2. SD Library: For data logging
  3. WiFi/Bluetooth Library: For sending alerts

Step-by-Step Implementation

1. Setup Hardware

  • Connect the microphone module to the Arduino (analog input).
  • Connect the SD card module to the Arduino.
  • (Optional) Connect the WiFi/Bluetooth module.

2. Initial Calibration

cpp

Copy code

#include <SD.h>
#include <SPI.h>
#include <ArduinoFFT.h>

const int micPin = A0;
const int chipSelect = 4;  // SD card module select pin
const unsigned int samplingFrequency = 1000; // Hz
const unsigned int samples = 128;  // Must be a power of 2

double vReal[samples];
double vImag[samples];
ArduinoFFT FFT = ArduinoFFT(vReal, vImag, samples, samplingFrequency);

void setup() {
  Serial.begin(9600);
  if (!SD.begin(chipSelect)) {
    Serial.println("SD card initialization failed!");
    return;
  }
  Serial.println("SD card initialized.");
  
  // Perform initial calibration
  File dataFile = SD.open("maxVolumes.txt", FILE_WRITE);
  if (dataFile) {
    for (int i = 0; i < 900; i++) {  // 15 minutes = 900 seconds
      recordAndAnalyze(dataFile);
      delay(1000); // Wait 1 second
    }
    dataFile.close();
  } else {
    Serial.println("Error opening file for writing");
  }
}

void loop() {
  // Continuous monitoring code will go here
}

void recordAndAnalyze(File &dataFile) {
  for (int i = 0; i < samples; i++) {
    vReal[i] = analogRead(micPin);
    vImag[i] = 0;
    delay(1000 / samplingFrequency);
  }
  FFT.Windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD);
  FFT.Compute(FFT_FORWARD);
  FFT.ComplexToMagnitude();
  
  double maxVolume[samples / 2];
  for (int i = 0; i < samples / 2; i++) {
    if (vReal[i] > maxVolume[i]) {
      maxVolume[i] = vReal[i];
    }
  }
  
  for (int i = 0; i < samples / 2; i++) {
    dataFile.print(maxVolume[i]);
    if (i < samples / 2 - 1) dataFile.print(",");
  }
  dataFile.println();
}

Let me tell you.

It knows nothing, it has no intelligence at all. It will always give you a answer, but it is more than likely that the answer you will get will be wrong. It is excellent at BS.

It has no idea of context, it simply strings stuff together based on the likelihood of the probity of the most used word following the previous one.

It is only of use if you know how to spot its mistakes.

2 Likes

would a worn bearing result in increased current consumption by the motors which drive the machinery? You could using a microcontroller to monitor the current and report problems.
Some years ago I implemented software which monitored machines for broken or worn tools in a factory. Results being transmitted over ethernet using UDP datagrams to a central server.
The machines also had a keypad for operators to enter job numbers etc

A dry bearing may even cause less drag initially as opposed to being packed with grease - though I'm not 100% sure. Also, in this situation there is a lot of water splashing around, and some bearings inside rollers, so not practical to add close-up sensors as some have suggested. The product coming up the conveyors also varies occasionally, sometimes really big potatoes with rocks in between so the load current will vary according to that and make the cause of change in current harder to nail down.

Then it might be better to monitor the speed of the conveyor belt to see how it varies from the set speed. Are you in Idaho?

I'm in New Zealand. There are several conveyors, water splashing everywhere, and other machines that don't have conveyors, hence the reason I just want to monitor the sound. We have bigger machines inside the factory with dedicated monitoring devices - I want to make something general purpose.

Seriously, this project is right for using artificial intelligence to know the changes in reoccurring sounds.

1 Like

Just to be certain, are you suggesting a 'bigger' project with a more powerful processor? I recently learned about TinyML which sounds quite interesting though maybe not 'tiny' enough for an Uno. I watched a few videos where they 'teach' a machine various sounds and tell them which are bad etc. I imagine once I am able to get my little project working I will dig deeper into the machine learning side of things for an upgraded model.

Your project is based on an untold number of "sounds". Somehow you must classify them so they can be compared to each other over an extended period of time. Who is going to classify them, note any changes from time to time and if there is a significant difference, report that difference?

You don't need to know each sound, FFT is going to classify them and save the peaks of each frequency FFT based on other suggestions I have received.
Then the Arduino will monitor the sounds and only report a frequency that goes above its original peak for more than 15 minutes. You will over-complicate it if you try to think in terms of recognizable sounds when it can just be a matter of monitoring frequencies.

Would using a 14 channel graphic equalizer as the basis for measurements simplify things?

You will be extremely lucky if this strategy actually works.

In theory it sounds simple enough but real life is not like that. In practice any FFT of a real sound jumps about all over the place with the peaks in each harmonic bin are all interrelated. This is because sound contains a lot more information than a single peak meaning anything.

What is this chip? The only one I know of is the MSGEQ7 which is a 7 channel equaliser. You can use two for two different sources like left and right stereo channels. At a pinch you can use two with the same input and slightly miss tune one to fill in between the peaks.

However, the problem with this is that they are only second order filters to begin with, and trying to get this extended number of channels results in only having first order filters. The "order" of a filter is how sharply it changes output with a change in frequency, and a first order filter is what you get with an RC (resistor - capacitor) filter, and second order is what you get with an LC (Inductor - capacitor) filter.

Also these chips are not very stable and are subject to noise.

This is a video I made showing this chip with a sin wave signal generator. Notice that some frequences can be above or below the audio range so some listeners.

Spectrum Display

The music samples show the left / right stereo. Note that they are reflected so that each colour represents the same bandwidth. You can "see" the effect of stereo on the different types of music.

So do you actually have some sort of solution or are you just suggesting nothing will work for me?

I am suggesting that so far you have not come up with a viable solution. It is your use of a Uno coupled with relying on the change in harmonic bins that would not work.

You might get some joy (but not guaranteed) if you use some AI. Not the chat GPT sort of AI, but the real pattern recognition stuff.
Like @Paul_KD7HB suggested in Post#14

This sort of thing:-
Google’s flagship machine learning library: “TensorFlow“

But a lot depends on the training data.
https://www.eetasia.com/news/article/Data-is-King-for-AI-Sound-Recognition