You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const unsigned long sampleTime = 1000 / sampleRate; // 10ms between samples
164
163
165
164
// Data collection variables
166
165
unsigned long lastSample = 0;
167
-
int sampleCount = 0;
168
-
bool collecting = false;
169
166
170
167
void setup() {
171
168
Serial.begin(115200);
172
169
analogReadResolution(14);
173
170
174
171
Serial.println("- Motor Vibration Data Collector");
175
-
Serial.println("- Send 'start' to begin data collection");
172
+
Serial.println("- Streaming continuous data for Edge Impulse");
176
173
Serial.println("- Data format: X_accel,Y_accel,Z_accel");
177
174
178
175
delay(1000);
179
176
}
180
177
181
178
void loop() {
182
-
// Check for commands
183
-
if (Serial.available()) {
184
-
String command = Serial.readString();
185
-
command.trim();
186
-
187
-
if (command == "start" && !collecting) {
188
-
startCollection();
189
-
} else if (command == "stop" && collecting) {
190
-
stopCollection();
191
-
}
192
-
}
193
-
194
-
// Collect data if active
195
-
if (collecting) {
196
-
collectData();
197
-
}
198
-
}
199
-
200
-
void startCollection() {
201
-
collecting = true;
202
-
sampleCount = 0;
203
-
lastSample = millis();
204
-
205
-
Serial.println("- Starting data collection...");
206
-
delay(100);
207
-
}
208
-
209
-
void stopCollection() {
210
-
collecting = false;
211
-
Serial.println();
212
-
Serial.print("- Data collection stopped. Samples: ");
213
-
Serial.println(sampleCount);
214
-
Serial.println("- Send 'start' for another window");
215
-
}
216
-
217
-
void collectData() {
218
179
unsigned long currentTime = millis();
219
180
220
181
if (currentTime - lastSample >= sampleTime) {
@@ -240,12 +201,7 @@ void collectData() {
240
201
Serial.print(",");
241
202
Serial.println(zAccel, 4);
242
203
243
-
sampleCount++;
244
204
lastSample = currentTime;
245
-
246
-
if (sampleCount >= windowSize) {
247
-
stopCollection();
248
-
}
249
205
}
250
206
}
251
207
```
@@ -285,22 +241,21 @@ To ensure accurate vibration analysis and successful machine learning training,
285
241
```arduino
286
242
// Sampling parameters
287
243
const int sampleRate = 100; // 100 Hz
288
-
const int windowSize = 200; // 2-second windows
289
-
const unsigned long sampleTime = 1000 / sampleRate; // 10ms between samples
244
+
const unsigned long sampleTime = 1000 / sampleRate; // 10 ms between samples
290
245
```
291
246
292
247
In this code:
293
248
294
249
- Sample rate of 100 Hz captures enough frequency response for detecting most motor faults
295
-
- Window size of 200 samples creates 2-second data segments that work well with Edge Impulse training
296
250
- Sample time calculation automatically determines the precise timing needed between measurements
251
+
- The system streams data continuously without requiring manual start/stop commands
297
252
298
253
### Signal Processing and Conversion
299
254
300
255
Once we have the raw sensor readings, we need to convert them into useful acceleration values. This conversion process transforms the ADC readings into data we can analyze:
301
256
302
257
```arduino
303
-
void collectData() {
258
+
void loop() {
304
259
unsigned long currentTime = millis();
305
260
306
261
if (currentTime - lastSample >= sampleTime) {
@@ -347,12 +302,14 @@ In this code:
347
302
348
303
After uploading the example sketch to the Nano R4 board, you should see this output in the Arduino IDE's Serial Monitor when data collection is active:
349
304
350
-

305
+

351
306
352
307
### Complete Example Sketch
353
308
354
309
Download the complete data collection example sketch [here](assets/motor_vibration_collector.zip).
## Connecting the Vibration Monitor to Edge Impulse
357
314
358
315
As vibration-based condition monitoring becomes more important for predictive maintenance, connecting our data collection system to Edge Impulse enables the development of intelligent anomaly detection models. Edge Impulse provides a complete platform for embedded machine learning, allowing us to transform raw vibration data into useful insights about motor health.
@@ -372,6 +329,8 @@ The first step involves creating an Edge Impulse account and setting up a new pr
372
329
- Choose project type: Personal (free tier with 60 min job limit, 4 GB data limit)
373
330
- Choose project setting: Private (recommended for this application)
374
331
332
+

333
+
375
334
3.**Project Configuration**: Once created, the project will be ready for data collection. Sampling frequency and window settings will be configured later during impulse design.
376
335
377
336
### Data Collection with Edge Impulse CLI
@@ -395,6 +354,8 @@ Verify the installation with the following command:
Now that you have the CLI installed, you can set up data forwarding to stream vibration data directly from your Nano R4 board to Edge Impulse.
@@ -407,14 +368,18 @@ edge-impulse-data-forwarder
407
368
408
369
The tool will guide you through the setup process:
409
370
410
-
1. Log in with your Edge Impulse credentials when prompted
411
-
2. Select your motor anomaly detection project
412
-
3. Choose the correct serial port for your Arduino
413
-
4. Set baud rate to `115200`
414
-
5. Select data format: `CSV`
415
-
6. Configure 3 columns for `X`, `Y`, `Z` acceleration data
371
+
1.**Login**: Enter your Edge Impulse username/email and password when prompted
372
+
2.**Select Device**: Choose the correct serial port for your Arduino (for example, `COM5`)
373
+
3.**Data Detection**: The tool will automatically detect the data frequency (100 Hz) and number of sensor axes (3)
374
+
4.**Name Axes**: When asked "What do you want to call them?", enter: `X`,`Y`,`Z`
375
+
5.**Device Name**: Give your device a name (for example, `nano-r4`)
376
+
6.**Project Connection**: If you have multiple projects, the tool will ask which Edge Impulse project you want to connect the device to. Select your motor anomaly detection project.
377
+
378
+

379
+
380
+
Once configured, the forwarder will stream data from your Nano R4 board to Edge Impulse. You can verify the device connection by checking the "Devices" tab in Edge Impulse Studio. You can then start collecting training data for your machine learning model.
416
381
417
-
Once configured, the forwarder will stream data from your Nano R4 to Edge Impulse when you send the `start` command through the Arduino IDE's Serial Monitor.
382
+

418
383
419
384
#### Data Collection Process
420
385
@@ -453,37 +418,43 @@ The spectral analysis block extracts relevant features from the raw vibration si
453
418
454
419
#### Model Training Process
455
420
456
-
Follow these steps to train the anomaly detection model using the collected normal operation data:
421
+
Follow these steps to train the anomaly detection model using the collected idle and nominal operation data:
457
422
458
423
1.**Generate Features**: Click "Generate features" to extract spectral features from all training data
459
424
2.**Feature Explorer**: Review the feature explorer visualization to verify data quality and feature separation
460
425
3.**Anomaly Detection Setup**: Configure K-means clustering with 32 clusters for pattern recognition
461
-
4.**Axis Selection**: Use "Select suggested axes" to automatically choose most relevant spectral features
462
-
5.**Start Training**: Initiate the training process and monitor convergence metrics
426
+
4.**Axis Selection**: Use "Select suggested axes" to automatically choose the most relevant spectral features
427
+
5.**Start Training**: Start the training process and monitor convergence metrics
428
+
429
+
***__Important note__: The feature explorer shows how well your idle and nominal data separate in the feature space. Good separation means the model can clearly distinguish between different operating states. If the data points overlap significantly, you may need to collect more diverse data or adjust your sensor mounting.***
463
430
464
431
The training process creates clusters representing normal motor operation patterns. Any future data that falls outside these established clusters will be identified as anomalous.
465
432
433
+
***__Important note__: The 32 clusters create a detailed map of normal operation patterns. Each cluster represents a different "type" of normal vibration signature. When new data doesn't fit well into any existing cluster, it's flagged as an anomaly. More clusters provide finer detail but require more training data.***
434
+
466
435
#### Model Validation and Testing
467
436
468
437
After training completion, validate the model performance using the following methods:
469
438
470
439
-**Live Classification**: Test with new motor data to verify anomaly detection capability
471
440
-**Threshold Tuning**: Adjust anomaly threshold (typically 0.3-0.5) based on desired sensitivity
472
441
-**Performance Analysis**: Review clustering quality and feature importance rankings
473
-
-**False Alarm Testing**: Validate with known normal conditions to minimize false positives
442
+
-**False Alarm Testing**: Validate with known normal conditions to reduce false positives
443
+
444
+
***__Important note__: The anomaly threshold is critical for system performance. A lower threshold (0.2 to 0.3) makes the system more sensitive and catches subtle problems but may trigger false alarms. A higher threshold (0.4 to 0.6) reduces false alarms but might miss early-stage faults. Start with 0.3 and adjust based on your specific application requirements.***
474
445
475
446
### Model Deployment
476
447
477
448
After successful training and validation, deploy the model as an Arduino library for embedded inference:
478
449
479
450
1.**Deployment Section**: Navigate to the "Deployment" tab in Edge Impulse Studio
480
451
2.**Arduino Library**: Select "Arduino library" as the deployment target
481
-
3.**Optimization Settings**: Choose "int8" quantization for memory efficiency on the Nano R4
482
-
4.**Model Analysis**:Review memory usage and inference timing estimates
452
+
3.**Optimization Settings**: Choose `int8` quantization for memory efficiency on the Nano R4
453
+
4.**Model Analysis**:Review memory usage and inference timing estimates
483
454
5.**Download Library**: Download the generated Arduino library ZIP file
484
455
6.**Library Installation**: Install in Arduino IDE using "Sketch > Include Library > Add .ZIP Library"
485
456
486
-
The generated library includes optimized inference code specifically compiled for the Arduino Nano R4's ARM Cortex-M4 processor, ensuring efficient real-time anomaly detection with minimal computational overhead.
457
+
The generated library includes optimized inference code specifically compiled for the Nano R4's Arm® Cortex®-M4 processor, ensuring efficient real-time anomaly detection with low computational overhead.
487
458
488
459
## Improving the Vibration Monitor with Machine Learning
0 commit comments