180 (single-axis), 90 (dual-axis), 45 (triple-axis)
180 (single-axis), 90 (dual-axis), 45 (triple-axis)
0.1 to 1
1 to 5
0.01 to 1/s
1 mA to 10 mA
-40C to 125C
Analog, digital, I2C, SPI, UART
Conclusion
The Tilt Sensor is a versatile and accurate component that measures the tilt angle of an object with respect to the horizontal plane. Its compact design, low power consumption, and high sensitivity make it suitable for a wide range of IoT applications, robotics, and industrial automation. By selecting the appropriate type of Tilt Sensor and configuring it for the specific application, developers can achieve precise and reliable measurements.
Tilt Sensor DocumentationOverviewThe Tilt Sensor is a digital sensor that detects changes in tilt or orientation of an object. It is commonly used in IoT applications such as robotics, gaming, and smart home devices. The sensor outputs a digital signal indicating the tilt direction (up, down, left, right, or neutral).Pinout| Pin | Function |
| --- | --- |
| VCC | Power Supply (3.3V or 5V) |
| GND | Ground |
| OUT | Digital Output (Tilt Direction) |Interfacing with MicrocontrollersThe Tilt Sensor can be easily interfaced with popular microcontrollers such as Arduino, Raspberry Pi, and ESP32.Example 1: ArduinoIn this example, we will use an Arduino board to read the tilt direction and control an LED accordingly.```c++
const int tiltPin = 2; // Tilt sensor output pin
const int ledPin = 13; // LED pinvoid setup() {
pinMode(tiltPin, INPUT);
pinMode(ledPin, OUTPUT);
}void loop() {
int tiltState = digitalRead(tiltPin);
if (tiltState == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on the LED when tilted
} else {
digitalWrite(ledPin, LOW); // Turn off the LED when not tilted
}
delay(50);
}
```Example 2: Python with Raspberry PiIn this example, we will use a Raspberry Pi board to read the tilt direction and print the result to the console.```python
import RPi.GPIO as GPIO
import timeGPIO.setmode(GPIO.BCM)
tilt_pin = 17 # Tilt sensor output pin
GPIO.setup(tilt_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)while True:
tilt_state = GPIO.input(tilt_pin)
if tilt_state:
print("Tilted!")
else:
print("Not tilted.")
time.sleep(0.5)
```Example 3: ESP32 with MicroPythonIn this example, we will use an ESP32 board to read the tilt direction and send the result to a remote server using Wi-Fi.```python
import machine
import urequeststilt_pin = machine.Pin(4, machine.Pin.IN)
wi Fi_ssid = "your_wifi_ssid"
wi Fi_password = "your_wifi_password"def connect_wifi():
import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect(wiFi_ssid, wiFi_password)
while not sta_if.isconnected():
passconnect_wifi()while True:
tilt_state = tilt_pin.value()
if tilt_state:
print("Tilted!")
urequests.post("http://your_server_ip/toggle", json={"state": "tilted"})
else:
print("Not tilted.")
urequests.post("http://your_server_ip/toggle", json={"state": "not_tilted"})
time.sleep(0.5)
```NotesThe tilt sensor output may require debouncing depending on the mechanical characteristics of the sensor and the application.
The examples above assume a simple digital output from the tilt sensor. If your sensor provides analog output, you may need to use an ADC (Analog-to-Digital Converter) to read the output.
Ensure to power the tilt sensor according to the manufacturer's specifications to avoid damage.