Accelerometer + Temperature

Adafruit ADXL343 + ADT7410 Sensor FeatherWing

  • Analog Devices ADXL343 accelerometer
  • ADT7410 16-bit temperature sensor

Both acceleration and temperature are reported over I2C.   The Analog Devices ADXL343 has three axes of measurements: X, Y, and Z.   You can set the sensitivity level to either +-2g, +-4g, +-8g or +-16g (lower = better resolution for slow motion). User-selectable data rate (0.1 .. 3200 Hz)  

mn698
  • +/- 2 g (10-bit data, or +/- 512)
  • +/- 4 g (11-bit data, or +/- 1024)
  • +/- 8g (12-bit data, or +/- 2048)
  • +/- 16 g (13-bit data, or +/- 4096)

Most triaxial IEPE accelerometers are limited to measuring 4 kHz signals.  

Note that magnetic mount of accelerometer will limit measurement of vibration to 2.0 kHz.   Adhesive mounting limited to measuring 2.5 to 5.0 kHz, and stud mounting can achieve > 6.0 kHz.  

 

Resources

  • I2C or SPI (I2C recommended)
  • ADT7410 uses I2C address 0x48 by default
  • ADXL343 uses I2C address 0x53 by default

 

AF Tutorial

AF ADXL343 guide

Adafruit Unified Sensor driver

 


/*
  Adafruit ADXL343 + ADT7410 Sensor FeatherWing
  Product #4147

  
*/

// M0  (Feather M0)
// Make sure Arduino IDE board = "Adafruit Feather M0"
const byte pin_LED = 13;

//////////////////////////////////////////////////////////////////////////////
// 300000 ms = 5 min
// 60000 ms = 1 min
// 10000 ms = 10 sec = 0.1 Hz 
// 1000 ms = 1 sec = 1 Hz
// 100 ms = 0.1 sec = 10 Hz
// 10 ms = 0.01 sec = 100 Hz
const unsigned long timerInterval = 5000;  
unsigned long timerLast = 0;  // timer
//////////////////////////////////////////////////////////////////////////////
// Adafruit ADXL343 + ADT7410 Sensor FeatherWing
//
//  Install the "Adafruit ADXL343" and "Adafruit_ADT7410" libraries
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_ADT7410.h"
#include <Adafruit_ADXL343.h>
float tempF = 0.0;
struct AccelReadingAvg {
  float x;
  float y;
  float z;
};
AccelReadingAvg AccelMax = {0.0, 0.0, 0.0};
// Create the ADT7410 temperature sensor object
Adafruit_ADT7410 TempSensor = Adafruit_ADT7410();
// Create the ADXL343 accelerometer sensor object
const byte unique_id = 12345;
Adafruit_ADXL343 accel = Adafruit_ADXL343(unique_id);
//////////////////////////////////////////////////////////////////////////////


void setup() {  
  Serial.begin(9600);
  while (!Serial) {
    delay(1);
  }

  //////////////////////////////////////////////////////////////////////////////
  // Adafruit ADXL343 + ADT7410 Sensor FeatherWing
  /* Initialise the ADXL343 */
  if(!accel.begin()) {
    Serial.println("ERROR - no ADXL343 detected accelerometer");
    while(1);
  }  
  // Set the accelerometer range
  accel.setRange(ADXL343_RANGE_16_G);
  // accel.setRange(ADXL343_RANGE_8_G);
  // accel.setRange(ADXL343_RANGE_4_G);
  // accel.setRange(ADXL343_RANGE_2_G);
  accel.printSensorDetails();
  Serial.println("");
  if (! TempSensor.begin())   {
    Serial.println("ERROR - temp sensor ADT7410 not found");
    while (1);
  }
  // TempSensor takes 250 ms to get first readings
  delay(250);

  Serial.println("Setup complete\n");
} // setup()


void loop() {

  // Read the accelerometer and collect the maximum value
  sensors_event_t event;
  accel.getEvent(&event); 
  if (fabs(event.acceleration.x) > fabs(AccelMax.x)) AccelMax.x = event.acceleration.x;
  if (fabs(event.acceleration.y) > fabs(AccelMax.y)) AccelMax.y = event.acceleration.y;
  if (fabs(event.acceleration.z) > fabs(AccelMax.z)) AccelMax.z = event.acceleration.z;
    
  if (timerLast > millis())  timerLast = millis();
  if ((millis() - timerLast) > timerInterval) {
    // toggle LED to show write activity
    digitalWrite(pin_LED, HIGH);
    Serial.print("X: "); Serial.print(AccelMax.x,1); Serial.print("  ");
    Serial.print("Y: "); Serial.print(AccelMax.y,1); Serial.print("  ");
    Serial.print("Z: "); Serial.print(AccelMax.z,1); Serial.print("  ");
    Serial.print("m/s^2  ");
    Serial.print(event.timestamp);
    Serial.println(" ms");
    digitalWrite(pin_LED, LOW);
    AccelMax.x = 0.0; AccelMax.y = 0.0; AccelMax.z = 0.0;
    // Read the temperature
    float tempC = TempSensor.readTempC();
    tempF = (tempC * 9.0/5.0)+32.0;
    Serial.print("Temperature: "); Serial.print(tempF,1); Serial.println(" F\n");
    timerLast = millis();
  }
  
  // The yield() function allows ESP8266 microcontroller to run a 
  // number of utility functions in the background, without causing 
  // the ESP8266 to crash or reset. Include it within any 
  // while() + digitalRead() and other loops;
  yield();
  
} // loop()


void blinkLED(byte ledPIN){
  //  consumes 300 ms.
  for(int i = 5; i>0; i--){
    digitalWrite(ledPIN, HIGH);
    delay(30);
    digitalWrite(ledPIN, LOW);
    delay(30);
  }    
} // blinkLED()

More AF FeatherWing products from Adafruit and from Particle

 


Do you need help developing or customizing a IoT product for your needs?   Send me an email requesting a free one hour phone / web share consultation.  

 

The information presented on this website is for the author's use only.   Use of this information by anyone other than the author is offered as guidelines and non-professional advice only.   No liability is assumed by the author or this web site.