← Back to Basic Projects
Basic . Project #19

⚖️ Tilt Sensor Toggle Switch

Detect orientation changes or vibration and use it to toggle an LED on and off.

📋 Overview

A ball-tilt sensor contains a tiny metallic ball that completes a circuit when the module is tilted at a certain angle. It's the simplest way to detect motion or orientation.

What you'll learn: Digital switch input, state toggling logic, and mechanical sensor basics.

Estimated time: 20-30 minutes. Difficulty: ⭐ Beginner-friendly.

🧩 Components Needed

ComponentSpecificationQtyNotes
Arduino Uno R35V1
Tilt Switch (SW-520D)Ball-type1
LED5mm1
Resistor220Ohm1
Resistor10kOhm1Pull-down

📖 Step-by-Step Tutorial

1

Wire Tilt Sensor

Connect one leg to 5V, other leg to Pin 2 and GND via 10kOhm pull-down.
2

Wire LED

Connect LED to Pin 13 via 220Ohm resistor.
3

Upload and Tilt

Upload the code. Tilt the breadboard 90 degrees — the LED will toggle state.
💡
Tilt switches are mechanical and can be "bouncy." The code uses a small delay to debounce the signal and prevent accidental toggling.

💻 Arduino Code

tilt_toggle.ino
INO
// Tilt Toggle : Volt X
const int tiltPin = 2;
const int ledPin = 13;
bool ledState = LOW;

void setup() {
  pinMode(tiltPin, INPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  if (digitalRead(tiltPin) == HIGH) {
    ledState = !ledState;
    digitalWrite(ledPin, ledState);
    delay(500); // Simple debounce
  }
}

Reviews & Ratings

0 reviews
5★
0
4★
0
3★
0
2★
0
1★
0

Loading reviews…