Due at the start of class on Tuesday, Sept. 8th

There are two halves of Homework 2:

Part A:

  1. Watch the end of the video lecture to round out the end of class (12 minutes long)
  2. Complete and submit the quick SOS signalling assignment that is given at the end of that video

Part B:

  1. Watch some electronics lectures to learn new things (~90 minutes in total)
  2. Complete an electronics/programming assignment incorporating that learning

Detail on both parts is below.

Part A1. Watch the tail end of the lecture from class

In which we learn how to use Tinkercad Circuits for programming an Arduino. Video:

Part A2. Complete and submit the SOS signalling assignment from the end of that video

The tail end of the video asks you to blink the on-board LED following the classic SOS pattern:

. . .    - - -    . . .

Please write your code in Tinkercad to get that to work, (be sure to add the appropriate comment block1 at the top of your code), and:

a. Submit your Tinkercad “share” link to this Canvas assignment. To generate a link for your design, click “share” in the upper right corner of a Tinkercad sketch, then “Invite people.”

b. Submit your exported .ino sketch to the this Canvas assignment. To export the code from Tinkercad, click on the “Download code” button: Tinkercad export

Part B1. Watch some electronics lectures to learn new things

These lectures cover the elementary ideas behind electronics; how we can draw schematics to represent circuits; the basic mathematics that describe electrical flow in a circuit; and how to design and build a circuit to drive an external LED off of the Arduino.

If you feel like you know this stuff already, you are welcome to watch the videos at high speed, and/or skip ones that cover familiar material.

a. Electronics: schematic basics (video 16) (14 minutes)

b. Electronics: first circuit (video 17) (10 minutes)

c. Electronics: switch (video 18) (7 minutes)

d. Electronics: multple switches (video 19) (5 minutes)

e. Electronics: serial and parallel arrangements (video 20) (12 minutes)

f. Electronics: flow basics (video 21) (8 minutes)

g. Electronics: flow math (video 22) (8 minutes)

h. Electronics: solve for resistance (video 23) (10 minutes)

j. Electronics: Arduino, breadboard, LED (video 26) (9 minutes)

k. Electronics: wiring an external LED (video 27) (7 minutes)

l. Tinkercad: wiring an external LED (video 28) (4 minutes)

Part B2. Complete an electronics/programming assignment incorporating your new learning

Below is a little graph of three LEDs over time. Whenever an LED’s line appears, it’s on, and whenever it disappears, it’s off.

Just in case you’d prefer it in words: all three LEDs will be on for one second when the Arduino first starts up. Then they will all turn off for a half second. Then LED3 turns on for a half second and back off. Then LED2 turns on for a half second and back off. Then LED1 turns on for a second and back off, and then all three are off for a half second. The cycle then repeats indefinitely.

Your assignment:

Use Tinkercad to build a system where three LEDs blink in the pattern described above. The LEDs’ colors don’t matter.

Optional additional step: Make it so that every time LED1 changes status (i.e. every time it turns on or off), the Arduino sends a serial message saying so. The message stream should look like:

        LED1 is on
        LED1 is off
        LED1 is on
        LED1 is off
        ...

This Serial stuff may be new to you, but worry not—there’s a tutorial section towards the bottom of this page.

Deliverables

  1. Submit your Tinkercad “share” link to this Canvas assignment. To generate a link for your design, click “share” in the upper right corner of a Tinkercad sketch, then “Invite people.”

  2. Submit your exported .ino sketch to this Canvas assignment (same assignment as the schematic file below). To export the code from Tinkercad, click on the “Download code” button:

  3. Draw a schematic for the circuit(s) you build. You can make your drawing on paper or on the computer. Don’t worry about lines being perfectly straight, etc, but do draw clearly and legibly. You can use the schematics from in the videos above, and those which appear below on this page, as style guides. Submit the image (jpg/png/gif/tif) as another file (in addition to the .ino from above) to this Canvas assignment.

Collaboration and help

You are welcome to collaborate with your classmates, friends, etc., on this homework assignment. Look up help in any source that you find useful, including the web, reference books, whatever you’d like to use.

