Overview
Earthquakes are scary natural disasters that can cause a lot of damage and danger. Imagine if there was a way to know when an earthquake might happen a little bit before it does. That would give us time to protect ourselves and our things.
In today’s tutorial, we are going to make an “Earthquake Detector” using the XIAO RP2040 Microcontroller and Vibration Sensor.
What is an Earthquake Detector?
An earthquake detector is a device designed to sense and detect movements or vibrations in the ground that occur during an earthquake. The detector can use various sensors, such as accelerometers or gyroscopes, to pick up these movements. When it senses unusual ground activity, it triggers an alarm or sends out warnings to alert people in advance about the possibility of an impending earthquake
PCBGOGO has offered high-quality PCBs and the best PCB assembly service all over the world since 2015. Discover an incredible offer that puts PCB prototyping within reach for just $1. Yes, you read that right – for only a dollar, you can bring your innovative ideas to life with a PCB prototype. Don’t miss out on this fantastic opportunity to turn your electronics projects into reality. Explore the campaign here: PCBGOGO $1 PCB Prototype and pave the way for your next big creation!
Hardware Components
You’ll need the following hardware components to get started:
Components | Value / Model | Qty |
---|---|---|
PCB | PCB-GOGO | |
XIAO | RP2040 | 1 |
Vibration Sensor | SW420 | 1 |
Buzzer | – | 1 |
Jumper Wires | – | 1 |
XIAO RP2040 Pinout
For details on the datasheet of the XIAO RP2040 Microcontroller visit this link.
Pin No | Pin Name |
---|---|
1 | P26 / A0 / D0 |
2 | P27 / A1 / D1 |
3 | P28 / A2 / D2 |
4 | P29 / A3 / D3 |
5 | P6 / SDA/ D4 |
6 | P7 / SCL / D5 |
7 | P0 / TX / D6 |
8 | P1 / RX / CSN / D7 |
9 | P2 / SCK / D8 |
10 | P3 / MISO / D9 |
11 | P4 / MOSI / D10 |
12 | 3V3 |
13 | GND |
14 | 5V |
801s Vibration Sensor Pinout
Pin No | Pin Name | Pin Description |
---|---|---|
1 | VCC | VCC is the +5 volt Positive Pin |
2 | Sig | Signal Output |
3 | GND | GND is the (Ground) Negative |
Steps-by-Step Guide
(1) Setting up Arduino IDE
Download Arduino IDE Software from its official site. Here is a step-by-step guide on “How to install Arduino IDE“.
(2) XIAO RP2040 in Arduino IDE
There’s an add-on that allows you to program the XIAO RP2040 using the Arduino IDE. Here is a step-by-step guide on “How to Install XIAO RP2040 on Arduino IDE“.
(3) Schematic
Make connections according to the circuit diagram given below.
Wiring / Connections
XIAO RP2040 | Vibration Sensor | Buzzer |
---|---|---|
5V | VCC | |
GND | GND | GND |
D2 | AO | – |
D0 | – | +ve |
(4) Uploading Code
Now copy the following code and upload it to Arduino IDE Software.
// Circuits DIY
// For Complete Details Visit -> https://www.circuits-diy.com/earthquake-detector-alarm-using-xiao-rp2040
int BUZZER = D0; // Digital Pin 0 define Buzzer interface
int VIBRATION = D2; // Digital Pin 2 define vibration sensor interface
int VAL; // Define the variable as VAL
void setup()
{
Serial.begin(9600);
pinMode(BUZZER,OUTPUT); //The defined Output as Buzzer
pinMode(VIBRATION,INPUT); //The defined input as Vibration
}
void loop()
{
VAL=digitalRead(VIBRATION);
if(VAL==HIGH) // If the sensor detects a vibration Buzzer will be HIGH
{
Serial.print("Vibration Detected : ");
Serial.println(VAL);
digitalWrite(BUZZER,HIGH);
delay(2000);
}
else
{
Serial.println(VAL);
digitalWrite(BUZZER,LOW); //if detects no vibration Buzzer stay in LOW
}
}
How code works
BUZZER
andVIBRATION
are defined as the digital pins connected to the buzzer and vibration sensor, respectively.- In the
setup()
function:Serial.begin(9600)
initializes serial communication at a baud rate of 9600 for debugging and outputting sensor readings.pinMode()
setsBUZZER
as an output pin andVIBRATION
as an input pin.
- The
loop()
function continuously performs the following:- Reads the value from the vibration sensor using
digitalRead(VIBRATION)
and stores it in the variableVAL
. - If
VAL
isHIGH
(vibration detected), it prints a message to the serial monitor, turns on the buzzer (digitalWrite(BUZZER, HIGH)
), and waits for 2 seconds (delay(2000)
). - If no vibration is detected (when
VAL
is notHIGH
), it turns off the buzzer (digitalWrite(BUZZER, LOW)
).
- Reads the value from the vibration sensor using
This code essentially creates a basic earthquake detector: when the vibration sensor detects movement (like an earthquake), it triggers the buzzer to sound an alarm.
Applications
- Early Warning System: Provides early alerts to individuals and communities about possible earthquakes.
- Safety Measures: Allows time for people to take cover, secure belongings, or initiate emergency protocols.
- Infrastructure Protection: Helps in safeguarding buildings, bridges, and critical infrastructure.
- Research and Data Collection: Collect valuable data on seismic activities for scientific analysis.
Conclusion
The earthquake detector using XIAO RP2040 and a vibration sensor serves as a valuable tool for preemptively sensing seismic activities. Its ability to detect vibrations and trigger alarms offers crucial seconds or minutes for people to prepare and take safety precautions.