ZachLabs Arduino

Lab 0: Serial Monitor

Universal Serial Bus (or “USB”) was invented in the 1990s as an attempt to unify the various interfaces used to connect peripherals (external devices) to PCs, like PS/2 ports (keyboards and mice), parallel ports (printers and scanners), serial ports (modems), and game ports (joysticks and gamepads). USB can be used to connect almost any type of peripheral to a PC. It removes the need for manual configuration (a huge hassle in pre-2000s PCs) and even provides a modest amount of power, removing the need for external power supplies for many devices.

The downside is that USB is exceptionally complicated, at least compared to the ports listed above that it replaced. Fortunately, your Arduino includes a neat little integrated circuit called the CH340G that actually simulates a serial port (yes, the outdated one mentioned above) and allows you to send ASCII text, one byte at a time, back and forth between your Arduino and the PC using a USB cable (which also conveniently provides power to the Arduino and allows it to run).

In many of the labs that follow you will use the USB serial connection to send text from your Arduino to your PC, which can then be viewed in the Arduino IDE’s serial monitor. This is incredibly useful for debugging, as otherwise it can be very difficult to tell what an Arduino program is doing. Although it is possible to send data in the other direction (from the PC to the Arduino), you will not do that in any of these labs.

Example Program

Connect your Arduino to your PC and upload the following program:

void setup()
{
    // Open the serial connection:
    Serial.begin(9600);
}

void loop()
{
    // Print a message twice a second:
    Serial.println("Hello, world!");
    delay(500);
}

If you open the serial monitor in the Arduino IDE (“Tools > Serial Monitor”, or Ctrl+Shift+M) you should see the text “Hello, world!” (without quotes) printed to the screen twice each second. This data is sent over the USB cable, so if your Arduino is not connected to your PC you will not see any text appear!

If you are getting errors in the Arduino IDE, make sure that you have typed println with a lowercase L and not printIn with an uppercase I. The two letters look very similar in many fonts. Also, make sure that you have used double quotes like " and not single quotes like '. Although they are interchangeable in Python they mean something completely different in C. 

Learn More

Assignment

Using the program above as a starting point, create a program that prints the worst “Dad joke” you know (or can find on the internet) to the serial monitor. Use the delay() function to ensure that your joke has the correct comedic timing (i.e., delay between the joke and the punchline).

Challenge

Add an additional creative flair, like a few animated dots between the joke and the punchline to build up the suspense for someone watching. Remember that you can use Serial.print() to print text without automatically advancing to the next line.