However:

  1. You must type out the code you use. That means that while you can copy parts of it from another source, you have to type every single letter yourself! We’re building muscle memory. (If you work with a partner, you can both have identical code, but you must both type it out yourself.) Be sure to note the sources you used (including classmates, etc.) in the opening comment block.

  2. You must build your own circuit. You can make the same circuit your friend does, but you have to actually use your own hands to make yours.

  3. You must draw your own schematic. It’s fine if it looks the same as someone else’s (I expect nearly every schematic in the class to look quite similar) but you have to draw yours yourself.

Grading rubric

Part A

points part
3 SOS signal works as described
3 proper comment block in code submission
6 total

Part B

points part
4 blinking matches assigned pattern
3 LEDs wired properly: each driven by its own Arduino output, with its own 270Ω current-limiting resistor
3 code written with correct comment block and reasonable formatting throughout
2 schematic is electrically valid and drawn with standardized symbols
2 (optional bonus) serial feedback as per specification: the correct messages at the correct time
12 total

Questions? Concerns? Write me an email! I’m here to help.


Extra tutorial-style information that you may find helpful

(Note that lots of this just reiterates what the videos above went over.)

For those of you new to electronics

There is one big wiring mistake that people sometimes make when they’re first learning this material.

Do not connect the power (which means 5V, or any other Arduino pin that is an OUTPUT) directly to ground.

In other words, no wire should directly go from 5V to GND. If you make this mistake, you may destroy the Arduino (which is a $10 loss, and not the end of the world). It is also possible to harm the computer connected to the Arduino! That can get a bit more expensive.

If at any point the Arduino or any wires attached to it become warm/hot, immediately unplug the Arduino from your computer. Check your wiring—you probably have connected power to ground somewhere.

How do I use a breadboard?

The good people at SparkFun (an education-market-focused electronics supplier) have a nice tutorial https://learn.sparkfun.com/tutorials/how-to-use-a-breadboard/ which covers what the video said plus some extra history which is interesting.

Wiring a single LED up

We drew a schematic representing how to power a single LED from the Arduino which looked something like this:

Schematic illustrating an Arduino with pin 3 connected to a 270Ω resistor, to the positive leg of an LED, back to the ground symbol. The Arduino's ground pin is also connected to the ground symbol.

If the circuit you make matches the drawing, to get the LED to light up, we simply need to tell the Arduino to “turn on” power on pin 3. This can be accomplished thusly: digitalWrite(3, HIGH);. (You can probably guess how to turn off that LED in code.)

Perhaps you’re not sure how to go about actually wiring the circuit up, though. Below, we’re going to keep referring back to the schematic, and relating each part of it to the wiring in the real world. By going systematically through the schematic, we’ll be assured of translating it into a viable and correct circuit in the world.

Choosing a different pin for driving an LED is straightforward: instead of digitalWrite(3, HIGH); you simply digitalWrite(x, HIGH); where x is your pin number of choice. Remember that each of the pins you use will need to have their pin mode set using the pinMode() command.

The walkthrough below uses pin 3 for the LED, but any digital I/O pin(s) on the Arduino will work. (Caveat: it’s best to avoid pins 0 and 1, since wiring things to those will often interfere with the Arduino’s communication with the computer.)

1. Connect Arduino pin 3 to one side of the 270Ω resistor

Schematic illustrating an Arduino with pin 3 connected to a 270Ω resistor, to the positive leg of an LED, back to the common ground; an arrow points to the connection between the Arduino pin 3 and one side of the resistor

Photograph of a jumper going from Arduino pin 3 to position A8 on a medium sized breadboard

Photograph of a jumper going from Arduino pin 3 to position A8 on a medium sized breadboard, and one leg of a 270Ω resistor plugged into position D8

Q: What color wire should I use? The Arduino does not know or care what color wires you’re using. However, you will help yourself greatly by choosing good colors; in this example, matching the wire color to the LED color will help keep things clear.

