Caden GamacheBrian RashapEdward Ishman
Published © MIT

HawkSpider Vibrations Monitor

A small device that magnetically attaches to machinery (near a motor) and cuts the power if vibrations reach out of expected bounds.

IntermediateWork in progress8 hours4
HawkSpider Vibrations Monitor

Things used in this project

Hardware components

Particle Argon
Piezo Sensor Piezo Sensor
SparkFun Triple Axis Accelerometer Breakout - ADXL335
SparkFun Triple Axis Accelerometer Breakout - ADXL335
Rocker Switch, SPST
Rocker Switch, SPST
Adafruit uSD Module
rAether LM7812/LM7815 AC/DC 12v to 5v Voltage Regulator

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Drill / Driver, 20V
Drill / Driver, 20V
3D Printer (generic)
3D Printer (generic)


Read more

Custom parts and enclosures

Sensor Mount

This model was used to carry both the piezo sensor and 3-axis accelerometer. A magnet will be attached to the back for easily mounting to the metal surface of most machinery.

Sensor Mount v2

I modeled this version for attaching to a PCB using a bolt. However this was later discarded.






This code waits for a button to be pressed, reads accelerometer/piezo data 4096 times, and then writes it to an sd card. Has some serial functionality for trouble shooting.
 * Project HawkSpider_CadenG
 * Description: A proof-of-concept integration that measures vibrations within the Hawk Spider energy storage device and
 *              also controls a relay to disengage components during a vibrations event.
 * Author: Caden Gamache
 * Date: 05/18/2023 - 

/********************** Libraries **********************/ 
#include <SPI.h>
#include <SdFat.h>

/********************** Variables **********************/
// Pinmodes
const int STARTPIN = D7;
const int PIEZOPIN = A0;
const int ACCELX = A2;
const int ACCELY = A3;
const int ACCELZ = A4;

// General
int i;
bool onOff;

// Timers
float logTime;
unsigned int startTime;

// ButtonState
bool logStart;

// SD Card
String dateTime, noYear;
const char FILE_BASE_NAME[] = "Data";
const uint8_t BASE_NAME_SIZE = sizeof(FILE_BASE_NAME) - 1;
const int chipSelect = SS;
float data[4096];
float accelX[4096];
float accelY[4096];
float accelZ[4096];
float timeStamp[4096];
char fileName[13];
int fileNumber = 0;

// Piezo
float piezoVibration;

// Accelerometer
int rawX, rawY, rawZ;
float scaledX, scaledY, scaledZ;  // Scaled values for each axis
int scale = 3;  // 3 (±3g) for ADXL337, 200 (±200g) for ADXL377

/*********************** Objects ***********************/
SdFat sd;
SdFile file;

/********************* Prototypes **********************/
// Same functionality as Arduino's standard map function, except using floats
float mapf(float x, float in_min, float in_max, float out_min, float out_max);

void setup() {
  waitFor(Serial.isConnected, 10000);


  startTime = micros();
  // Initialize at the highest speed supported by the board that is
  // not over 50 MHz. Try a lower speed if SPI errors
  if (!sd.begin(chipSelect, SD_SCK_MHZ(10))) {
    Serial.printf("Error starting SD Module"); 

  if (BASE_NAME_SIZE > 6) {
    Serial.println("FILE_BASE_NAME too long");
    while(1);  // Stop program


void loop() {
  /************************** Button Initialize ***************************/
  logStart = digitalRead(STARTPIN);
  Serial.printf("Press button to log data\n");
  while(logStart == FALSE) {  
    logStart = digitalRead(STARTPIN);  // Traps here until button is pressed
  /******************************* SD Setup *******************************/
  Serial.printf("Data Logging Started\n");
  while (sd.exists(fileName)) {  // Cycle through files until number not found
    sprintf(fileName,"%s%02i.csv",FILE_BASE_NAME,fileNumber);  // Create numbered filename
    Serial.printf("Filename is %s\n",fileName);
  if (!, O_WRONLY | O_CREAT | O_EXCL)) {  // Open file for printing
    Serial.println("File Failed to Open");
  file.printf("Time, Signal, Frequency, FFT Magnitude, Complex FFT, Accelerometer X, Accelerometer Y, Accelerometer Z, Scaled X, Scaled Y, Scaled Z\n");  // Print header row
  Serial.printf("\nLogging to: %s\n",fileName);

  startTime = micros();

  /***************************** Piezo Sensor *****************************/
  for (i=0;i<4096;i++) {
    onOff = !onOff;
    digitalWrite(STARTPIN, onOff);
    logTime = (micros() - startTime) / 1000000.0;

    piezoVibration = analogRead(PIEZOPIN)/1280.0;
    data[i] = piezoVibration;
    timeStamp[i] = logTime;

    accelX[i] = analogRead(ACCELX);
    accelY[i] = analogRead(ACCELY);
    accelZ[i] = analogRead(ACCELZ);


  /***************************** Accelerometer *****************************/
  // Scales based on power connected to 5V (Swap 675 values for 1023 if connected to 3.3V)
  scaledX = mapf(accelX[1], 0, 675, -scale, scale);
  scaledY = mapf(accelY[1], 0, 675, -scale, scale);
  scaledZ = mapf(accelZ[1], 0, 675, -scale, scale);
  // Scaled accelerometer X,Y,Z  readings
  Serial.printf("X = %f g\nY = %f g\nZ = %f g\n",scaledX, scaledY, scaledZ);

  /************************ Time and Write to Drive ************************/
  dateTime = Time.timeStr();  // Collects real world time
  noYear = dateTime.substring(0,19);
  Serial.printf("Time of full data collect %s\n",noYear.c_str());
  for (i=0;i<4096;i++) {
    Serial.printf("Time from start: %f Piezo value = %f\n", timeStamp[i], data[i]);
    file.printf("%f,%f, , , ,%f,%f,%f\n", timeStamp[i], data[i], accelX[i], accelY[i], accelZ[i]);

  digitalWrite(STARTPIN, LOW);
  delay(500);  // Small delay before looping

float mapf(float x, float in_min, float in_max, float out_min, float out_max) {
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;


Caden Gamache

Caden Gamache

3 projects • 8 followers
Finished CNM's internet of things boot-camp where I learned IoT skills. I have a passion for learning and try to build skills wherever I am!
Brian Rashap

Brian Rashap

11 projects • 59 followers
Former General Manager of US Facilities Operations at Intel Corporation. Currently loving my encore career as a teacher focused on IoT.
Edward Ishman

Edward Ishman

3 projects • 17 followers
Thanks to Dr. Brian Rashap and Edward Ishman.


Add projectSign up / Login