Pin isn't reading as HIGH when my sensor code is implemented

I’m learning to use the Adafruit LSM9DS0 ( and have cobbled this code together such that an LED will turn on when it detects motion on the accelerometer, specifically when the magnitude of the change is over a certain threshold (MOVE_THRESHOLD). I ran the code on an Uno and it worked great. Now that I’m trying to run it on a Mini Pro, hence needing pin 10 always on to power the sensor, it’s not working. When I comment out acceldata(), the pin is registering 5V like it should. Once acceldata() is on, the pin is not reading 5V, but 0V. I’m sure this is something obvious in acceldata() that I’m missing, but I’m still missing it. I’ve attached the code to this post.


_2016_08_08_9DOF_Test_1.ino (3.74 KB)

Please post the code here to avoid the need to download it. When you post it please select the code and add code tags to make it easier to copy.


UKHeliBob, my apologies. I had completely missed the code feature. Is this what you meant?

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_LSM9DS0.h>
#include <Adafruit_Sensor.h>

// i2c, calls the Flora 9DOF
Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0();
// You can also use software SPI
//Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(13, 12, 11, 10, 9);
// Or hardware SPI! In this case, only CS pins are passed in
//Adafruit_LSM9DS0 lsm = Adafruit_LSM9DS0(10, 9);

// mess with this number to adjust blinking
// lower number = more sensitive
#define MOVE_THRESHOLD 100

void setupSensor()
  // 1.) Set the accelerometer range
  // 2.) Set the magnetometer sensitivity

  // 3.) Setup the gyroscope

void setup() 
//Pin 10 to always be on to power the LSM9DS0 
//Pin 13 to turn on when a change in acceleration is detected

#ifndef ESP8266
  while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
  Serial.println("LSM raw read demo");
  // Try to initialise and warn if we couldn't detect the chip
  if (!lsm.begin())
    Serial.println("Oops ... unable to initialize the LSM9DS0. Check your wiring!");
    while (1);
  Serial.println("Found LSM9DS0 9DOF");

void loop() 
  //Pin 10 to always be on to power the LSM9DS0 
  digitalWrite(10, HIGH);
  //Takes the acceleration data, produces vector, detects change in vector to turn on pin 13 LED

void acceldata()
  Serial.print("Accel X: "); Serial.print((int)lsm.accelData.x); Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.accelData.y);       Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.accelData.z);     Serial.print(" ");
/*  Serial.print("Mag X: "); Serial.print((int)lsm.magData.x);     Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.magData.y);         Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.magData.z);       Serial.print(" ");
  Serial.print("Gyro X: "); Serial.print((int)lsm.gyroData.x);   Serial.print(" ");
  Serial.print("Y: "); Serial.print((int)lsm.gyroData.y);        Serial.print(" ");
  Serial.print("Z: "); Serial.println((int)lsm.gyroData.z);      Serial.println(" ");
  Serial.print("Temp: "); Serial.print((int)lsm.temperature);    Serial.println(" ");

  // Get the magnitude (length) of the 3 axis vector
  double storedVector = lsm.accelData.x*lsm.accelData.x;
  storedVector += lsm.accelData.y*lsm.accelData.y;
  storedVector += lsm.accelData.z*lsm.accelData.z;
  storedVector = sqrt(storedVector);
  Serial.print("Len: "); Serial.println(storedVector);
  // wait a bit
  // get new data!;
  double newVector = lsm.accelData.x*lsm.accelData.x;
  newVector += lsm.accelData.y*lsm.accelData.y;
  newVector += lsm.accelData.z*lsm.accelData.z;
  newVector = sqrt(newVector);
  Serial.print("New Len: "); Serial.println(newVector);

  // are we moving 
  if (abs(newVector - storedVector) > MOVE_THRESHOLD) {
    Serial.print("Delta_a: "); Serial.println(newVector - storedVector);
    digitalWrite(13, HIGH); 
    digitalWrite(13, LOW);

That's more like it.

How is the sensor wired to the Arduino ?

SCL is connected to A5, SDA is connected to A4, 3V to pin 10, GND to battery GND.

So you connect a 3V device just to 5V?

Everything I read said the accelerometer could take it without an issue.

Proserpia: Everything I read said the accelerometer could take it without an issue.

As Abe Lincoln said, you shouldn't believe everything you read on the WWW.

The normal breakout module has a voltage regulator on it and level shifters. The FLORA version is lacking both. So connecting 5V to any of it's lines is beyond the absolute maximum of 4,8V and far beyond the normal maximum voltage of 3,6V...

Okay, so it won't work with the sensor. That still doesn't explain why the pin isn't reading a voltage when the code is implemented.