Impostare una soglia di luminosità
Decida quando una lettura è “abbastanza buio” per attivare un'azione.
Impostare una soglia di luminosità è una lezione Arduino & IoT Academy gratuita su CoddyKit. Questa è la lezione 3 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Arduino & IoT Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Arduino & IoT Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
Raw Numbers Need Meaning
An analog reading like 312 means nothing on its own. A threshold turns that number into a clear decision: dark or bright.
What a Threshold Is
A threshold is a cutoff value. Readings on one side count as dark, and readings on the other count as bright.
Store It in a Variable
Keep your cutoff in a named variable so it is easy to find and adjust later in one place.
int threshold = 400;Compare With if
Use an if statement to compare the live reading against your threshold and branch your logic from there.
if (light < threshold) {
// it is dark
}Direction Depends on Wiring
Whether dark means a higher or lower number depends on how you wired the divider. Confirm it before you trust the test.
Find Your Number
Print readings in a bright room and a dark one, then pick a midpoint between them as your starting threshold.
Add else for Bright
Pair your if with an else so the bright case is handled too, instead of doing nothing when light is high.
else {
// it is bright
}One Cutoff Causes Flicker
Near the line, tiny changes can flip the result back and forth. This rapid flicker looks like a glitch.
Add Hysteresis
Hysteresis uses two cutoffs: one to switch on and a different one to switch off. The gap stops nervous flicker.
Make It Adjustable
Feed the threshold from a potentiometer so anyone can dial in dark without re-uploading code.
Thresholds Drive Decisions
This same threshold idea works for temperature, moisture, and distance. It is how sensors become decisions.
Quick Check
What problem does hysteresis solve at a light threshold?
Recap: Deciding on Light
You stored a threshold, compared readings with if and else, and added hysteresis so the decision stays steady.
Domande Frequenti
La lezione «Impostare una soglia di luminosità» è gratuita?
Sì — il testo completo di «Impostare una soglia di luminosità» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Arduino & IoT Academy, passa a CoddyKit PRO. Il corso Arduino & IoT Academy include 4 lezioni in totale.
Cosa imparerò in «Impostare una soglia di luminosità»?
Decida quando una lettura è “abbastanza buio” per attivare un'azione. Eserciti Arduino & IoT Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare Arduino & IoT Academy?
Non è richiesta alcuna esperienza precedente. Arduino & IoT Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 3 di 4.
Quanto tempo richiede la lezione «Impostare una soglia di luminosità»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione Arduino & IoT Academy?
Sì. Ogni lezione Arduino & IoT Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Leggere un sensore di movimento PIR
- Misurare la luce con un LDR
- Impostare una soglia di luminosità
- Luce notturna automatica