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 hours83
HawkSpider Vibrations Monitor

Things used in this project

Hardware components

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

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)

Story

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.

Schematics

HawkSpiderFritz_CadenG_schem

HawkSpiderFritz_CadenG_breadboard

Code

HawkSpider_CadenG

C/C++
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 - 
 */
SYSTEM_MODE(SEMI_AUTOMATIC);

/********************** 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() {
  Serial.begin(9600);
  waitFor(Serial.isConnected, 10000);

  pinMode(STARTPIN,INPUT_PULLDOWN);
  pinMode(PIEZOPIN,INPUT);

  Particle.syncTime();
  startTime = micros();
  
  // Initialize at the highest speed supported by the board that is
  // not over 50 MHz. Try a lower speed if SPI errors occur.cc
  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
  }

  sprintf(fileName,"%s%02i.csv",FILE_BASE_NAME,fileNumber);
}

void loop() {
  /************************** Button Initialize ***************************/
  pinMode(STARTPIN,INPUT_PULLDOWN);
  logStart = digitalRead(STARTPIN);
  Serial.printf("Press button to log data\n");
  while(logStart == FALSE) {  
    logStart = digitalRead(STARTPIN);  // Traps here until button is pressed
    Serial.printf("");
  }
  /******************************* SD Setup *******************************/
  Serial.printf("Data Logging Started\n");
  while (sd.exists(fileName)) {  // Cycle through files until number not found
    fileNumber++;
    sprintf(fileName,"%s%02i.csv",FILE_BASE_NAME,fileNumber);  // Create numbered filename
    Serial.printf("Filename is %s\n",fileName);
  }
  if (!file.open(fileName, 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 *****************************/
  pinMode(STARTPIN, OUTPUT);
  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);

    delayMicroseconds(2500);
  }

  /***************************** 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]);
    delayMicroseconds(500);
  }

  file.close();
  Serial.printf("Done\n");
  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;
}

Credits

Caden Gamache
4 projects • 9 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!
Contact
Brian Rashap
13 projects • 118 followers
Former General Manager of US Facilities Operations at Intel Corporation. Currently loving my encore career as a teacher focused on IoT.
Contact
Edward Ishman
5 projects • 70 followers
Contact
Thanks to Dr. Brian Rashap and Edward Ishman.

Comments

Please log in or sign up to comment.