Serial.read()

Descripción

Lee los datos de la entrada serie. read() ihereda de la clase Stream.

Sintaxis

Serial.read()

Solo Arduino Mega:

Serial1.read()

Serial2.read()

Serial3.read()

Parámetros

  • Ninguno

Retornos

  • El primer byte disponible de los datos de la entrada serie (o -1 si no hay datos disponibles) - int

Ejemplo

int incomingByte = 0; // para la entrada de datos serie void setup() { Serial.begin(9600); // abre el puerto serie, configura los datos a 9600 bps } void loop() { // envia datos sólo cuando se reciben datos: if (Serial.available() > 0) { // lee el byte de entrada: incomingByte = Serial.read(); // di lo que tienes: Serial.print("I received: "); Serial.println((char)incomingByte, DEC); } }
  • Type "HELLO" on Serial Monitor and click Send button:
  • COM6
    Send
    Autoscroll Show timestamp
    Clear output
    9600 baud  
    Newline  
  • The result on Serial Monitor:
  • COM6
    Send
    I received: H I received: E I received: L I received: L I received: O I received:
    Autoscroll Show timestamp
    Clear output
    9600 baud  
    Newline  

※ Nota:

Serial functions are not only used for the communication between an Arduino board and Serial Monitor of Arduino IDE but also used for the communication between:

  • An Arduino board and other Arduino board
  • An Arduino board and other sensors/devices
  • An Arduino board and computer (any Serial software on computer)

Ver También

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.

※ OUR MESSAGES

  • We are AVAILABLE for HIRE. See how to hire us to build your project
  • Any suggestion, correction, and translation? please email us at ArduinoGetStarted@gmail.com, We appreciate it
  • We mainly keep improving the references in English. See English version of this page for the latest update.