New York
Offline
Edison Member
Karma: 1
Posts: 1023
E != m*c^2
|
 |
« on: February 25, 2009, 09:04:21 pm » |
I made a little project using the ADX330 accelerometer and my arduino... I know its simple and its been done before (which I found out to my dismay AFTER i made this) but I am quite proud cause I am only a few weeks into the arduino and I made this code from scratch - all it took was the consumption of 10 cups of coffee and a few head scratching moments...  anyway, enjoy:
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #1 on: February 26, 2009, 04:13:28 am » |
Well done. I hope you enjoyed getting that working. What do you have planned for your next project?
|
|
|
|
|
Logged
|
|
|
|
|
|
|
New York
Offline
Edison Member
Karma: 1
Posts: 1023
E != m*c^2
|
 |
« Reply #3 on: February 26, 2009, 03:51:33 pm » |
thx guys, il post the code when i get home... i took a look at 3d ruby... and it seems pretty awesome, il play around with that a little, but my next project is a lillypad + accelerometer robotic hand cntrol project... im still working on the code behind it but its actually fairly simple... il let u knw when im done ;D
|
|
|
|
« Last Edit: February 26, 2009, 03:51:49 pm by jezuz »
|
Logged
|
|
|
|
|
New York
Offline
Edison Member
Karma: 1
Posts: 1023
E != m*c^2
|
 |
