Pages: [1]   Go Down
Author Topic: Adding an Adxl to my board  (Read 1369 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a couple of 'things' hooked up to a number of pins on my arduino uno. I have hooked up my adxl 335 accelerometer to the analog pins on the arduino before, and it worked. I was wondering if there was a different place to hook up my adxl connetions without using the pins i originally had  to use.  i have been trying different connections, but haven't hit the right combo yet. 

Pins in use on arduino:
3.3V
5V
GND, both of them
A0
A1

My original adxl connections are
Arduino- adxl
A0-self-test
A1-z axis
A2-y axis
A3-x axis
A4-ground
A5-vcc
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1328
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


  The best thing to do is use a proto board or something to get more connections to your 3.3v and Gnd. You will need more connections to Gnd and 5V if you want to add Leds.  What I am speaking of is a parallel connection.  With GND for example, you come from the GND pin and with board you can have a copper strip that would allow more connections to be connected to GND.

 If you do the above you will only need A1-z axis, A2-y axis, A3-x axis, and self test is optional.



Mark
Logged


Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1328
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


  Yes, a breadboard has parallel connections that can be used for multiple pwr and GND. You are most likely on the right track.


Mark
Logged


Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You will need analog pins to sense the accelerometer. Digital pins only sense on and off. I suggest you get a small breadboard. Pass power and ground to the breadboard with jumper wires. Breadboards have busses, columns of holes that are connected. You jump power to one of those holes and the rest on the same column are all connected to power.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My accelerometer has been in a breadboard.  The power is in the Vin pin, and the gnd is in the digital side.  Is that OK? I have my x,y,and z in analog pins now.  However, now my x axis is showing a reading of 0, regardless.  I have two codes- one just for the readouts, and the other with an alarm. I was trying to get the plain code to work, so i could adapt it for my project, but it wasn't working. My alarm code, however, I have gotten to start working properly, so i will just use that for the time being.
The alarm code takes the difference (movement) of the adxls axis, and then prints low (normal) or high (moving), and lights the LED when it is on high. 

Continuing the matter, i have a sensor system hooked up and running.  What it does is if the two sensor values are above the alarmValue, it lights the LED.  I am trying to add the adxl, so that when the two sensor values are above the alarmValue, and the adxl is on HIGH, the LED will light up.  I'm not sure how to add the LED system in, because it is not based on an alarmValue. 

Two sensor code
Code:
if (corda > alarmValue  && toad > alarmValue)
  {
    digitalWrite (ledPin, HIGH); // turn the LED on
  }

  else
  {
    digitalWrite (ledPin, LOW);
  }

How i tried to modify it...
Code:
//    if ((ybase-ypin) >= 100) //makes the high, low signals
  if ((abs(yy-ybase) >= diff) && (abs(zz-zbase)>= diff))
 {
  digitalWrite(xbackward, HIGH);
  Serial.print("high= ybase \t");
  Serial.print(yy-ybase);
  //Serial.print(  analogRead(ybase)-ypin);
   Serial.print("cc \t");
  //Serial.print(abs(zbase-zpin));
 }
 else
 {
   digitalWrite(xbackward, LOW);
  Serial.print("low \t"); 
 };
 
if (corda > alarmValue  && toad > alarmValue && (xbackward, HIGH)) 
  {
    digitalWrite (ledPin, HIGH); // turn the LED on
  }

  else
  {
    digitalWrite (ledPin, LOW);
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1328
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


  You can use any of the GND pins on the Arduino they are all connected together. For power to the adxl 335
you should connect 3.3v pin on the Arduino.

 Here is Sparkfun's page on that unit. http://www.sparkfun.com/products/9269

Here is a builder example found at sparkfun's page http://bildr.org/2011/04/sensing-orientation-with-the-adxl335-arduino/

I would like to help you with your code too but, you need to post all of it so that I can figure out how defined "xbackward" and things like that.


Mark
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Mark, I wasn't sure if i should post all my code.  I have the adxl powered and working correctly.  
Here is the full adxl code, and it is giving me the proper readings.  

Code:
const int xpin = A4;                 
const int ypin = A3;                 
const int zpin = A2;                 
int ledPin = 13;
float alarmValue; 
int xforward = 6;
int xbackward = 7;
int ledState = LOW;
int xbase = 467;
int ybase = 490;
int zbase = 540;
int diff = 30;

int xx;
int yy;
int zz;

void setup()
{
 
  Serial.begin(9600);
  Serial.println("Ready");
   alarmValue = 25;
}

void loop()
{
 
 
  Serial.print(analogRead(xpin));
    Serial.print("x \t");
  yy = analogRead(ypin);
  Serial.print(analogRead(ypin));
    Serial.print("y \t");
  Serial.print(analogRead(zpin));
  zz = analogRead(zpin);
  Serial.println("z");
    delay(1000);
      if ((abs(yy-ybase) >= diff) && (abs(zz-zbase)>= diff))
 {
  digitalWrite(xbackward, HIGH);
  Serial.print("high= ybase \t");
  Serial.print(yy-ybase);
     Serial.print("cc \t");
   digitalWrite (ledPin, HIGH);
 }
 else
 {
   digitalWrite(xbackward, LOW);
  Serial.print("low \t"); 
  digitalWrite (ledPin, LOW);
 };
}
« Last Edit: July 12, 2011, 01:21:16 pm by uink » Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Most of your commented codes are wrong. Please remove them. There's no point in keeping them. If you power the accelerometer with 3.3V, did you use 3.3V as analog reference voltage? No, according to your setup(). So your base value is not near 500 but near 338. That is the first thing I noticed. If you set the accelerometer flat, what do you get for x and y? 338 or near 500?

What do you to accomplish? You said nothing about it. From what I know, you can only sustain acceleration with circular motion. So your acceleration goes above alarm only for a short moment before you need to decelerate.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am not using the 3.3V, i am using Vin.  I simply want a sensor to alert me if there is any movement.  if there is, just light a LED. 
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am not using the 3.3V, i am using Vin.  I simply want a sensor to alert me if there is any movement.  if there is, just light a LED. 

Vin is supposed to be connected to the positive lead on a battery or an ac adapter (wall wart), thus the 'in'. It's not supposed to supply power to your accelerometer. Please post your project pic.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Vin is supposed to be connected to the positive lead on a battery or an ac adapter (wall wart), thus the 'in'. It's not supposed to supply power to your accelerometer. Please post your project pic.

I am new to arduino and electronics, so i am learning as i go.  I will change the power to 3.3V.  I don't have a camera to post pictures.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 72
Posts: 7171
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I am new to arduino and electronics, so i am learning as i go.  I will change the power to 3.3V.  I don't have a camera to post pictures.

You will also need to connect 3.3V to aref pin on arduino and run the following in setup so your accelerometer reading (0-3.3V range) will still be mapped to (0-1023) and the mid points will be around 500.

analogReference(EXTERNAL);
Logged


Pages: [1]   Go Up
Jump to: