Web Serial Example

This is an example of how to use the Web Serial API to connect to a serial device. It will connect to a serial device at 115200 baud and print out all data that is received.

Note: This example is only supported in Chrome and works with a serial device that is connected to your computer.

Scenarios

Connect via bluetooth

To connect via bluetooth, you need to have a bluetooth device connected to your computer. After that, you can click the button below to connect to the serial device. The serial device will be connected to your computer and you can start sending data to it. You can also see the data that is received from the serial device. The serial device must be set to 115200 baud. You can change the baud rate in the code.

Connect via USB

To connect via USB, you need to have a USB device connected to your computer. After that, you can click the button below to connect to the serial device. The serial device will be connected to your computer and you can start sending data to it. You can also see the data that is received from the serial device. The serial device must be set to 115200 baud. You can change the baud rate in the code.

1. Flash your Arduino capable device

The Arduino could be programmed with the following code:

Click here
void setup() {
    Serial.begin(115200); // Start serial communication with 115200 baud
}

void loop() {
    if (Serial.available()) { // Check whether data is available
        String data = Serial.readStringUntil('\n'); // Read data up to the line break
        Serial.println("Echo: " + data); // Send back the received data
    }
}

2. Connect to the serial device

Connection

Port

Readable

Writeable
Written

3. Send and receive data to the connected serial device