Aller au contenu
Bamba IoT

KY-020 : câblage ESP32, code et brochage

Modules KY-0xxNumérique

Le KY-020 est un module de commutateur d'inclinaison qui détecte les changements d'orientation.

Photo du KY-020

Démarrer

Câblage vers l’ESP32

Câblage vers l’ESP32
Broche du capteurBroche ESP32StatutRôle
Pin (-)GNDRequisSol
Pin (middle)3.3VRequisAlimentation
Pin (S)GPIO4RequisEntrée numérique (n'importe quel GPIO)
Schéma de câblage du KY-020

Code

Aucune bibliothèque à installer.

basic.ino
int tilt_switch = 10; // Declaration of the sensor input pin
int value; // Temporary variable

void setup() {
    pinMode(tilt_switch, INPUT); // Initialization sensor pin
    Serial.begin(9600); // Initialization of the serial monitor
    Serial.println("KY-020 Inclination test");
}

void loop() {
    // The current signal at the sensor is read out
    value = digitalRead(tilt_switch);
    // If a signal could be detected, this is displayed on the serial monitor.
    if (value == LOW) {
        Serial.println("Inclination recognized");
        delay(1000); // 1s break
    }
}

Brochage

Brochage
BrocheTypeDescription
Pin (-)PowerConnexion à la terre
Pin (middle)PowerAlimentation3,3 V à 5 V
Pin (S)CommunicationSortie de signal numériqueChange d'état lorsqu'il est incliné
Brochage du KY-020

Caractéristiques

Le KY-020 est un module de commutateur d'inclinaison qui détecte les changements d'orientation. Il fournit une sortie de signal numérique, ce qui le rend adapté aux applications telles que la détection de mouvement, les systèmes de sécurité et les commandes basées sur l'inclinaison.

Caractéristiques
CaractéristiqueValeur
Dimensions19 x 15 x 5 mm
Output TypeDigital
Operating Voltage3.3V - 5V