Day 2

Introduction

Today I learned how to receive input from the Serial Monitor in Arduino. This helps the Arduino interact with the user by receiving commands or data typed from the computer.

What I Did

New Concepts and Functions

Challenges

I had some confusion with Serial.readStringUntil() needing a char instead of a string, but I fixed it by using single quotes (e.g. '\n').

Code Snippets


void setup() {
  Serial.begin(9600);
  Serial.println("Enter your name:");
}

void loop() {
  if (Serial.available()) {
    String name = Serial.readStringUntil('\n');
    Serial.print("Hello, ");
    Serial.println(name);
  }
}
    

Conclusion

Receiving input from the Serial Monitor opened up new possibilities for interaction. I’m looking forward to controlling LEDs or sensors using typed commands next.

🏠 Home ⬅️ Previous Day ➡️ Next Day