[아두이노 부품] Arduino vibration module 아두이노 진동 모듈

2017. 8. 2. 03:28Arduino

진동 모터가 작동하게 하는 것은 간단하다.

전압을 두 개의 단자로 나눠서 주면 진동을 울릴 수 있다.

진동 모터는 빨강, 파랑의 단자 두 개가 있는데, 양극 + - 상관없이 연결해도 다 된다.

2.5V에서 3.8V의 전압을 주면 작동하는 Precision Microdrives의 진동 모터를 사용할 것이다.

그래서 3V의 전압을 주면 잘 작동할 것이다.


To make a vibration motor vibrate is very simple. All we have to do is add the needed voltage to the 2 terminals.
A vibration motor has 2 terminals, usually a red wire and a blue wire. The polarity does not matter for motors.
For our vibration motor, we will be using a vibration motor by Precision Microdrives.
This motor has an operating voltage range of 2.5-3.8V to be powered.
So if we connect 3 volts across its terminal, it will vibrate really well.




적절한 전압을 주기 위해서 알맞은 저항을 사용하지 않으면 진동 모터나 아두이노 보드 자체에 무리가 가서 문제가 생길 수 있다고 한다,,,



1
2
3
4
5
6
7
8
9
10
11
12
13
void setup() {
  pinMode( 6 , OUTPUT);
}
 
void loop() {
  
  analogWrite( 6 , 100 );
  delay(1000);
 
  analogWrite( 6 , 0 );
  delay(3000);
 
}
cs



setup()에서 진동 모터가 아두이노 6번 포트에 연결됐다고 지정하고, OUTPUT으로 둬서 loop()에서 구현한 실행 결과가 출력이 되게 설정한다.

loop()에서 진동 세기를 100으로 진동을 1초 울리고, 3초 동안 멈추고하는 것이 반복된다.

4초에 한 번씩 진동이 울리는 코드이다.


[출처] http://learningaboutelectronics.com/Articles/Vibration-motor-circuit.php







위의 예제는 수많은 방법들 중 한 가지 방법이고, 다양한 방법으로 진동을 주는 것을 구현을 할 수 있다.


어떤 특정 이벤트가 발생했을 시, 진동 모터가 울리게 설정을 하는 것을 아래에서 구현을 할 것이다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
int touchSensor = A0;  // 터치센서 핀 설정
int ledPin = 10;       // LED 핀 설정
 
void setup() 
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);  
  pinMode(touchSensor, INPUT);
}
 
void loop() 
{
  //터치값 읽음
  int touchValue = digitalRead(touchSensor);
  
  if (touchValue == HIGH)
  {// 터치됨
    digitalWrite(ledPin, HIGH);
    Serial.println("TOUCHED");
    analogWrite( 6 , 100 );
  }
  else
  {//터치 안됨
    digitalWrite(ledPin,LOW);
    Serial.println("NOT TOUCHED");
  }
}
 
cs



Softpot 터치센서와 LED 의 핀을 선언해준다.


setup()에서 터치센서를 입력으로 받으면 LED 빛을 출력해주는 형식으로 설정해준다.


loop()에서 터치센서의 값을 읽어와 터치값으로 받아서,


터치 값이 1이면 TOUCHED를 출력하고, LED 빛을 내고, 6번 포트의 진동을 준다.


터치 값이 0이면 NOT TOUCHED를 출력하고, LED 빛을 끈다.


[빨강] softpot 압력센서


[노랑] LED


[초록] 진동 모듈






마지막으로 시리얼 통신으로 지정한 입력을 줄 때, 불이 들어오고 진동이 울리게 하는 것을 구현했음.





serialEvent를 통해서 danger라는 입력이 있으면 WATCH OUT을 같이 출력하고 LED 빛과 진동을 같이 출력하는 코드이다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
int ledPin = 6;       // LED 핀 설정
int motorPin = 6;
 
String inputString = "";         // a string to hold incoming data
boolean stringComplete = false;  // whether the string is complete
 
void setup() {
  Serial.begin(9600);
  inputString.reserve(200);
}
 
void loop() {
  
  if (stringComplete)
  {
    if(inputString.equals("danger\n"))
    {
      Serial.print(inputString + " WATCH OUT!!!\n");
      inputString = "";
      stringComplete = false;
      digitalWrite(ledPin, HIGH);
      analogWrite( motorPin , 100 );
      delay(500);
      digitalWrite(ledPin, LOW);
    }
    else
    {
      Serial.print(inputString);
      inputString = "";
      stringComplete = false;
      digitalWrite(ledPin, LOW);
    }    
  }
}
 
void serialEvent() {
  while (Serial.available()) {
    char inChar = (char)Serial.read();
    inputString += inChar;
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}
 
cs