- Piezoelectric Sensor → Connect to Analog Pin A0
- One lead to A0
- Other lead to GND
- (Optional: Add a pull-down resistor ~1MΩ between A0 and GND)
- LED (optional) → Connect to Digital Pin 13
- Anode (long leg) → Pin 13
- Cathode (short leg) → GND via 220Ω resistor
-
Open Arduino IDE
-
Create Sketch Folder
- Create a new folder named
arduino_slip_detectionin your Arduino sketches directory - Typically:
Documents/Arduino/arduino_slip_detection/
- Create a new folder named
-
Copy Files
- Copy
arduino_slip_detection.inoto the sketch folder - Copy
arduino_model.hto the same sketch folder
- Copy
-
Verify File Structure
arduino_slip_detection/ ├── arduino_slip_detection.ino └── arduino_model.h -
Select Board
- Tools → Board → Arduino Uno
-
Select Port
- Tools → Port → [Your Arduino COM Port]
-
Upload
- Click Upload button (or Ctrl+U)
- Wait for "Done uploading" message
-
Open Serial Monitor
- Tools → Serial Monitor (or Ctrl+Shift+M)
- Set baud rate to 9600
-
Expected Output
Slip Detection System Initialized Model: 17 nodes Features: 5 Ready for detection... Features: [0.xxx, 0.xxx, ...] | Prediction: NO_SLIP | Probability: 0.xxx -
Test with Sensor
- Apply pressure/vibration to piezoelectric sensor
- Watch for "SLIP" predictions
- LED on pin 13 will light up when slip is detected
The feature extraction in arduino_slip_detection.ino uses normalization constants that may need adjustment based on your sensor:
Current Normalization (lines 118-122):
features[0] = constrain(features[0], 0.0, 1.0);
features[1] = constrain(features[1] * 2.0, 0.0, 1.0);
features[2] = constrain(features[2] * 5.0, 0.0, 1.0);
features[3] = constrain(features[3] * 5.0, 0.0, 1.0);
features[4] = constrain(features[4], 0.0, 1.0);To Calibrate:
- Run the code and observe feature values in Serial Monitor
- Compare with your training data ranges
- Adjust multipliers (2.0, 5.0, etc.) to match training data distribution
- Model Size: ~17 nodes (very compact!)
- SRAM Usage: ~2KB (well within Arduino Uno's 2KB limit)
- Flash Usage: ~8KB (well within Arduino Uno's 32KB limit)
"arduino_model.h: No such file or directory"
- Ensure
arduino_model.his in the same folder as.inofile - Check file name spelling (case-sensitive)
Model predictions seem wrong
- Verify sensor is connected to A0
- Check feature normalization matches training data
- Ensure sensor readings are in expected range (0-1023)
Serial Monitor shows no output
- Check baud rate is set to 9600
- Verify USB cable connection
- Try resetting Arduino
LED not working
- Check LED polarity (long leg = anode)
- Verify LED is connected to pin 13
- Test LED with simple blink sketch first
After testing with sample data:
- Collect real piezoelectric sensor data
- Label your dataset (slip vs no-slip)
- Retrain model with your data
- Regenerate
arduino_model.h - Re-upload to Arduino
- Sampling Rate: Currently 100 samples per window with 10ms delay = 1 second per prediction
- To Speed Up: Reduce
WINDOW_SIZE(but may affect accuracy) - To Improve Accuracy: Increase
WINDOW_SIZE(but slower predictions)