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
title: 'Motor Anomaly Detection with the Arduino® Nano R4'
2
+
title: 'Motor Anomaly Detection with the Nano R4'
3
3
description: "This application note describes how to implement a motor anomaly detection system using the Nano R4 board, an accelerometer and Edge Impulse."
4
4
difficulty: intermediate
5
5
compatible-products: [nano-r4]
@@ -214,7 +214,7 @@ The complete example sketch is shown below.
214
214
accelerometer or Modulino Movement connected to an Arduino Nano R4.
215
215
The data is formatted for Edge Impulse data collection and training.
216
216
217
-
@version 2.0 01/06/25
217
+
@version 2.5 01/06/25
218
218
@author Arduino Product Experience Team
219
219
*/
220
220
@@ -223,7 +223,7 @@ The complete example sketch is shown below.
223
223
// #define USE_MODULINO // For Modulino Movement (LSM6DSOXTR)
224
224
225
225
#ifdef USE_MODULINO
226
-
#include <Arduino_Modulino.h>
226
+
#include <Modulino.h>
227
227
ModulinoMovement movement;
228
228
#endif
229
229
@@ -254,14 +254,38 @@ unsigned long lastSample = 0;
254
254
255
255
void setup() {
256
256
Serial.begin(115200);
257
+
while (!Serial);
257
258
258
259
#ifdef USE_MODULINO
259
-
// Initialize Modulino Movement
260
+
// Initialize Modulino I2C communication
260
261
Modulino.begin();
261
-
movement.begin();
262
+
263
+
// Detect and connect to movement sensor module
264
+
if (!movement.begin()) {
265
+
Serial.println("Failed to initialize Modulino Movement!");
266
+
while (1);
267
+
}
262
268
263
269
Serial.println("- Motor Vibration Data Collector (Modulino Movement)");
-`movement.begin()` specifically initializes the Movement sensor with default settings
412
444
- No pin assignments are needed as the sensor communicates via I²C through the Qwiic connector
413
445
- The sensor automatically configures itself with optimal settings for vibration monitoring
414
-
446
+
- Values are returned directly in g units without requiring additional conversion
415
447
416
448
### Data Collection Timing and Control
417
449
@@ -470,45 +502,46 @@ For the digital Modulino Movement, the conversion is handled internally by the s
470
502
471
503
```arduino
472
504
#ifdef USE_MODULINO
473
-
// Read acceleration data from Modulino Movement
474
-
if (movement.isDataReady()) {
475
-
xAccel = movement.getAccelerationX();
476
-
yAccel = movement.getAccelerationY();
477
-
zAccel = movement.getAccelerationZ();
478
-
} else {
479
-
// Skip this sample if data not ready
480
-
return;
481
-
}
505
+
// Read new movement data from the sensor
506
+
movement.update();
507
+
508
+
// Get acceleration values (already in g units)
509
+
xAccel = movement.getX();
510
+
yAccel = movement.getY();
511
+
zAccel = movement.getZ();
482
512
#endif
483
513
```
484
514
485
515
In this code:
486
516
487
-
-`isDataReady()`checks if new data is available from the sensor
517
+
-`movement.update()`refreshes the sensor data
488
518
- The acceleration values are returned directly in g units, eliminating manual calibration
489
519
- Built-in digital filtering provides clean, noise-free measurements
490
-
-Data skipping prevents invalid readings when sensor data isn't ready
520
+
-No conversion calculations are needed as the sensor handles all processing internally
491
521
492
522
### Edge Impulse Data Formatting
493
523
494
524
The final step formats our acceleration data so it can be used with Edge Impulse data collection tools:
495
525
496
526
```arduino
497
-
// Output CSV format
498
-
Serial.print(xAccel, 4);
499
-
Serial.print(",");
500
-
Serial.print(yAccel, 4);
501
-
Serial.print(",");
502
-
Serial.println(zAccel, 4);
527
+
// Output CSV format for Edge Impulse
528
+
if (dataValid) {
529
+
Serial.print(xAccel, 4);
530
+
Serial.print(",");
531
+
Serial.print(yAccel, 4);
532
+
Serial.print(",");
533
+
Serial.println(zAccel, 4);
534
+
}
503
535
```
504
536
505
537
In this code:
506
538
507
539
- CSV format with four decimal places gives us the precision needed for machine learning training
508
540
- Single-line output per sample makes it easy to integrate with the Edge Impulse data forwarder
509
541
- Comma separation follows standard CSV format that most data processing tools expect
542
+
- The output format is identical regardless of which sensor is used, ensuring compatibility with Edge Impulse
510
543
511
-
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:
544
+
After uploading the example sketch to the Nano R4 board, you should see output in the Arduino IDE's Serial Monitor similar to this:
512
545
513
546

514
547
@@ -724,7 +757,7 @@ The complete enhanced example sketch is shown below:
724
757
either an ADXL335 accelerometer or Modulino Movement and Edge Impulse
725
758
machine learning model deployed on Arduino Nano R4 for predictive maintenance.
726
759
727
-
@version 2.0 01/06/25
760
+
@version 2.1 01/06/25
728
761
@author Arduino Product Experience Team
729
762
*/
730
763
@@ -736,7 +769,7 @@ The complete enhanced example sketch is shown below:
736
769
// #define USE_MODULINO // For Modulino Movement (LSM6DSOXTR)
737
770
738
771
#ifdef USE_MODULINO
739
-
#include <Arduino_Modulino.h>
772
+
#include <Modulino.h>
740
773
ModulinoMovement movement;
741
774
#endif
742
775
@@ -792,9 +825,14 @@ void setup() {
792
825
while (!Serial);
793
826
794
827
#ifdef USE_MODULINO
795
-
// Initialize Modulino Movement
828
+
// Initialize Modulino I2C communication
796
829
Modulino.begin();
797
-
movement.begin();
830
+
831
+
// Detect and connect to movement sensor module
832
+
if (!movement.begin()) {
833
+
Serial.println("Failed to initialize Modulino Movement!");
834
+
while (1);
835
+
}
798
836
799
837
ei_printf("Motor Anomaly Detection System (Modulino Movement)\n");
@@ -1034,7 +1069,7 @@ The enhanced sketch starts by selecting the appropriate sensor and including the
1034
1069
// #define USE_MODULINO // For Modulino Movement (LSM6DSOXTR)
1035
1070
1036
1071
#ifdef USE_MODULINO
1037
-
#include <Arduino_Modulino.h>
1072
+
#include <Modulino.h>
1038
1073
ModulinoMovement movement;
1039
1074
#endif
1040
1075
@@ -1093,16 +1128,13 @@ For the digital Modulino Movement, the system reads calibrated acceleration valu
1093
1128
1094
1129
```arduino
1095
1130
#ifdef USE_MODULINO
1096
-
// Read acceleration data from Modulino Movement
1097
-
if (movement.isDataReady()) {
1098
-
xAccel = movement.getAccelerationX();
1099
-
yAccel = movement.getAccelerationY();
1100
-
zAccel = movement.getAccelerationZ();
1101
-
} else {
1102
-
// Use last known values if data not ready
1103
-
sample--; // Retry this sample
1104
-
continue;
1105
-
}
1131
+
// Read new movement data from the sensor
1132
+
movement.update();
1133
+
1134
+
// Get acceleration values (already in g units)
1135
+
xAccel = movement.getX();
1136
+
yAccel = movement.getY();
1137
+
zAccel = movement.getZ();
1106
1138
#endif
1107
1139
```
1108
1140
@@ -1140,7 +1172,7 @@ This function reads vibration data from the selected accelerometer and converts
1140
1172
1141
1173
### Machine Learning Inference Execution
1142
1174
1143
-
The system analyzes the collected vibration data using both machine learning models to determine motor state and detect anomalies.
1175
+
The system analyzes the collected vibration data using both machine learning models to determine motor state and detect anomalies. The inference process is identical regardless of which sensor you're using, as both provide the same data format to the models.
1144
1176
1145
1177
```arduino
1146
1178
void performInference() {
@@ -1182,7 +1214,7 @@ This function runs both models on the collected data. The classification model d
1182
1214
1183
1215
### Anomaly Detection and Alert System
1184
1216
1185
-
The system provides feedback when it detects problems with the motor.
1217
+
The system provides feedback when it detects problems with the motor, using the same alert mechanism regardless of which sensor is providing the data.
1186
1218
1187
1219
```arduino
1188
1220
void triggerAnomalyAlert() {
@@ -1211,7 +1243,7 @@ After uploading the enhanced sketch to the Nano R4 board, you should see the fol
1211
1243
1212
1244

1213
1245
1214
-
When an anomaly is detected, the built-in LED will flash twice and the serial output will display the anomaly score above the configured threshold along with a warning message.
1246
+
When an anomaly is detected, the built-in LED will flash three times and the serial output will display the anomaly score above the configured threshold along with a warning message.
1215
1247
1216
1248
### Complete Enhanced Example Sketch
1217
1249
@@ -1222,7 +1254,7 @@ The complete intelligent motor anomaly detection sketch can be downloaded [here]
1222
1254
1223
1255
### System Integration Considerations
1224
1256
1225
-
When deploying the intelligent anomaly detection system in industrial environments, consider the following factors:
1257
+
When deploying the intelligent anomaly detection system in industrial environments, consider the following factors based on your sensor choice:
1226
1258
1227
1259
-**Environmental Protection**: Protect the Nano R4 board and accelerometer from dust, moisture and temperature extremes using appropriate enclosures rated for the operating environment.
1228
1260
-**Mounting Stability**: Ensure secure mechanical mounting of both the accelerometer sensor and the Nano R4 enclosure to prevent sensor movement that could affect measurement accuracy.
0 commit comments