// Projet Détecteur de Lumière Automatique - Nucleo C031C6
// LDR + LED automatique + Buzzer
#define LDR_PIN A0 // PA0
#define LED_PIN PA5 // LED jaune intégrée sur la carte
#define BUZZER_PIN D6 // PA6
int lightValue = 0;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
Serial.begin(115200);
Serial.println("=== Détecteur de Lumière Automatique (Nucleo C031C6) ===");
Serial.println("Déplace le slider du LDR pour tester");
delay(1000);
}
void loop() {
lightValue = analogRead(LDR_PIN);
Serial.print("Luminosité LDR : ");
Serial.print(lightValue);
if (lightValue < 1800) { // Il fait sombre
digitalWrite(LED_PIN, HIGH);
Serial.print(" → LED ALLUMÉE");
if (lightValue < 900) { // Très sombre
tone(BUZZER_PIN, 1500, 200);
Serial.print(" → BUZZER ON");
} else {
noTone(BUZZER_PIN);
}
}
else {
digitalWrite(LED_PIN, LOW);
noTone(BUZZER_PIN);
Serial.print(" → LED ÉTEINTE");
}
Serial.println();
delay(400);
}