0Pricing
Arduino & IoT Academy · Lezione

Leggere i comandi digitati

Utilizzi l'input Serial per attivare azioni dalla tastiera.

Leggere i comandi digitati è una lezione Arduino & IoT Academy gratuita su CoddyKit. Questa è la lezione 4 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.

Talk Back to Your Board

Serial works both ways. You can type into the Monitor and your board will read it, letting you send commands from your keyboard. ⌨️

Is Anything Waiting?

First check if data has arrived with Serial.available(). It returns how many bytes are sitting in the buffer, ready to read.

if (Serial.available() > 0) {
}

Why Check First

Reading when nothing is there gives junk. So you guard your read with available() and only act when real data exists.

Read One Character

Grab a single incoming character with Serial.read(). It pulls one byte from the buffer and hands it to you.

char c = Serial.read();

React to a Command

Now branch on what you got. Compare the character and run different actions, like turning an LED on or off.

if (c == '1') digitalWrite(13, HIGH);
if (c == '0') digitalWrite(13, LOW);

Mind the Quotes

Notice the single quotes around '1'. That is a character, not the number one, and matching it correctly matters.

Reading Whole Words

For full commands like on or off, read a whole line with readStringUntil(), stopping at the newline you send.

String cmd = Serial.readStringUntil('\n');

Compare the Text

Then test the whole word. If the String equals on, do one thing; if it equals off, do another.

if (cmd == "on") digitalWrite(13, HIGH);

Set the Line Ending

In the Monitor, pick a line ending like Newline. It tells readStringUntil where each typed command stops.

Confirm Back

Good feedback feels great. After acting on a command, println a confirmation so you know the board heard you.

Serial.println("LED is on");

Now It Is Interactive

You just built a tiny command interface. Type, the board reads, acts, and replies. That is real two-way control. 🚀

Quick Check

Which function tells you whether typed data has arrived and is waiting to be read?

Recap

You made the board listen: checking available(), reading characters or full lines, acting on commands, and confirming back. Two-way Serial done! 🎉

Domande Frequenti

La lezione «Leggere i comandi digitati» è gratuita?

Sì — il testo completo di «Leggere i comandi digitati» è 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 «Leggere i comandi digitati»?

Utilizzi l'input Serial per attivare azioni dalla tastiera. 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 4 di 4.

Quanto tempo richiede la lezione «Leggere i comandi digitati»?

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. Serial.begin e baud rate
  2. Serial.print e println
  3. Osservare i valori dei sensori in tempo reale
  4. Leggere i comandi digitati
← Torna a Arduino & IoT Academy