Démarrer
Câblage vers l’ESP32
| Broche du capteur | Broche ESP32 | Statut | Rôle |
|---|---|---|---|
| Pin (-) | GND | Requis | Sol |
| Pin (+) | 3.3V or 5V | Requis | Alimentation |
| Pin (S) | GPIO15 | Requis | Entrée numérique (n'importe quel GPIO) |

Code
Aucune bibliothèque à installer.
int sensorPin = 10; // Sensor connected to digital pin 10
int ledPin = 13; // LED connected to digital pin 13
int sensorValue = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH); // Enable internal pull-up resistor
Serial.begin(9600);
}
void loop() {
sensorValue = digitalRead(sensorPin);
if (sensorValue == HIGH) {
digitalWrite(ledPin, HIGH); // Turn on LED
Serial.println("Object detected");
} else {
digitalWrite(ledPin, LOW); // Turn off LED
}
delay(100);
}
Brochage
Caractéristiques
Le KY-010 est un module photo-interrupteur qui détecte les objets en détectant les interruptions dans un faisceau infrarouge. Il est idéal pour les applications nécessitant une détection d'objets sans contact, telles que le comptage ou la mesure de vitesse.
| Caractéristique | Valeur |
|---|---|
| Dimensions | 19 mm x 15 mm |
| Slot Width | 5 mm |
| Output Type | Digital |
| Operating Voltage | 3.3V - 5V |