« Reply #4 on: February 26, 2009, 08:12:30 pm » |
iight guys here is the code...
int groundpin = 18; // analog input pin 4 int powerpin = 19; // analog input pin 5 int xpin = 3; // x-axis of the accelerometer int ypin = 2; // y-axis int zpin = 1; // z-axis (only on 3-axis models) long xy_max = 470; long xy_min = 550;
int forwardPin = 9; int backPin = 10; int leftPin = 11; int rightPin = 12; int centerPin = 8;
long x = 0; long y = 0;
void setup() { Serial.begin(9600); pinMode(forwardPin, OUTPUT); pinMode(backPin, OUTPUT); pinMode(leftPin, OUTPUT); pinMode(rightPin, OUTPUT); pinMode(groundpin, OUTPUT); pinMode(powerpin, OUTPUT); digitalWrite(groundpin, LOW); digitalWrite(powerpin, HIGH); }
void loop() {
x = analogRead(xpin); y = analogRead(ypin); digitalWrite(centerPin, LOW);
if (y < xy_max) { //backwards digitalWrite(backPin, HIGH);
Serial.println("The arduino is moving(tilted) backwards"); } else if (y >= xy_max){ digitalWrite(backPin, LOW); } if (y > xy_min) { //forwards
digitalWrite(forwardPin, HIGH);
Serial.println("The arduino is moving(tilted) forwards");
} else if (y <= xy_min){ digitalWrite(forwardPin, LOW); } if (x > xy_min) { //left
digitalWrite(leftPin, HIGH);
Serial.println("The arduino is moving(tilted) left");
} else if (x <= xy_min){ digitalWrite(leftPin, LOW); } if (x < xy_max) { //right
digitalWrite(rightPin, HIGH);
Serial.println("The arduino is moving(tilted) right"); } else if (x >= xy_max){ digitalWrite(rightPin, LOW);
} if (y >= xy_max && y <= xy_min && x <= xy_min && x >= xy_max) { // nothing digitalWrite(forwardPin, LOW); digitalWrite(backPin, LOW); digitalWrite(centerPin, HIGH); digitalWrite(leftPin, LOW); digitalWrite(rightPin, LOW); Serial.println("The arduino is currently not moving(tilted) in any direction"); } }
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #5 on: February 27, 2009, 03:46:19 am » |
Thanks for sharing.
Here are some tips that may help you if you add to this sketch
You can simplify the position checks, for example you can do the y position check as follows:
if (y < xy_max) { //backwards digitalWrite(backPin, HIGH); Serial.println("The arduino is moving(tilted) backwards"); } else{ digitalWrite(backPin, LOW); }
This works because if y is not less than xy_max it must be greater than or equal , so you don't need to do that check
If you just wanted to control the led without the serial message you can simplify further. The following code will set the pin HIGH when x is less than xy_max and low otherwise
digitalWrite(backPin, (x<xy_max) );
the expression (x<xy_max) evaluates to true (the same as HIGH) if x is less than xy_max and false (the same as LOW) otherwise.
Have fun!
|
|
|
|
« Last Edit: February 27, 2009, 03:46:39 am by mem »
|
Logged
|
|
|
|
|
New York
Offline
Edison Member
Karma: 1
Posts: 1023
E != m*c^2
|
 |
« Reply #6 on: February 27, 2009, 05:09:55 pm » |
ure absolutely right, i just did that so it was easier to understand for me (i was doing it late, and when im tired i always try to write out code completely so that i understand it better, and thus dont make any stupid mistakes) but thx:) and il have some pix of the robotic arm up later tonight if ure interested 
|
|
|
|
|
Logged
|
|
|
|
|
London
Offline
Faraday Member
Karma: 6
Posts: 6226
Have fun!
|
 |
« Reply #7 on: February 27, 2009, 05:23:30 pm » |
Looking forward to seeing the pictures 
|
|
|
|
|
Logged
|
|
|
|
|
New York
Offline
Edison Member
Karma: 1
Posts: 1023
E != m*c^2
|
 |
« Reply #8 on: March 03, 2009, 10:20:35 pm » |
the project has been put on hold due to difficulties with the damn robotic arm's motors... and im quite busy with schoolwork at the time... il be sure to get right back ontop of the work as soon as i can... 
|
|
|
|
|
Logged
|
|
|
|
|
New York
Offline
Edison Member
Karma: 1
Posts: 1023
E != m*c^2
|
 |
« Reply #9 on: March 25, 2009, 07:57:46 pm » |
ok, so i pcb'd the project..finally... but i was out of the good wires so i ended up just putting some crappy short ones so that atleast i could test if it sorta works, and so it would look valid... here are the picks: http://img410.imageshack.us/gal.php?g=dscn0994.jpg
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 1
Arduino rocks
|
 |
« Reply #10 on: July 05, 2010, 02:11:57 am » |
hey I am using Triple Axis Accelerometer Breakout - MMA7260Q. I dont understand the behavior of accelerometer. From where can I know xymin and xymax ? I tried to figure it out by myself. COuldnt do it.. please help if someone knows..
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 1
Arduino rocks
|
 |
« Reply #11 on: July 27, 2010, 10:29:50 am » |
Nice :-)
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Jr. Member
Karma: 0
Posts: 71
Arduino rocks
|
 |
« Reply #12 on: July 30, 2010, 03:38:58 pm » |
Nice project!  I'm going to start working with accelerometers too with the wii nunchuck. I have the connector from SparkFun
|
|
|
|
|
Logged
|
|
|
|
|
New York
Offline
Edison Member
Karma: 1
Posts: 1023
E != m*c^2
|
 |
« Reply #13 on: July 31, 2010, 12:19:03 pm » |
Thanks guys. Blast from the past, though (this thing must have been on page 30 by now). I'm going to start working with accelerometers too with the wii nunchuck. I have the connector from SparkFun I tried my luck with the wii nunchuck and it failed me miserably (I didn't use the premade connector tho, so perhaps I mucked up when resoldering the breakout wires :'(). If you get yours working, I'd enjoy seeing it in action. 
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Newbie
Karma: 0
Posts: 20
Arduino rocks
|
 |
« Reply #14 on: August 22, 2010, 05:14:14 pm » |
hey I am using Triple Axis Accelerometer Breakout - MMA7260Q. I dont understand the behavior of accelerometer. From where can I know xymin and xymax ? I tried to figure it out by myself. COuldnt do it.. please help if someone knows.. Hello, freescale published a nice application notes ( http://www.freescale.com/files/sensors/doc/app_note/AN3107.pdf ) I guess it can help you. regards, reha
|
|
|
|
|
Logged
|
|
|
|
|
|