0Pricing
Arduino & IoT Academy · Lezione

Riattivare con timer o pin

Programmi i risvegli o attivi la scheda in risposta a un evento.

Riattivare con timer o pin è 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.

Two Ways to Wake

A sleeping ESP needs a reason to wake. The two classic triggers are a timer that counts down and a pin that senses an event. ⏰

Timer Wakeups for Schedules

A timer wakeup is perfect for regular jobs, like reading a sensor every ten minutes. The chip sleeps, then wakes right on schedule.

esp_sleep_enable_timer_wakeup(600 * 1000000);

Microseconds, Always

Timer values are in microseconds. For ten minutes you write 600 seconds times one million, so picking the right zeros really matters.

Pin Wakeups for Events

An external wakeup reacts to the real world. A motion sensor or button can jolt the chip awake the instant something happens.

ext0 Wakes on One Pin

The ext0 source watches a single RTC pin. You choose the pin and whether a HIGH or LOW level should trigger the wakeup.

esp_sleep_enable_ext0_wakeup(GPIO_NUM_33, 1);

ext1 Wakes on Many Pins

Need several buttons? The ext1 source watches a group of RTC pins at once, waking when any of them hits the chosen level.

Only RTC Pins Qualify

Not every pin can wake the chip. Only the special RTC pins stay alive during deep sleep, so wire your trigger to one of those.

Combine Both Triggers

You can arm a timer and a pin together. The chip then wakes on a regular schedule or immediately if an event interrupts the nap.

Find Out Why It Woke

After waking, ask the chip what happened with wakeup_cause. Then you can run different code for a timer versus a button press.

esp_sleep_get_wakeup_cause();

Branch on the Reason

Compare the cause against known sources to branch your logic. A timer might mean read a sensor; a pin might mean send an alert.

if (cause == ESP_SLEEP_WAKEUP_TIMER) { /* scheduled job */ }

Arm, Then Sleep

Always set your wakeup sources first, then call sleep last. Arming after the sleep call is pointless because that line never runs.

Quick Check

Pick the right wakeup for the job.

Recap: Choose Your Trigger

Use a timer for scheduled jobs and an ext pin for real-world events. Arm sources before sleep, then check the cause to branch on wakeup. ⚡

Domande Frequenti

La lezione «Riattivare con timer o pin» è gratuita?

Sì — il testo completo di «Riattivare con timer o pin» è 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 «Riattivare con timer o pin»?

Programmi i risvegli o attivi la scheda in risposta a un evento. 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 «Riattivare con timer o pin»?

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

  1. Dove va a finire l'energia
  2. Attivare il deep sleep di ESP
  3. Riattivare con timer o pin
  4. Progettare un nodo sensore a batteria
← Torna a Arduino & IoT Academy