The SW-420 Vibration Sensor is a simple and cost-effective module designed to detect vibrations and shocks. It is based on the principle of a conductive ball inside a tube that makes contact with pins when the sensor is moved, thus closing the circuit. This sensor is widely used in applications such as burglar alarms, car alarms, smart vehicles, earthquake detection systems, and other systems where vibration or impact detection is required.
Pin Number | Name | Description |
---|---|---|
1 | GND | Ground, connected to the system ground |
2 | DO | Digital Output, logic high when triggered |
3 | VCC | Power supply, 3.3V to 5V |
// Define the pin where the sensor is connected
const int vibrationSensorPin = 2;
void setup() {
// Initialize the sensor pin as an input
pinMode(vibrationSensorPin, INPUT);
// Begin serial communication at a baud rate of 9600
Serial.begin(9600);
}
void loop() {
// Read the state of the vibration sensor
int sensorState = digitalRead(vibrationSensorPin);
// Check if the sensor is triggered
if (sensorState == HIGH) {
// If the sensor is triggered, print a message to the serial monitor
Serial.println("Vibration detected!");
} else {
// If the sensor is not triggered, print a different message
Serial.println("No vibration detected.");
}
// Wait for a short period before reading again
delay(100);
}
Q: Can the SW-420 Vibration Sensor detect the direction of vibration? A: No, the SW-420 can only detect the presence of vibration, not its direction.
Q: Is it possible to use the SW-420 sensor with a battery? A: Yes, as long as the battery voltage is within the operating range of 3.3V to 5V.
Q: How can I extend the life of the sensor? A: Avoid exposing the sensor to continuous vibrations and extreme temperatures to prolong its lifespan.
Q: Can I use the SW-420 sensor with an analog input? A: The SW-420 provides a digital output and is not designed for analog input. However, some modules may come with an analog output; refer to the specific module datasheet for details.