Arduino(1):SW-420 vibration sense module

The SW-420 vibration sensing module is a non-directional vibration sensor, which can be used in various vibration triggers, such as: anti-theft, smart car, earthquake, etc.When the vibration sensing module is stationary, the circuit is turned on and the output is high. When motion or vibration occurs, the circuit will briefly open and output a low level. The module has a blue cross-shaped potentiometer adjustment that adjusts the sensitivity to suit your needs.

[Material]

  • Arduino Uno x 1
  • Vibration sensing module SW-042 x 1
  • Breadboard x 1
  • LED x 1
  • 220K resistance x 1
  • Buzzer x 1
  • Connection line x 7

[Wiring and circuit diagram]

ArduinoSW-420
+5V(VCC)VCC
GNDGND
Pin 3D0


[Code]

Program 1: Read whether D0 is 0 or 1, to determine whether vibration occurs?
int vibr = 3;  //  D0
int led = 9;   
int buzzer = 12; 

void setup() {
  pinMode(vibr,INPUT);
  pinMode(led,OUTPUT);
  pinMode(buzzer,OUTPUT);
}

void loop() {
  int val;
 
  val=digitalRead(vibr);
  
  if(val==1)   {
    digitalWrite(led,HIGH);
    digitalWrite(buzzer,HIGH);
    delay(2000);
   }
   else {
    digitalWrite(led,LOW);
    digitalWrite(buzzer,LOW);
    delay(1000);
   }
} 
Program 2: Use the pulseIn() function to read the pulse on the pin D0 (high or low). For example, if the value is HIGH, pulseIn() waits for the pin to go high, starts timing, then waits for the pin to go LOW and stop timing. If no complete pulse is received within the overtime, the length of the return pulse (in microseconds) or 0 is returned.
int vibr =3;  
int led = 9;  
int buzzer = 12; 

void setup() {
  pinMode(vibr,INPUT);
  pinMode(led,OUTPUT);
  pinMode(buzzer,OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int val;

  long measurement =TP_init();
  delay(50);
  Serial.println(measurement);
 
  if (measurement > 500){
    digitalWrite(led,HIGH);
    digitalWrite(buzzer,HIGH);
    delay(2000);
   }
   else {
    digitalWrite(led,LOW);
    digitalWrite(buzzer,LOW);
    delay(1000);
   }
}

long TP_init(){
  delay(10);
  long measurement=pulseIn (vibr, HIGH);  
  return measurement;
}

[Results]



[Reference]

Post a Comment

Previous Post Next Post