Ler um ADXL3xx acelerômetro - Acelerômetro Arduíno
Autor: Maria e Deivson | Publicado: 2012-01-24T20:20:00-03:00




ADXL3xx&nbsp;Acelerómetro

Este tutorial mostra como ler um Analog Devices&nbsp;ADXL3xx&nbsp;série (por exemplo,&nbsp;ADXL320&nbsp;,&nbsp;ADXL321&nbsp;,&nbsp;ADXL322&nbsp;,ADXL330&nbsp;)&nbsp;acelerômetro&nbsp;e comunicar a aceleração para o computador pessoal.






Circuito
Usa o acelerômetro amperagem muito pouco, para que possa ser conectado ao seu Arduino e executar diretamente a partir da saída dos pinos digitais do Arduino de saída.&nbsp;Para fazer isso, você usará três dos pinos de entrada analógica como digital I / O pins, de poder e de solo para o acelerômetro, e para o pino de auto-teste.&nbsp;Você vai usar as outras três entradas analógicas para ler saídas analógicas do acclerometer é.







imagem desenvolvido utilizando&nbsp;Fritzing&nbsp;.&nbsp;Para mais exemplos de circuito, consulte a&nbsp;página do projeto Fritzing








Código








/*&nbsp;http://www.arduino.cc/en/Tutorial/ADXL3xx&nbsp;The circuit:&nbsp;analog 0: accelerometer self test&nbsp;analog 1: z-axis&nbsp;analog 2: y-axis&nbsp;analog 3: x-axis&nbsp;analog 4: ground&nbsp;analog 5: vcc&nbsp;created 2 Jul 2008&nbsp;by David A. Mellis&nbsp;modified 30 Aug 2011&nbsp;by Tom Igoe&nbsp;This example code is in the public domain.*///&nbsp;
essas constantes descrever os pinos.&nbsp;Eles não vão mudar:&nbsp;const&nbsp;int&nbsp;groundpin&nbsp;=&nbsp;18;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;//&nbsp;
pino de entrada analógica 4 - térreo&nbsp;const&nbsp;int&nbsp;powerpin&nbsp;=&nbsp;19;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//&nbsp;
pino de entrada analógica 5 - tensão&nbsp;const&nbsp;int&nbsp;xpin&nbsp;=&nbsp;A3;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//&nbsp;
&nbsp;eixo-x do acelerômetro&nbsp;const&nbsp;int&nbsp;ypin&nbsp;=&nbsp;A2;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//&nbsp;
&nbsp;eixo-yconst&nbsp;int&nbsp;zpin&nbsp;=&nbsp;A1;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//&nbsp;
z-axis (apenas em 3 eixos modelos)&nbsp;&nbsp;void&nbsp;setup(){&nbsp;&nbsp;//&nbsp;
inicializa a comunicação serial:&nbsp;&nbsp;&nbsp;&nbsp;Serial.begin(9600);&nbsp;
&nbsp;// Fornecer solo e de energia usando as entradas analógicas como normal&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;pinos &nbsp;digital.&nbsp;Isto torna possível conectar diretamente a&nbsp;&nbsp;//&nbsp;bordo breakout para o Arduino.&nbsp;Se você usar o 5V normal e&nbsp;&nbsp; //&nbsp;pinos / GND no Arduino, você pode remover essas&nbsp;&nbsp;//&nbsp;imprimir os valores do sensor:&nbsp;&nbsp;&nbsp;pinMode(groundpin,&nbsp;OUTPUT);&nbsp;&nbsp;pinMode(powerpin,&nbsp;OUTPUT);&nbsp;&nbsp;digitalWrite(groundpin,&nbsp;LOW);&nbsp;&nbsp;digitalWrite(powerpin,&nbsp;HIGH);}void&nbsp;loop(){&nbsp;&nbsp;//&nbsp;
imprimir um guia entre os valores:&nbsp;&nbsp;&nbsp;Serial.print(analogRead(xpin));&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;imprimir um guia entre os valores :&nbsp;&nbsp;&nbsp;&nbsp;Serial.print("\t");&nbsp;&nbsp;Serial.print(analogRead(ypin));&nbsp;&nbsp;//&nbsp;
imprimir um&nbsp;guia&nbsp;entre os valores:&nbsp;&nbsp;&nbsp;Serial.print("\t");&nbsp;&nbsp;Serial.print(analogRead(zpin));&nbsp;&nbsp;Serial.println();&nbsp;&nbsp;//&nbsp;
atraso&nbsp;antes de ler&nbsp;a seguir:&nbsp;&nbsp;&nbsp;delay(100);
}

&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Fonte: Arduino.cc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;