Q: Why use row 8 on the breadboard? No reason at all; this is totally arbitrary. The Arduino has no idea what row it’s plugged in to and doesn’t care about the number. It knows its own pin numbers (i.e. pin 3 in this case), but doesn’t have any way of knowing what external wiring you’ve done.

Q: Which side of the resistor should I attach to the Arduino connection, and which side to the LED connection? In the case of a resistor, which does not have “polarity,” it doesn’t matter. Either direction will work the same.

2. Connect the other side of the resistor to the positive leg of the LED

Schematic illustrating an Arduino with pin 3 connected to a 270Ω resistor, to the positive leg of an LED, back to the Arduino's ground; an arrow points to the connection between the resistor and the positive leg of the led.

Where will we make this connection, between the “other” leg of the resistor and the LED? Anywhere we want. We can hop over the center divider to the other side of the breadboard, or keep using only the left side of the breadboard; it’s a question of style rather than substantive difference.

Photograph of a resistor's short leg connecting to an LED's long leg in the same row.

Q: Which LED leg is which? The LED, unlike a resistor, does have polarity. In order for power to flow through it (and for it to light up), the power should go into the longer leg, and then out of the shorter leg. Wiring the LED backwards will not harm it; it simply won’t light up because power won’t flow through it.

Photograph of an LED, with the long leg labeled as "positive" and the short leg labeled as "negative"

3. Connect the negative leg of the LED back to the ground

Finally we make the last connection, from the negative leg of the LED to the Arduino’s ground, via the breadboard’s “power rails,” which are the columns running up the right and left sides of the board marked with + and . (In our context, the minus sign means the same thing as ground.)

Schematic illustrating an Arduino with pin 3 connected to a 270Ω resistor, to the positive leg of an LED, back to the Arduino's ground; an arrow points to the connection between the shorter leg of the LED and ground.

The blue dotted line shown above should not actually be drawn in the schematic; it’s just shown here to illustrate clearly that all of the ⏚ ground symbols are understood to be electrically connected—in this case, via the power rail on the breadboard.

It’s best to use black wires for any connections to ground; that’s just the color convention. Good color choices are very helpful when you’re trying to debug a complex circuit with lots of wires.

4. Adding more LEDs

Once you’ve got one LED wired properly, it won’t be difficult to add more of them.

Each output LED should be driven by its own Arduino pin, have its own resistor, and have its own connection to ground.

So far in this tutorial, we’ve wired a green LED to pin 3, so if you’re going to add a red LED, you can drive that LED off of any other digital Arduino pin you like (avoiding pins 0 and 1 as mentioned above).

Q: My LEDs are all working, but they’re very dim. My wiring looks fine. What’s wrong? Make sure you used the correct pinMode() command for all of the outputs you’re using.

I don’t know how to do the optional Serial part of the assignment

It is possible to tell the Arduino to communicate something back to the computer as it is running. We do this using a feature called “serial communication,” and once you get the hang of it, you’ll find it very useful.

Here’s how you implement serial communication:

1) Tell the Arduino to turn on its serial port. How? With the command Serial.begin(9600);. Since you only need to do this once, the usual practice is to put it somewhere inside of the setup, like so:

void setup(){
    Serial.begin(9600);
}

Of course your setup can contain as many instructions as you’d like; for instance, it could look like:

void setup(){
    pinMode(13, OUTPUT);
    pinMode(10, OUTPUT);
    digitalWrite(13, HIGH);
    Serial.begin(9600);
}

2) Then, as part of the instructions you’re writing, tell the Arduino precisely what text you want it to send to the computer. (If you know about console feedback then this will be familiar.) The command to tell the Arduino to transmit the text hello is: Serial.println("hello");. Therefore, the command to tell the Arduino to transmit the text LED1 is on is simply Serial.println("LED1 is on");. You will need to figure out where to put the serial commands in your code so that the Arduino transmits the right messages at the right time.

3) To see the serial messages that the Arduino is transmitting in Tinkercad, click on the “Serial Monitor” button at the bottom of the Code pane on the right. A small text area will pop up where you can see the serial data.


Footnote:

  1. This is in the syllabus, remember? Here’s a link for your convenience. You’re welcome!