Démarrer
Câblage vers l’ESP32
| Broche du capteur | Broche ESP32 | Statut | Rôle |
|---|---|---|---|
| GND | GND | Requis | Sol |
| +V | 3.3V or 5V | Requis | Alimentation |
| Signal | GPIO36 | Requis | Entrée analogique (broche ADC) |
Code
Aucune bibliothèque à installer.
// 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
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éristique | Valeur |
|---|---|
| Output | Analog voltage proportional to light intensity |
| Dimensions | 28 x 15 x 7 mm |
| Fixed Resistance | 10 kΩ |
| Operating Voltage | 3.3V - 5V |
| Operating Temperature | -25°C to 70°C |

