0Pricing
Arduino & IoT Academy · Aula

Leia os comandos que você digita

Use a entrada Serial para acionar ações pelo teclado.

Leia os comandos que você digita é uma aula grátis de Arduino & IoT Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Arduino & IoT Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Arduino & IoT Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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! 🎉

Perguntas Frequentes

A aula “Leia os comandos que você digita” é grátis?

Sim — o texto completo de “Leia os comandos que você digita” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Arduino & IoT Academy, atualize para CoddyKit PRO. O curso de Arduino & IoT Academy inclui 4 aulas no total.

O que vou aprender em “Leia os comandos que você digita”?

Use a entrada Serial para acionar ações pelo teclado. Você pratica Arduino & IoT Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Arduino & IoT Academy?

Nenhuma experiência prévia é necessária. Arduino & IoT Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Leia os comandos que você digita”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Arduino & IoT Academy?

Sim. Cada aula de Arduino & IoT Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Serial.begin e Taxa de Transmissão
  2. Serial.print versus println
  3. Veja os valores dos sensores ao vivo
  4. Leia os comandos que você digita
← Voltar para Arduino & IoT Academy