Learn to Program in C++ with Arduino – SCOPES-DF

Lesson Details

Age Ranges*
Fab Tools*
Standards
Fab-Programming.1, Fab-Programming.2, Fab-Programming.3
Author

Author

Corey Rice
Corey Rice
K-12 teacher
High School Science and Engineering teacher for 10 years. 2017 Fab Academy Graduate. Science Olympiad Coach. Active and relentless builder of things and relationships. Read More

Summary

A large part of learning Arduino for most people, is getting started with coding. These lessons offer explorations of some of the core concepts of reading and writing Arduino code.

What You'll Need

Arduino Uno (but most any type of Arduino or clone will do)

Computer with Arduino IDE installed or Arduino Create web-based IDE or Chromeduino2 for Chromebooks

USB cable (to attach the Arduino to the computer)

**Any collaboration on writing or editing the main documents of this lesson would be appreciated. Direct message Corey Rice to engage in improving these primary documents.

The Instructions

The Main Document

Background information and springboard for following exercises

This document was written in an effort to get students started programming with Arduino. In my high school level Engineering course, later work is contingent upon being able to read and write code for Arduino.

Learn to Code with Arduino (main document)

Students should read this document to get oriented with the Arduino IDE and understand some of the overarching concepts. Toward the end of the document, there is some supporting information that leads students through the corresponding exercises. Each of those exercises have their own separate document, which can be assigned to students via Google Classroom, Schoology, or whatever your local Learning Management System is used at the institution where you teach. Nontraditional learning institutions may want to simply point self-motivated students to the document linked above, and let students go at their own pace. Same for any adult who wants to learn.

Folder of Student Exercises

The corresponding exercises are a series of investigations of (mostly) separated topics, that students can work on at their own pace. These exercises lend themselves to student-driven individualized learning, and full student engagement. Ideally, a classroom teacher could assign these exercises and then let the students work individually. The teacher would then spend the class time answering questions as students come upon them, rather than delivering whole-group lectures on these computer science concepts. It is critical that students be encouraged to try experimenting and tinkering with the code in order to determine how it works.

Since students will advance at their own pace, the time for any student to complete all of these assignments can vary quite a bit. However, it is reasonable to expect a student to finish these assignments faster as they progress through them. About two hours per exercise is a moderate expectation for high school students who are reasonably engaged and responding to every item. *Students will need to know how to take a screenshot on the computer they are using, if they will turn in these exercises as written.

Exercise 1: Using the Arduino for Math

Getting oriented while working on something fairly familiar

#1 Using the Arduino for Math

Students will complete the first exercise, which requires them to get oriented in using the Arduino with their computer and the IDE. It also has them get acquainted with the format of the upcoming exercises and the processes required while they still work on concepts that should be largely familiar to them. (The hope is that the math itself is not the stumbling block for students, and they focus on mastering the Arduino/ Computer Science tasks in this exercise.)

Exercise 2: Boolean Logic

The basics of 'if()' and 'else' as handled by Arduino

#2 Boolean Logic

The concepts covered in this exercise may be the least familiar to many students new to computer science. For that reason, it may take some longer than they expect and more effort. This is the time for the teacher to take on the role of cheerleader and encourage students to keep trying to experiment with the code on the Arduino and Serial Monitor until they reach an understanding of how these concepts work.

Exercise 3: While Loops

The simplest conditional loop

#3 While Loops

While loops are common in physical computing, and so they deserve to be ‘near the front’ whenever working with Arduino. These exercises also teach the core concepts of looping functions, which is needed to fully understand the ‘void loop()’ that prominently appears in Arduino programming. This exercise will likely take much less time than the Boolean logic exercise that preceded it.

Exercise 4: Arrays

Making and using lists of data

#4 Arrays

Lists of information are a part of how humans understand things. Computer Science handles lists with arrays (among other things). Once mastered, arrays are incredibly valuable ways to control complex things or multi-step actions.

This concept will likely have students re-investigating the syntax needed to control things. Since arrays have their own syntactic rules for setting and getting values, this is to be expected.

Exercise 5: For Loops

An increment based loop, with a planned exit

#5 For Loops

For loops are a great way to control things in programs and, paired with the power of arrays, they can provide some of the most elegant solutions to the problems of physical computing.

At this point students may have hit their stride with these exercises, or be in serious need of encouragement. Ideally, students should be able to start seeing larger patterns in programs and be asking more abstract questions about what is going on in a given example program.

Exercise 6: User Defined Functions

The power to simplify programs by writing reusable functions

#6 User Defined Functions

Any time something needs to be done repeatedly or segmented into pieces, functions can save the day. This also serves as a reason to further investigate the ‘void setup()’ and ‘void loop()’ functions of Arduino. As well as a primer for more advanced concepts like Object Oriented Programming, Variable Scope, and Arduino Libraries.

This concept is more abstract than the previous exercises, and the teacher should expect students to start asking questions about what is going on with the code. Progress may slow.

Exercise 7: Variable Scope

Not all variables are global, and that's a good thing

#7 Variable Scope

Variables are one of the first concepts you need for these exercises, but they have some advanced concepts attached to them. Understanding the difference between global variables and local variables is a key concept to implementing User Defined Functions and more advanced program structures.

Exercise 8: Readability & Maintainability

Some style choices can be made while writing code, that do more than make it look good

#8 Readability & Maintainability

As you get better at writing code, there are some good moves you can make to improve the code you write. These things include: well placed comments, clever naming of variables, writing code the minimum number of times, and consolidating values to a minimum of variables.

Exercise 9: Object Oriented Programming

"A Classy Solution" --Adafruit.com

#9 Object Oriented Programming

After a person learns how to write code that follows in chronological order, they will eventually want to consolidates their code for maintainability and expand-ability. OOP lays the foundation for all Arduino Libraries and many other programming languages.

If everything students learned before this exercise was learning to add and subtract, learning OOP is analogous to learning how to multiply and divide. [Functional programming is analogous the derivative and integral.]

These are the most advanced concepts covered by these exercises. Expect students to struggle, and have many questions. If you are running these exercises as a unit with a time limit, not all students may make it through this exercise.

Exercise 10: Arduino Libraries

Many nice people have already written code, and shared it with you

#10 Arduino Libraries

The good news is that this exercise is much easier than the one that preceded it. All a student needs here is to see how to implement some OOP, not how to write it from nothing.

Standards

  • (Fab-Programming.1): I understand the basic structure of a simple program and can modify values, variables, or other parameters to alter its output, function, or behavior.
  • (Fab-Programming.2): I can create a program with more than one instruction.
  • (Fab-Programming.3): I can create a program with multiple instructions and branching elements as well as reading / controlling inputs and outputs on a microcontroller board.

Lesson Feedback

2 Reviews

  1. maïa February 20, 2019
  2. SCOPES-DF March 8, 2019
Load More

Contact us

Having trouble? Let us know by completing the form below. We'll do our best to get your issues resolved quickly.

"*" indicates required fields

Name*
Email*
This field is for validation purposes and should be left unchanged.
?