Aller au contenu
Bamba IoT

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

Modules KY-0xxAnalogique

Le KY-054 est un module phototransistor qui détecte les niveaux de lumière ambiante et fournit une sortie de tension analogique proportionnelle à l'intensité lumineuse.

Photo du KY-054

Démarrer

Câblage vers l’ESP32

Câblage vers l’ESP32
Broche du capteurBroche ESP32StatutRôle
GNDGNDRequisSol
+V3.3V or 5VRequisAlimentation
SignalGPIO36RequisEntrée analogique (broche ADC)

Code

Aucune bibliothèque à installer.

basic.ino
// Define pin for phototransistor
int light_sensor = A5;
// Definition of the parameters required for the calculation
const double U1 = 5.0;
const double R2 = 10000.0;
double U2;
double I;
double R1;
double lux;
int rawValue;

void setup() {
  // Define the pin mode
  pinMode(light_sensor, INPUT);
  // Set up serial communication for serial monitor
  Serial.begin(9600);
  Serial.println("KY-054 Brightness test");
}

void loop() {
  // Reading the voltage of the light sensor
  rawValue = analogRead(light_sensor);
  U2 = rawValue * (5.0/1023) ;  

  // Check U2 for the division
  if (U2 != 0) {
    // Calculate the resistance of the sensor
    R1 = (U1 * R2) / U2;
    // Calculate current
    I = (U1 / R1) * 1000000.0;
    // Calculate lux
    lux = log(I)/0.06;
  }
  else lux = 0;

  // Output the result on the serial monitor
  Serial.print("Lux:\t");
  Serial.println(lux);

  // wait for one second
  delay(1000);
}

Brochage

Brochage
BrocheTypeDescription
GNDPowerConnexion à la terre
+VPowerAlimentation3,3 V ou 5 V
SignalCommunicationSortie analogiqueTension proportionnelle à l'intensité lumineuse
Brochage du KY-054

Caractéristiques

Le KY-054 est un module phototransistor qui détecte les niveaux de lumière ambiante et fournit une sortie de tension analogique proportionnelle à l'intensité lumineuse. Il est couramment utilisé dans les projets nécessitant des capacités de détection de la lumière, tels que les systèmes d'éclairage automatiques et la détection de la luminosité.

Caractéristiques
CaractéristiqueValeur
OutputAnalog voltage proportional to light intensity
Dimensions28 x 15 x 7 mm
Fixed Resistance10 kΩ
Operating Voltage3.3V - 5V
Operating Temperature-25°C to 70°C