Hello all,
We are trying to write code to make a vibrating motor vibrate when the data from an accelerometer is within certain parameters. We have beginner code to get the data from the accelerometer, but are having some trouble figuring out how to use this data to send a charge to a specific pin, and how to tell the Arduino when exactly to send the charge. We are using an Arduino Uno along with a MPU9250 accelerometer. Any and all help is appreciated.
Pasted here is our current code:
#include "MPU9250.h"
// an MPU9250 object with the MPU-9250 sensor on I2C bus 0 with address 0x68
MPU9250 IMU(Wire,0x68);
int status;
void setup() {
// serial to display data
Serial.begin(115200);
while(!Serial) {}
// start communication with IMU
status = IMU.begin();
if (status < 0) {
Serial.println("IMU initialization unsuccessful");
Serial.println("Check IMU wiring or try cycling power");
Serial.print("Status: ");
Serial.println(status);
while(1) {}
}
}
void loop() {
// read the sensor
IMU.readSensor();
// display the data
Serial.print("AccelX: ");
Serial.print(IMU.getAccelX_mss(),6);
Serial.print("\t");
Serial.print("AccelY: ");
Serial.print(IMU.getAccelY_mss(),6);
Serial.print("\t");
Serial.print("AccelZ: ");
Serial.print(IMU.getAccelZ_mss(),6);
Serial.print("\t");
Serial.print("GyroX: ");
Serial.print(IMU.getGyroX_rads(),6);
Serial.print("\t");
Serial.print("GyroY: ");
Serial.print(IMU.getGyroY_rads(),6);
Serial.print("\t");
Serial.print("GyroZ: ");
Serial.print(IMU.getGyroZ_rads(),6);
Serial.print("\t");
Serial.print("MagX: ");
Serial.print(IMU.getMagX_uT(),6);
Serial.print("\t");
Serial.print("MagY: ");
Serial.print(IMU.getMagY_uT(),6);
Serial.print("\t");
Serial.print("MaZ: ");
Serial.print(IMU.getMagZ_uT(),6);
Serial.print("\t");
Serial.print("Temperature in C: ");
Serial.println(IMU.getTemperature_C(),6);
delay(100);
}