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

I’m learning to use the Adafruit LSM9DS0 (https://www.adafruit.com/products/2020) 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.

Thanks!

_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.

(deleted)

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
  lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_2G);
  //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_4G);
  //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_6G);
  //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_8G);
  //lsm.setupAccel(lsm.LSM9DS0_ACCELRANGE_16G);
  
  // 2.) Set the magnetometer sensitivity
  lsm.setupMag(lsm.LSM9DS0_MAGGAIN_2GAUSS);
  //lsm.setupMag(lsm.LSM9DS0_MAGGAIN_4GAUSS);
  //lsm.setupMag(lsm.LSM9DS0_MAGGAIN_8GAUSS);
  //lsm.setupMag(lsm.LSM9DS0_MAGGAIN_12GAUSS);

  // 3.) Setup the gyroscope
  lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_245DPS);
  //lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_500DPS);
  //lsm.setupGyro(lsm.LSM9DS0_GYROSCALE_2000DPS);
}

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


#ifndef ESP8266
  while (!Serial);     // will pause Zero, Leonardo, etc until serial console opens
#endif
  Serial.begin(9600);
  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");
  Serial.println("");
  Serial.println("");
}

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
  acceldata();
}

void acceldata()
{
  lsm.read();
  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(" ");
*/
  delay(1000);

  // Get the magnitude (length) of the 3 axis vector
  // http://en.wikipedia.org/wiki/Euclidean_vector#Length
  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
  delay(50);
  
  // get new data!
  lsm.read();
  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.println("Twinkle!");
    Serial.print("Delta_a: "); Serial.println(newVector - storedVector);
    digitalWrite(13, HIGH); 
  }
  else
  {
    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.