略過產品資訊
1 / 1

HK STEM CLUB

KY-020 傾斜開關模組 - TILT SWITCH MODULE

KY-020 傾斜開關模組 - TILT SWITCH MODULE

定價 HK$15.00
定價 售價 HK$15.00
特價 售罄
查看完整資訊

KY-020 TILT SWITCH MODULE

Description

KY-020 Arduino tilt switch sensor module. Closes the circuit when it is tilted to the side as long as it is moved with enough force and degree of inclination to activate the ball switch inside.

  • Arduino KY-020 Tilt Switch Module

  • KY-020 tilt switch Fritzing part image

Specifications

The KY-020 consists of a 10kΩ resistor and a metallic ball switch with bidirectional conduction that will open/close the circuit depending on its tilt degree. It does not measure tilt angle.

Operating Voltage 3.3V to 5v
Output Type Digital

KY-020 Connection Diagram

Connect the module's Power line (middle) and ground (-) to +5 and GND respectively. Connect signal (S) to pin 2 on the Arduino.

KY-020 Arduino
S 2
middle +5V
- GND
KY-020 Tilt switch connection diagramclick to enlarge

KY-020 Arduino Example Code

The following sketch will turn on the LED on pin 13 of the Arduino when the module detects a change in inclination degree. Tilt the KY-020 to turn the LED on/off.

int tiltPin = 2;      // pin number for tilt switch signal 
int ledPin =  13;     // pin number of LED 
int tiltState = 0;    // variable for reading the tilt switch status

void setup() {  
  pinMode(ledPin, OUTPUT);  // set the LED pin as output      
  pinMode(tiltPin, INPUT);  // set the tilt switch pin as input
}

void loop(){
  // get the tilt switch state
  tiltState = digitalRead(tiltPin);

  // check if tilt switch is tilted.
  if (tiltState == HIGH) {     
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    digitalWrite(ledPin, LOW); 
  }
}