Go Down

Topic: Accelerometer output unsteady (Read 873 times) previous topic - next topic


Hi folks.  I'm trying to set up a device that will display "UP" "DOWN" "LEFT" "RIGHT" on an LCD display, using an MMA7361 accelerometer as the input sensor.  I've got it all set up, and the initial code written, but I can seem to get a stable output from the accelerometer.  I'm using 2 analog inputs as the x and y inputs (not using the z axis) and digital outs to the LCD.  When the code is initially executed the accelerometer is sitting flat, and it takes baseline readings for x and y.  While the program is running however,  the x and y values are jumping al over the place, even while the sensor sits still.  I'm not sure if the problem lies in the accelerometer, or if there is some sort of interference being introduced somewhere within the controller. Here's the code:

Code: [Select]
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int xIn=A4;
int yIn=A3;
int xbl;
int ybl;
int sl=1;

void setup(){
 lcd.begin(20, 4);
 pinMode(xIn, INPUT);      
 pinMode(yIn, INPUT);
 pinMode(A5, INPUT);
 pinMode(sl, OUTPUT);
 digitalWrite(sl, HIGH);
 xbl = analogRead(xIn);
 ybl = analogRead(yIn);

void loop(){
 int xPos=analogRead(xIn);
 int yPos=analogRead(yIn);
 int offset=65;
  if (xPos>xbl+offset) {
  if (xPos<xbl-offset) {
  if (yPos>ybl+offset) {
  if (yPos<ybl-offset) {
  //Displays readings to Serial Monitor
   Serial.print("xbl ");
   Serial.print(" X: ");  
   Serial.print(" ybl ");
   Serial.print(" Y: ");

Has anybody ever come across an issue like this.  I'm pretty new to Arduino, so if I left any info out just let me know. Thanks.


Alright... got the problem soved, but still don't quite understand.  The accelerometer requires a high on the S (Sleep) pin in order to operate. I was using pin 1 (digital out) to provide that voltage, and applied it in setup().  For some reason this was messing things up.  I took it off pin 1, and am now just applying a constant 5v from the power supply board I'm using. Works fine, everthing steadied right out.


I had the same Accelerometer and same problem. The Accelerometer is very simple to use and good for beginners. I had the same problem when I hooked it up to the breadboard. But then i got much better results when I actually soldered it to some wires. I think this is because conductivity increase when you solder the wires to it plus they stop disconnecting.

Here is some reference, I suggest connecting it with special wires or soldering it:

I also used this tutorial but it's in French. Use Google Translate to translate it into English:

Hope this helps!

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