0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Arduinoで加速度センサを使う

Posted at

この記事は、arduinoで加速度センサ(KXR94-2050)を使うためのものです。X,Y,Zそれぞれの軸の加速度を計測できます。1個当たり850円で購入出来ます。
http://akizukidenshi.com/catalog/g/gM-05153/
※静止状態において重力加速度がわかるので、姿勢がわかります。動いているときには、動きの加速度が加わるので、絶対的な姿勢はわかりません。

接続方法

IMG_5685.JPG

1<->5V
2<->5V
3<->GND
5<->GND
6<->A2
7<->A1
8<->A0

プログラム

説明書によると1.65Vが基準値(ゼロG)です。

シリアルプロッタで確認するプログラム例です。
3つの値の場合、x,y,zとなるように出力すると、シリアルプロッタで3つのグラフが表示できます。print命令は改行なし、println命令は改行ありで、最後のzだけ、改行します。

acce.ino
void setup() {
  Serial.begin(9600);
}

void loop() {
  int x = analogRead(0);
  int y = analogRead(1);
  int z = analogRead(2);
  Serial.print(x);
  Serial.print(",");
  Serial.print(y);
  Serial.print(",");
  Serial.println(z);
  
  delay(20);
}


0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?