0
0
AutocadHow-ToBeginner · 3 min read

How to Send Data from Arduino to PC Easily

To send data from Arduino to PC, use the Serial.begin() function to start serial communication and Serial.print() or Serial.println() to send data. Connect the Arduino to the PC via USB and open the Serial Monitor to view the data.
📐

Syntax

Serial.begin(speed): Starts serial communication at the specified baud rate (speed).
Serial.print(data): Sends data to the PC without a new line.
Serial.println(data): Sends data followed by a new line.

arduino
void setup() {
  Serial.begin(9600); // Start serial communication at 9600 baud
}

void loop() {
  Serial.println("Hello PC!"); // Send text to PC
  delay(1000); // Wait 1 second
}
Output
Hello PC! Hello PC! Hello PC! ... (repeats every second)
💻

Example

This example sends the number of seconds since the Arduino started to the PC every second. Open the Serial Monitor on your PC to see the output.

arduino
void setup() {
  Serial.begin(9600); // Initialize serial communication
}

void loop() {
  unsigned long seconds = millis() / 1000; // Calculate seconds
  Serial.print("Seconds since start: ");
  Serial.println(seconds); // Send seconds to PC
  delay(1000); // Wait 1 second
}
Output
Seconds since start: 0 Seconds since start: 1 Seconds since start: 2 Seconds since start: 3 ... (increments every second)
⚠️

Common Pitfalls

  • Forgetting to call Serial.begin() in setup() causes no data to be sent.
  • Using mismatched baud rates between Arduino and PC Serial Monitor leads to garbled output.
  • Not opening the Serial Monitor on the PC means you won't see the data.
  • Sending data too fast without delay can overwhelm the PC buffer.
arduino
void setup() {
  // Missing Serial.begin(9600); causes no output
}

void loop() {
  Serial.println("Data");
  delay(1000);
}

// Correct way:
void setup() {
  Serial.begin(9600); // Must initialize serial
}

void loop() {
  Serial.println("Data");
  delay(1000);
}
📊

Quick Reference

  • Serial.begin(baud_rate): Start serial communication.
  • Serial.print(data): Send data without newline.
  • Serial.println(data): Send data with newline.
  • Use delay(ms) to control sending speed.
  • Open Serial Monitor at matching baud rate to see data.

Key Takeaways

Always start serial communication with Serial.begin() in setup().
Use Serial.print() or Serial.println() to send data to the PC.
Match the baud rate in Arduino code and PC Serial Monitor for clear output.
Open the Serial Monitor on your PC to view the data sent from Arduino.
Add delays to avoid sending data too fast and overwhelming the PC.