Tab Content
Tab Title
Instructions
Tab Content
  1. Find this text in the Blink code: “void loop()”
  2. Notice how the lines of code that are highlighted in the reference video correlate with changes in the LED.

STEM Connections

The next section of code begins with the text “void loop()”. The Arduino board is currently running the void loop section of the Blink program. The lines of code from the program that the Arduino board is currently running are highlighted in the Arduino software featured in the reference video. This section contains the loop function, which runs each line of code within the curly brackets over and over again.

  • When the Arduino board runs “digitalWrite(LED_BUILTIN, HIGH);”, pin 13 switches to high voltage which turns the LED on.
  • When the Arduino board runs “delay(1000);”, it pauses and does not run the next line of code for 1000 milliseconds (or 1 second). • When the Arduino board runs “digitalWrite(LED_BUILTIN, LOW);”, pin 13 switches to low voltage which turns the LED off.
  • When the Arduino board runs “delay(1000);”, it pauses for 1000 milliseconds (or 1 second) again.

The Arduino board will continue running the loop function until it is unplugged from the power source.

Tab Title
Troubleshooting
Tab Content

The function “digitalWrite(LED_BUILTIN, HIGH)” and “digitalWrite(LED_BUILTIN, LOW)” do not appear

  1. In some version of the Arduino software, pin 13 is turned on using the code “pinMode(13, HIGH);” and pin 13 is turned off using the code “digitalWrite(13, LOW);”. 
Tab Title
Implementation
Tab Content

1. It’s nice to point out there are 4 lines of code in the void loop and point out each one so they can visualize what a “line of code” is. Reiterate that the loop runs these 4 lines over and over again and say it out loud “ 1, 2, 3, 4” and when it reaches the end go back to top of the loop to “1,2,3,4…”

2. Every line of code in the loop is responsible for some action. When programming anything, every step has to be thought out and coded for. Even waiting before you do your next task is an action that needs to be coded for.

3. One way to drive the point home that each line is responsible for an action is to tell your class that you are going to pretend to be an Arduino and your class, one table at a time, will read 1 line of code within the curly brackets of the void loop. To make it more fun, you can physically walk to each table and ask them to read a line. Ask your students to read just the actual line of code, not the comments. Start at any table and ask them to read 1 line. Remember, you are the Arduino, and you react to each line.

I. Students say: “digitalWrite(LED_BUILTIN, HIGH);” or “digitalWrite(13, HIGH);” I.

  • Say: “This line means pin 13 will be high voltage which means the LED will turn on”
  • Put your hands up to indicate the LED is, then go to the next table

II. Students say “delay(1000);” 

  • Say: This line means I, the Arduino, will not read another line of code for 1000 milliseconds”
  • Ask: “how many seconds is 1000 ms?”
  • Say: " for 1 second, I can’t read another line, but I was never told to turn off” (I think it’s fun to be awkward and stare at kids a little over a second… if you go over a second you can always say you operate in a different time)
  • Wait for 1 second, then go to the next table

III. Students say  “digitalWrite(LED_BUILTIN, LOW);” or “digitalWrite(13, LOW);”

  • Say: “This line means pin 13 will be low voltage which means the LED will turn off”,
  • Put your hands down to indicate the LED is off, then go to the next table

IV. Students say: “ delay(1000);

  • Say: “This line means I, the Arduino, will not read another line of code for 1000 milliseconds.
  • Wait for 1 second, then go to the next table

V. Repeat as desired, starting from line 1 

 

4.  Another analogy you can use with your students is that of Simon says. You can even use a student volunteer or have all students play along. Think of the Arduino board as the “Simon”. When it runs “digitalWrite(LED_BUILTIN, HIGH);” that is like saying “Simon says turn on.” When it runs “delay(1000)” that is like Simon waiting 1 second to give the next command. When it runs “digitalWrite(LED_BUILTIN, LOW);” that is like saying “Simon says turn off.” And then another “delay(1000);” is like Simon waiting for 1 second again to give the next command.

Instruction Category