Démarrer
Câblage vers l’ESP32
| Broche du capteur | Broche ESP32 | Statut | Rôle |
|---|---|---|---|
| GND | GND | Requis | Sol |
| +5V | 3.3V | Requis | Alimentation (utiliser 3,3 V pour ESP32) |
| VRx | GPIO36 | Requis | Entrée analogique de l'axe X (broche ADC) |
| VRy | GPIO39 | Requis | Entrée analogique de l'axe Y (broche ADC) |
| SW | GPIO34 | Optionnel | Entrée de bouton avec pull-up interne |

Code
Aucune bibliothèque à installer.
// Declaration and initialization of the input pins
int JoyStick_X = A0; // X-axis signal
int JoyStick_Y = A1; // Y-axis signal
int Button = 3; // Button
void setup() {
pinMode(JoyStick_X, INPUT);
pinMode(JoyStick_Y, INPUT);
pinMode(Button, INPUT_PULLUP); // Enable internal pull-up resistor
Serial.begin(9600); // Serial output with 9600 bps
}
void loop() {
float x, y;
int buttonState;
// Read current values and convert to voltage
x = analogRead(JoyStick_X) * (5.0 / 1023.0);
y = analogRead(JoyStick_Y) * (5.0 / 1023.0);
buttonState = digitalRead(Button);
// Output the values
Serial.print("X-axis:"); Serial.print(x, 4); Serial.print("V, ");
Serial.print("Y-axis:"); Serial.print(y, 4); Serial.print("V, ");
Serial.print("Button:");
if (buttonState == HIGH) {
Serial.println("not pressed");
} else {
Serial.println("pressed");
}
delay(200);
}
Brochage
| Broche | Type | Description |
|---|---|---|
| GND | Power | Connexion à la terre |
| +5V | Power | Alimentation3,3 V ou 5 V (vérifier la compatibilité) |
| VRx | Communication | Sortie analogique axe XLa tension varie avec la position X |
| VRy | Communication | Sortie analogique sur l'axe YLa tension varie avec la position Y |
| SW | Control | Signal interrupteur/boutonActif faible lorsqu'on appuie dessus |

Caractéristiques
Le KY-023 est un module joystick à deux axes qui fournit des sorties analogiques pour les positions X et Y, ainsi qu'une sortie numérique pour un bouton-poussoir intégré. Il est idéal pour les applications nécessitant une entrée directionnelle, telles que les télécommandes, les interfaces de jeu et la navigation robotique.
| Caractéristique | Valeur |
|---|---|
| Weight | 12 g |
| Dimensions | 34 x 39 x 26 mm |
| Operating Voltage | 3.3V - 5V |
| Output Voltage Range | 0V to VCC |
