Vibration Sensor Module

  • Vibration Sensor Module
Below the corresponding code:
an example project for the Vibration Sensor
//Author: Danny van den Brande
//This code is a basic code and a simple example on how to make a Earthquake alarm for example
//Feel free to do what you want with this code.
int GreenLed = 4;
int RedLed = 5;
int Shock = 6; 
int Buzzer = 7;
int val; // define numeric variables val

// here i set up the tones, you can change them @ void loop.
int tones[] = {261, 277, 293, 311, 329, 349, 369, 392, 415, 440, 466, 493, 523 ,554};
//              1    2    3    4    5    6    7    8    9    10   11   12   13   14
// You can add more tones but i added 14. Just fill in what tone you would like to use, @ void loop you see " tone(Buzzer, tones[12]); " below,  digitalWrite(Buzzer, HIGH);
// here you can change the tones by filling in a number between 1 and 14

void setup ()
{
  pinMode (GreenLed, OUTPUT) ; 
  pinMode (RedLed, OUTPUT) ; 
  pinMode (Shock, INPUT) ; //vibration sensor
  pinMode (Buzzer, OUTPUT) ;
}
void loop ()
{
  val = digitalRead (Shock) ; // Reads Digital Pin of sensor.
  if (val == HIGH) // When the shock sensor detects a signal, LED flashes
  {
    digitalWrite (RedLed, LOW);
    digitalWrite (GreenLed, HIGH);
    digitalWrite (Buzzer, LOW);
  }
  else
  {
    digitalWrite (RedLed, HIGH);
    digitalWrite (GreenLed, LOW);
    digitalWrite(Buzzer, HIGH); // here the Buzzer is set high in order to make a sound.
    tone(Buzzer, tones[6]); //here we set the tone by choosing from number 1 to 14
    delay (50);
    digitalWrite(Buzzer, LOW); // here we set the buzzer low and next we set noTone for the buzzer to make a break.
    noTone(Buzzer);
    delay (50); //this is the delay between each buzzer beep. You can play with the sounds by choosing from number 1 to 14
    digitalWrite(Buzzer, HIGH);
    tone(Buzzer, tones[9]);
    delay (100);
    digitalWrite(Buzzer, LOW);
    noTone(Buzzer);
  }
}

SCHEMATIC
Pin - = GND, connect to GND of the Arduino
Pin (middel pin) +5 v, connect to Arduino +5
Pin S signal, connect to Arduino pin 6
Specifications
Working voltage: 3~5V

Write a review

Please login or register to review

Vibration Sensor Module

  • Webwinkel Keurmerk en klantebeoordelingen

  • 14 dagen bedenktijd 
  • Verzendkosten voor eigen rekening
  • Product Code: KY-002
  • Availability: 14
  • 2.29€

  • Ex Tax: 1.89€

Similar Products

2 Color led module RG

2 Color led module RG

Below the corresponding code:// Arduino test code for KY011 int redpin = 11; // select the pin for ..

2.29€ Ex Tax: 1.89€

Mini Reed Module

Mini Reed Module

Below you can see the corresponding code: An example of a project for the mini reed switch//Author:..

2.36€ Ex Tax: 1.95€

Key Switch Button Module

Key Switch Button Module

Below you can see the corresponding code: An example project for the KY-004//Hello world! This time..

2.49€ Ex Tax: 2.06€

Sound Sensor Module

Sound Sensor Module

Below the corresponding code:Example code: Digital output.int Led = 13 ;// define LED Interfaceint b..

2.29€ Ex Tax: 1.89€