Warmup

Theory

Look around the edges of your Arduino board and you will see a set of pins labelled with numbers 0, 1, 2, and so on. These pins are used to connect to external devices such as sensors.

Some pins also connect to devices built-in to the board. Arduino Uno boards have a built-in light emitting diode (LED) on pin 13. To turn the LED on, you will instruct the Arduino to energise pin 13 to five volts (with respect to the GND pin). To turn the LED off, you will instruct the Arduino to reduce the voltage on pin 13 to zero volts.

Set up

The link between an Arduino and your computer is a serial port. On Windows, serial ports are named using the numbering scheme “COM1”, “COM2”, “COM3”, and so on.

When you connect the Arduino via the USB port, it will be allocated a serial port number. For historical reasons, some of the numbers will already be taken, so your Arduino may be allocated something like COM3 or COM4 or a higher number.

To use the Arduino software, you must tell it which serial port to use. You can identify the exact COM port using the Device Manager control panel, but in practice the highest numbered COM port is almost certainly the right choice.

  1. Plug in your Arduino board and start up the program called “Arduino”.
  2. On the Tools menu, open the Port submenu, and select the highest numbered COM port.

Code

The Arduino computer program is an integrated development environment (IDE). Type the following code into the Arduino IDE, replacing the existing content.

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  
  // Set pin 13 to have a high voltage level (5 volts)
  digitalWrite(13, HIGH);
  
  // wait for 1000 milliseconds
  delay(1000);
  
  // Set pin 13 to have a low voltage level (0 volts)
  digitalWrite(13, LOW);
  
  // wait for 1000 milliseconds
  delay(1000);               
}

Create a folder on your computer for this workshop, and save your Arduino file into that folder under the name lesson2.

Upload the code to the board

  1. Use the “upload” button on the Arduino toolbar to load your program onto the board.

Topics for workshop discussion

Exercise

  1. Change the speed at which the light flashes.
  2. Implement a Morse code-like sequence with long and short flashes, e.g. “long long short”.

This work is licensed under a Creative Commons Attribution 4.0 International License. For comments or corrections, please contact [email protected].