Go Down

Topic: accelerometer problems (Read 728 times) previous topic - next topic

ars

Hey,
Im using an adxl335 accelerometer, im using an old version of arduino which does not have a 3.3V pin so im using an external 3V supply to power my sensor.The problem is that when i run the program to light up an led when a tilt is detected, the led lights up, but the accelerometer readings gets boosted whenever the led lights up and gets lowered whenever the led goes low.I get the output:
accelerations are x, y, z : 396 391 483//when in stable position and led is ON
accelerations are x, y, z : 396 391 483
accelerations are x, y, z : 396 391 483
accelerations are x, y, z : 396 391 483
accelerations are x, y, z : 351 348 430//it gets lowered when the led turns off while it is still in stable mode
accelerations are x, y, z : 351 348 430
accelerations are x, y, z : 351 348 430
Please help:
Code: [Select]

int x,y,z;


void setup()
{
  Serial.begin(9600);      // sets the serial port to 9600
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
pinMode(3,OUTPUT);
}

void loop()
{
  x = analogRead(0);       // read analog input pin 0
  y = analogRead(1);       // read analog input pin 1
  z = analogRead(2);       // read analog input pin 1
  Serial.print("accelerations are x, y, z: ");
  Serial.print(x, DEC);    // print the acceleration in the X axis
  Serial.print(" ");       // prints a space between the numbers
  Serial.print(y, DEC);    // print the acceleration in the Y axis
  Serial.print(" ");       // prints a space between the numbers
  Serial.println(z, DEC);  // print the acceleration in the Z axis
if( y > 290 && z < 340)//up
{
   digitalWrite(7,HIGH);
}
else digitalWrite(7,LOW);

if( x<270 && y<270 && z<340)//down
{
   digitalWrite(6,HIGH);
}
else digitalWrite(6,LOW);
if ( x>260 && x<286 && y<290 && y>240 && z<350 && z>315)//centre
{
   digitalWrite(5,HIGH);
}
else digitalWrite(5,LOW);
if(x>298 && y>282 && z>310)//right
{
   digitalWrite(4,HIGH);
}
   else digitalWrite(4,LOW);
   if(x<235 && y<275 && z<318)//left
   {
     digitalWrite(3,HIGH);
   }
   else digitalWrite(3,LOW);
   
  delay(600);              // wait 100ms for next reading
}

liudr

I don't know if your problem comes from your code or your circuit so why not showing both? I suspect you didn't have a correct circuit for the LED, which affects the supply voltage of arduino large enough to affect you but without a circuit picture I can only suspect.

ars

I wired my leds from digital 7,6,5,4,3 to all the led's +ve pin and connected the ground of all leds together to arduino ground.Then for my accelerometer i wired the 5V from my arduino to 3 Si diodes with voltage taken accross a 1K resistor(this forms the 3.3V to power my accelerometer) connected to 3.3V pin of the sensor, ground of sensor to arduino ground and the X-acc,Y-acc,Z-acc pins of the sensor to analog 0,1,2 pins of arduino.......!!Please help.

liudr

This description spells a lot of trouble. If you had a newer version of arduino, you would have asked a question:"why is my arduino restarting all the time and USB connect/disconnect sound kept playing?"

Please stop what you're doing. You're hurting your arduino. Take a good picture of your connections and we can give you corrections using the picture and your description.

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!

Arduino
via Egeo 16
Torino, 10131
Italy