Skip to content

Instantly share code, notes, and snippets.

@topshed
Last active May 20, 2018 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save topshed/0d7b971825d002d3c8b6ed6aa3b67e6d to your computer and use it in GitHub Desktop.
Save topshed/0d7b971825d002d3c8b6ed6aa3b67e6d to your computer and use it in GitHub Desktop.

Buttons and the Serial monitor

What about if you want to find out what the Arduino is doing? You can communicate with it using the Serial Monitor.

In this example, use an Digital pin as an input to detect when a button is pressed.

Imgur

When the button is pressed the input value changes from 0 (LOW) to 1 (HIGH) and you can write this value to the Arduino's serial port.

Imgur

To see these messages, run Tools -> Serial Monitor from the Arduino IDE.

Imgur

Imgur

Use an "if" conditional to adjust the message written to the Serial port so that it says something more helpful

Imgur

Challenge

Add an LED and program the Arduino to turn it on when the button is pressed

Some very small Arduinos like the Trinket don't have a Serial port. Can you use an LED to indicate when the button is pressed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment