LoginSignup
0
1

More than 3 years have passed since last update.

振動センサモジュール使ってみた

Last updated at Posted at 2020-03-26

概要

振動センサーを購入したので試してみました。

部品

振動センサー:振動センサーモジュール
49円
image.png

表示機:TM1637が組み込まれた7セグLED
73円
image.png

コンピュータ:Arduino UNO互換機
699円
img.png

配線

スクリーンショット 2020-03-24 6.04.51.png

ソースコード


#include <Arduino.h>
#include <Wire.h>
#include <TM1637Display.h>
#define SERIAL_BAUD 115200

#define CLK 2
#define DIO 3
TM1637Display display(CLK, DIO);

void setup() {
  Serial.begin(SERIAL_BAUD);
  while(!Serial) {}

  uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
  display.setBrightness(0x0f);
  display.setSegments(data);
  delay(1000);
  pinMode(4,INPUT);
}

void loop() {
  int _ao = analogRead(A0);
  int _do=digitalRead(4);

  display.showNumberDec(_do, false); 
  Serial.print("\nDO: ");
  Serial.print(_do);
  Serial.print(" AO: ");
  Serial.print(_ao);
  delay(1);
}

github

少し感想

AOの方の入力が下がるとDOが0になるような動きをします。

すぐに検知が終了するため、実際に利用する場合には処理をかませる必要があると思います。
また、私のぶつ不良かもしれませんが、連続して点灯してしまう状態が何度かあったので、これが発生するとなかなか復旧しません。

動作確認

gif動画で上げても分かりにくかったので、Youtubeにて確認いただけると幸いです。
IMAGE ALT TEXT HERE

0
1
2

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
1