Talk to the Arduino from your laptop. Listen to what the Arduino is thinking. By the end of the week the Serial Monitor is your standard debugging fixture and you can print sensor readings, internal state, and timing information from any sketch.
Reading (~45 min)
- Arduino reference for
Serial.begin,Serial.print,Serial.println,Serial.read,Serial.available - Optional: the SparkFun "Serial Communication" tutorial. Understand UART framing at the bit level (useful for NET-101 later)
Lecture (~1.5 hr)
- What Serial is. A simple text-over-USB protocol the Arduino IDE provides. Your sketch writes strings to the Serial port; the IDE's Serial Monitor displays them; you can also send text back from the Monitor to the sketch
- Baud rate. The data rate. 9600 is conservative and reliable; 115200 is faster and works for most modern setups. Pick one in setup() with Serial.begin(rate); the Monitor's baud setting must match
- Serial.print vs Serial.println. print writes without a newline; println writes with one. Use println for human-readable output; use print + intermediate punctuation for compact tabular output
- Reading from Serial. Serial.available() tells you how many bytes are waiting. Serial.read() returns one byte (as an integer). For multi-character commands, you typically read until a newline or other delimiter
- Debug-print discipline. Print sparingly. Too much output is hard to read. Use prefixes ("DEBUG:" "SENSOR:") to separate categories. Comment out (or wrap in
#if DEBUG) prints you no longer need
Lab exercises (~2 hr)
Lab 11.1: Serial Debug. Modify your week-9 photoresistor sketch to print the analog reading every 250 ms to Serial Monitor. Add a "calibration" mode: hold a button; the Arduino captures the current reading as the new dark threshold. ~90 minutes.
Independent practice (~3 hr)
- Add Serial debug output to every sketch you have written in the course so far. Get used to having it always available; treat sketches without Serial output as incomplete from now on
- Build a two-way: send a single character from Monitor to Arduino; the Arduino responds by toggling an LED or changing PWM brightness. The Monitor's input box at the top is where you type
- Practice the print + intermediate-punctuation tabular pattern. Print 5 sensor readings per row, separated by commas. Pipe the output to a CSV-aware tool later if you want to graph the readings
Reflection prompts
- The Serial Monitor is your debugging fixture. What does it not show you? What kinds of bugs would be invisible to Serial debug output?
- Baud rate is a legacy term from telegraph and teletype machines (literally bits-per-second when transmitting raw data). Why is it still in use 60 years later?
- The Arduino can read from Serial as easily as it writes. Why do most sketches you have seen only write?
What's next
Week 12 adds the ultrasonic distance sensor (HC-SR04 or equivalent). The first sensor that gives you a real-world physical quantity (centimeters of distance) rather than a raw analog voltage. Sensors get more specific; your code becomes more application-shaped.