The ADXL335 is a small, thin, low power, complete 3-axis accel- erometer with signal conditioned voltage outputs.
The product measures acceleration with a minimum full-scale range of ±3 g.
It can measure the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion, shock, or vibration.
Here there is a collection of examples for connect the ADXL335 with Arduino
/* ADXL335 Simple Test*/ void setup() { Serial.begin(9600); } void loop() { Serial.print("X: "); Serial.print(analogRead(0)); Serial.print("\tY: "); Serial.print(analogRead(1)); Serial.print("\tZ: "); Serial.println(analogRead(2)); delay(500); }
/* ****Wand**** This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <Midi.h> /* Pin for 74HC959 connected to Display 7-seg */ #define LATCH 7 #define CLOCK 6 #define DATA 5 Midi midi(Serial); // Midi int old_note; // stores the old note int old_note_octave; // stores the old note_octave boolean note_on=false; boolean note_octave_on=false; int acc_x; int acc_y; void setup() { midi.begin(1,31250); // init Midi analogReference(EXTERNAL); // Analog Reference to 3.3V /* Set pin for Display*/ pinMode(LATCH,OUTPUT); pinMode(CLOCK,OUTPUT); pinMode(DATA,OUTPUT); } void loop() { /* Read Accelerometer */ acc_x = analogRead(0); // Note acc_y = analogRead(1) *8; // Pitch acc_x=map(acc_x,400,610,60,48); // Map min=400 e max=610 accelerometer scale // to 60 - 48 [C,Db,D,Eb,E,F,Gb,G,Ab,A,Bb,B] print_display(acc_x); // print current note on Display delayMicroseconds(500); /* Button Note */ if(digitalRead(3)==LOW) { // if the button note is pressed if(!note_on) { // if the note is not active midi.sendNoteOn(1,acc_x,127); // play note old_note=acc_x; // update current note value note_on=true; // note is played delayMicroseconds(500); } } else if (note_on) { // If the button is released and note is played midi.sendNoteOff(1,old_note,0); // stop note note_on=false; // note off delayMicroseconds(500); } /* Button Note Octave */ if(digitalRead(4)==LOW) { // if the button note_ocatve is pressed if(!note_octave_on) { // if the note_octave is not active midi.sendNoteOn(1,acc_x+12,127); // play note_octave old_note_octave=acc_x+12; // update current note_octave value note_octave_on=true; // note_octave is played delayMicroseconds(500); } } else if (note_octave_on) { // If the button is released and note is played midi.sendNoteOff(1,old_note_octave,0); // stop note note_octave_on=false; // note off delayMicroseconds(500); } /* Change the pitch value with the Y acceleration */ midi.sendPitchChange(acc_y); } /* Function to print the display the current note */ void print_display(int note) { digitalWrite(LATCH,LOW); // active LATCH if(note==48 || note==60 ) { shiftOut(DATA,CLOCK,LSBFIRST,0x4e); // C shiftOut(DATA,CLOCK,LSBFIRST,0x00); // } else if(note==49) { shiftOut(DATA,CLOCK,LSBFIRST,0x7e); // Db shiftOut(DATA,CLOCK,LSBFIRST,0x1f); // } else if(note==50) { shiftOut(DATA,CLOCK,LSBFIRST,0x7e); // D shiftOut(DATA,CLOCK,LSBFIRST,0x00); // }else if(note==51) { shiftOut(DATA,CLOCK,LSBFIRST,0x4f); // Eb shiftOut(DATA,CLOCK,LSBFIRST,0x1f); // }else if(note==52) { shiftOut(DATA,CLOCK,LSBFIRST,0x4f); // E shiftOut(DATA,CLOCK,LSBFIRST,0x00); // }else if(note==53) { shiftOut(DATA,CLOCK,LSBFIRST,0x47); // F shiftOut(DATA,CLOCK,LSBFIRST,0x00); // }else if(note==54) { shiftOut(DATA,CLOCK,LSBFIRST,0x5f); // Gb shiftOut(DATA,CLOCK,LSBFIRST,0x1f); // }else if(note==55) { shiftOut(DATA,CLOCK,LSBFIRST,0x5f); // G shiftOut(DATA,CLOCK,LSBFIRST,0x00); // }else if(note==56) { shiftOut(DATA,CLOCK,LSBFIRST,0x77); // Ab shiftOut(DATA,CLOCK,LSBFIRST,0x1f); // }else if(note==57) { shiftOut(DATA,CLOCK,LSBFIRST,0x77); // A shiftOut(DATA,CLOCK,LSBFIRST,0x00); // }else if(note==58) { shiftOut(DATA,CLOCK,LSBFIRST,0x7f); // Bb shiftOut(DATA,CLOCK,LSBFIRST,0x1f); // }else if(note==59) { shiftOut(DATA,CLOCK,LSBFIRST,0x7f); // B shiftOut(DATA,CLOCK,LSBFIRST,0x00); // } digitalWrite(LATCH,HIGH); // disable LATCH }