Friday, July 11, 2014

How to Work With HDX2 Vibration Switch Sensor using Arduino UNO.

Hi, This is my Very First Tutorial about How to work with HDX2 Vibration Switch Sensor using Arduino UNO.
  • No Libraries needed.
  • No Advance knowledge needed. 
 All you need are,

  • 1 x HDX2 Vibration Switch Sensor.
  • 1 x Arduino UNO board with USB cable ( or Lakduino ).
  • 2 x Male to Female Jumper Cables.
  • ( 1 x LED bulb if you need. )
OK.. Lets see How to do it..

  1. Connect the jumper wire's female end to HDX2 Vibration Switch Sensor.

  1. Connect Male ends to Arduino's 3 (digital) and GND (ground) ends.





If You have a LED connect it's (+) to Arduino's 13th female end And (-) to Arduino's GND

OK.. you Done..

     3.  Copy This Code to Your Arduino IDE.

-----------------------------------------------------

int ledPin = 13;
int sensor = 3;


void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(sensor, INPUT);

}

void loop() {
  if(digitalRead(sensor)==HIGH){
    digitalWrite(ledPin, HIGH);
    delay(1000);
  }else{
    digitalWrite(ledPin, LOW);
  }
}


-----------------------------------------------------

     4.  Compile and Upload to Arduino. 

You've Done !!  ;)

The LED or (and) Arduino's 13th pin's LED will blink when HDX2 Vibration Switch Sensor can sens a Vibrate !
Good Luck..



Any Questions ?? Comment Below.. :)

9 comments:

  1. can we use this sensor as an analog input using threshold level.

    ReplyDelete
    Replies
    1. Yes.. You can do it.. preview your sensor's incoming data with simple code given below. if you want some sample code let me know. thanks

      Serial.print(analogRead(sensor));

      Delete
  2. Hi, Can the code be amended so that it can have 6 vibration sensors and 6 LED's so that each vibration sensor lights a different LED?

    ReplyDelete
    Replies
    1. Hi, Please declare 6 variables for each LEDs and 6 Variables for each sensors.
      then filter results with if-else ladder.
      Thanks.

      Delete
  3. I have tried this code and cannot get it to work. not sure what I am doing wrong.

    ReplyDelete
  4. I finally got it working but had to go through a pull-up resistor.

    ReplyDelete
  5. Can we use this sensor as earthquake detector? Is this sensor same with SW420? Which have better sensitivity? Thanks

    ReplyDelete
  6. Blackjack from The Grand Victoria Casino - Mapyro
    Blackjack 문경 출장샵 From The 남양주 출장마사지 Grand Victoria Casino is a fun, 거제 출장마사지 exciting, and 목포 출장안마 fun casino table game featuring the same 군포 출장마사지 rules as standard blackjack.

    ReplyDelete