Go Down

Topic: How to reduce sensor fluctuations? (Read 2013 times) previous topic - next topic


Hi Everyone!!

i have been working on a project to get my arduino mega to read and display how level it is. i have been using an SCA100t Inclinometer to get the level readings via SPI and using the analog functions. the data sheet is located at:


after a lot of work and some help from the forums (love these forums. they are so active and helpful!) i finaly got the SPI to work. my current issue is that my readings are all over the place (+/- 8! and when i was using the analog readings it was even worse!). This is translating into a half degree or more of fluctuation!

i have tried two of SCA100t's on two different arduinos. i have tried hooking the chip up with the recommended capacitors and resistors, and without. i have tried using only the USB power, and i have tried using a powersupply. the only thing that i havent tried that i can think of is powering the sensor with a different power source than the arduino is using, but im not even sure that would work.

does anyone have any other ideas on how to remove this circuit noise?

this is the current code that im using just incase, though im not having any issues with the code:
Code: [Select]
get the SPI clock to work.
read the x and y information.

sensor attached to pins 50-53:

50:Data IN
51:Data OUT
53:Chip select
52:Serial Clock

// inslude the SPI library:
#include <SPI.h>

// Set pins
const int dataINPin = 50;     //MISO
const int dataOUTPin = 51;    //MOSI
const int chipSelectPin = 53;//Chip Select Pin
const int serialClockPin = 52;//CSK

//!!!Sets commands according to spec sheet to access memory register addresses
//!!!Commands are 8 bits or one byte
const byte MEAS  = B00000000; //Measure mode (normal operation mode after power on)
const byte RWTR  = B00001000; //Read and write temperature data register, ONLY WRITE COMMAND, note currently in use
const byte RDSR  = B00001010; //Read status register
const byte RLOAD = B00001011; //Reload NV data to memory output register
const byte STX   = B00001110; //Activate Self test for X-channel
const byte STY   = B00001111; //Activate Self test for Y-channel
const byte RDAX  = B00010000; //Read X-channel acceleration through SPI
const byte RDAY  = B00010001; //Read Y-channel acceleration through SPI

void setup() {
// initialize SPI:
// set the input & output:
pinMode (dataINPin, INPUT);
pinMode (dataOUTPin, OUTPUT);
pinMode (chipSelectPin, OUTPUT);
pinMode (serialClockPin, OUTPUT);

//!!!Allow self-test to initialize on start-up

void loop() {

    //!!!assigns integer to store X axis value, BIN tells function that variable is in binary
    int xAxisData = readCommand(RDAX);

Serial.println("X Axis: ");

    //!!!assigns integer to store Y axis value
    int yAxisData = readCommand(RDAY);

Serial.println("Y Axis: ");

for(int i = 0;i<90;i++) {


word readCommand(byte Command) {

    byte inByte = 0;
word result = 0;   // result to return

// take the chip select high to select the device:
digitalWrite(chipSelectPin, LOW);

    //!!!SCAT datasheet specifies a 150 microsecond pause to get correct reading

    //!!! Send command to slave(sensor):

    //!!!Reads output by using measure command
    result = SPI.transfer(MEAS);

    // shift the first byte left, then get the second byte:
    result = result << 8;
    inByte = SPI.transfer(MEAS);

    // combine the byte you just got with the previous one:
    result = result | inByte;

    // Result is in 11 bit word format with MSB first to shift ouput to 11 important bits
    result = result >> 5;

    // take the chip select high to de-select:
    digitalWrite(chipSelectPin, HIGH);

    // return the result:



From the data sheet you linked to:


Ratiometric output means that the zero offset point and sensitivity of the sensor are proportional to
the supply voltage. If the SCA100T supply voltage is fluctuating the SCA100T output will also vary.
When the same reference voltage for both the SCA100T sensor and the measuring part (A/Dconverter)
is used, the error caused by reference voltage variation is automatically compensated

I haven't followed through your use to see whether voltage compensation is an issue here but it's certainly something to check for, and to start with I'd try giving the inclinometer a rock steady supply voltage (not one provided via the Arduino's regulator) and see if that made any difference.
I only provide help via the forum - please do not contact me for private consultancy.


I had the same problem, there is an example of a smoothing function under analog inputs in Arduino 1.+, and on the Arduino.cc references page.
I have found a post on the old forum that says to use

Code: [Select]
/light1 is of type float)

light1 = light1 * 0.9 + float(analogRead(light1Pin)) * 0.1;

works well for my application because the leveling legs on my 5th wheel move very slowly, and I get a nice steady degree readout.
Looks like we may be doing somewhat similar projects.
Einstein once said you don't really understand anything until you can explain it to your Grandmother


Similar thread: http://arduino.cc/forum/index.php/topic,112730.0/topicseen.html
I agree, with other participants, in case when sampling rate don't need to be fast, low pass filtering (running average is the simplest one) is the best solution.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131