MichDragstar
Published © GPL3+

Arduino UNO and Vibration Sensor with Relay

When the vibration module detects vibration, the lamp will go on for 2 seconds and this for 3 times.

BeginnerFull instructions provided1 hour7,325
Arduino UNO and Vibration Sensor with Relay

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SW-420 Vibration sensor module
×1
Optocoupler PC817
×1
Transistor BC 547
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×1
Relay 5V DC
×1
5 mm LED: Red
5 mm LED: Red
A second LED is used to show the relay contact ON OFF
×1
Resistor 220 ohm
Resistor 220 ohm
×2
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
4xAA battery holder
4xAA battery holder
In this project I used a battery holder with 3 AA batteries
×1

Story

Read more

Schematics

Arduino UNO with Vibration sensor module and relay

Code

Vibration_sensor.ino

Arduino
//Vibration Sensor Module (Code)Arduino with relay and external 5V power source.
  
int vib_pin=2;
int led_pin=13;


// put your setup code here, to run once:
void setup() { 
  pinMode(vib_pin,INPUT);
  pinMode(led_pin,OUTPUT);
}


  // put your main code here, to run repeatedly:
void loop() {
  int val;
  val=digitalRead(vib_pin);
  if(val==1)
  {
    digitalWrite(led_pin,LOW);
    delay(2000);
    digitalWrite(led_pin,HIGH);
    delay(1000);
    digitalWrite(led_pin,LOW);
    delay(2000);
    digitalWrite(led_pin,HIGH);
    delay(1000);
    digitalWrite(led_pin,LOW);
    delay(2000);
    digitalWrite(led_pin,HIGH);
    delay(1000);
    
   }
   else
   digitalWrite(led_pin,HIGH);
}

Credits

MichDragstar
7 projects • 17 followers
Contact

Comments

Please log in or sign up to comment.