Arduino Tutorial 19: LED & Buzzer with Tilt Switch Balance sensor#arduinotutorial #arduinoproject

preview_player
Показать описание
In this video, we explore how to use a **Mercury Tilt Sensor** with an **Arduino** to control an **LED** and a **Buzzer**. The setup is simple yet effective, making it perfect for beginners interested in motion detection, safety systems, or tilt-based triggers.

---

📌 **Project Overview:**
We use a mercury tilt switch to detect the physical orientation of the system. When the sensor is in a **non-tilted** (open circuit) position, it **activates** an LED and a buzzer. When tilted (closed circuit), both outputs are turned **off**. This reverse logic can be useful in building safety systems, balance detection mechanisms, or anti-tamper alarms.

---

🔌 **Wiring Overview:**

| Component | Arduino Pin |
|------------------|-------------|
| Mercury Sensor | D3 |
| Buzzer (+) | D5 |
| LED (+) | D9 |
| All GND (-) | GND |

The mercury switch acts like a simple digital switch. We use `INPUT_PULLUP` to make the logic easier and avoid external resistors. The sensor outputs **HIGH** when not tilted (open), and **LOW** when tilted (closed).

---

🧠 **How It Works:**

- When the device is in a **steady, flat** position:
- Mercury inside the sensor **does not connect** the terminals
- Arduino reads **HIGH**
- LED and buzzer are **ON**

- When the device is **tilted**:
- Mercury **connects** the terminals
- Arduino reads **LOW**
- LED and buzzer are **OFF**

This setup is especially useful for detecting unwanted tilting, like in anti-theft systems or auto shutoff safety features.

---

💻 **Arduino Code Used:**

```cpp
const int mercuryPin = 3; // Mercury tilt switch connected to D3
const int ledPin = 9; // LED connected to D9
const int buzzerPin = 5; // Buzzer connected to D5

void setup() {
pinMode(mercuryPin, INPUT_PULLUP); // Use internal pull-up
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}

void loop() {
int sensorState = digitalRead(mercuryPin);

if (sensorState == HIGH) {
// Mercury is "off" (not tilted)
digitalWrite(ledPin, HIGH);
digitalWrite(buzzerPin, HIGH);
} else {
// Mercury is "on" (tilted)
digitalWrite(ledPin, LOW);
digitalWrite(buzzerPin, LOW);
}

delay(10);
}
Рекомендации по теме
welcome to shbcf.ru