E&R Unit 10: Arduino

Use a programmable microcontroller to solve electronics problems

ARDUINO OVERVIEW

 Download the Bug Bot Assignment

This unit is all about digital electronics and a device called an Arduino.  An Arduino is a small programmable microcontroller that can be used to control lights, motors, servos, and other electronic components.  When tackling a problem with electronics, an Arduino lets you:

  • Build a system with lights, sensors, motors, or servos
  • Write a program that takes inputs and controls outputs

Here, we get to learn how to build simple circuits and control them with an Arduino.  We’ll start with the basics, build some more interesting and complex circuits, and then create our own small Arduino project. As we work through our Arduino challenges, we’ll go through three main parts:

  1. Watch the Introduction to Arduino, build a simple circuit, and get your first two programs running.
  2. Tackle the Arduino Challenges to learn new functions with Arduinos and the Arduino programming language.
  3. Design and build a small Arduino project: make something cool.

When you’re done you will have seen our 5th programming language of the year, and will have learned the basics of circuits and working with Arduino

PART 1: ARDUINO BASICS

(10 pts)  About 2 days

Arduinos will be a very new thing for all of us, so we’ll want to start right at the beginning.  We’ll get an introduction to electronic circuits, Arduino boards, and the Arduino programming language.  We’ll also make our first two Arduino circuits.

PART 2: ARDUINO CHALLENGES

(40 pts) About 4 days

Next, you’ll be given a list of challenges to tackle with Arduino.  Work through them in order, building more complex programs and circuits as you go.  Complete at least 8 of the challenges (or more) before moving on!

PART 3: ARDUINO MINI-PROJECT

(20 pts) About 3 days

Take a few days to design and build something cool with Arduino.  You can make a special light display, learn how to use some of our programmable LEDs, work with sensors, servos, or even robotic arms!  You can design what you want to build or choose from a list of small projects.

 Download the wiring information!

 Download the designing information!

 Download the building information!

Part 1: Arduino Basics

Getting started with Arduino

First Arduino Circuit

The first part of any new system is to get something simple working.  In this quick part of our unit we’ll get our first Arduino circuit built, attach it to the computer, and upload a pre-built program.  This will help us make sure that everything is working before we change it to make our second simple Arduino program.

GRADING & PROCESS

Take a page of notes as you watch the Arduino Introduction video and the First Arduino Program

Build and program the first and second Arduino projects (be sure to check your Port!)

 Have Mr. Benshoof confirm that your projects are working properly!

Arduino Introduction

First Arduino Project

Second Arduino Project

What’s Due In Part 1: Arduino Basics

  • Arduino Notes
  • Basic Projects
  • Benshoof’s Confirmation

Here’s what’s due in Part 1: Arduino Basics

  1. At least 1 full page of notes from the Arduino Introduction and beginning project videos.
  2.  Build both of the basic projects and get them working properly (the videos will help a lot)
  3. Have Mr. Benshoof confirm your first two working projects

Part 2: Arduino Challenges

Continue building and programming with Arduino!

Example diagrams for a Mr. BlockMan

Here you’ll find 13 small Arduino challenges that start relatively simple and build in complexity as you keep working.

GRADING & PROCESS

 Complete at least 8 of the Arduino challenges below

 Additional notes on Arduino & Arduino programming as you work through challenges

 Have Mr. Benshoof confirm each of your working challenges!

ARDUINO PROJECTS

The goal is to work through each of the Arduino Projects one at a time.  You should take your time with each to make sure you really understand it.  Once each is complete, have Mr. Benshoof approve your work!

Arduino Project 1: Blinking LED

If you’re here, you’ve probably already completed the first Arduino Project.  Good job!  If you haven’t, the walk-through assignment can be read here so that you can get it complete.

PROBLEM:   Make an LED blink on-and-off

STEP 1:  Think about it – we’ll need an LED/resistor combo, and a program that turns the light on, waits, then turns it off.

STEP 2:  Build it – build the system at the right

Project 1

STEP 3:  Program it – the program you need to write is given below:

int redLight = 12;

void setup() {

pinMode( redLight, OUTPUT );

}

void loop() {

digitalWrite( redLight, HIGH );

delay(1000);

digitalWrite( redLight, LOW );

delay(1000);

}

STEP 4:  Verify, Run, and Test your program.  Make sure your Arduino is plugged into the USB, and hit “Upload”.  The Arduino should blink briefly as the program is uploaded, and then the program will start running on its own. If everything is setup correctly, the light will blink on-and-off.

Arduino Project 2: LED Traffic Light

PROBLEM:  Create a three-light system (green-yellow-red) that turns on the lights one at a time like a traffic light.  It should work like the video below:

 Traffic Light Video

STEP 1:  Think about it – we need 3 LED/resistor pairs, one of each color.  We also need a program that turns the lights on-and-off in order.

STEP 2:  Build it.  Build the system shown to the right:

Project 2

STEP 3: Program it.  Retype the program below into the Arduino software to make the traffic light work.

int redLight = 13;

int yellowLight = 12;

int greenLight = 11;

void setup() {

pinMode( redLight, OUTPUT );

pinMode( yellowLight, OUTPUT );

pinMode( greenLight, OUTPUT );

}

void loop() {

digitalWrite( redLight, HIGH );

digitalWrite( yellowLight, LOW );

delay(1000);

digitalWrite( greenLight, HIGH );

digitalWrite( redLight, LOW );

delay(1000);

digitalWrite( yellowLight, HIGH );

digitalWrite( greenLight, LOW );

delay(1000);

}

STEP 4: Verify, Upload, and Test.  You should have a working traffic light!  Changing the order or timing of the lights is as simple as editing your program and re-uploading.

Arduino Project 3: LED Light Bar

Problem:  Make an 8-LED display bar using the 8 colors of LEDs we have available.  The LEDs should be able to all light up so we can see the colors.  An examples is shown at the right:

IMG_1315

STEP 1:  Think about it – You need more LEDs as well as some more jumper wires.  A program will be needed to turn all the LEDs on.

STEP 2:  Build it – See if you can add the new LEDs on your own!

STEP 3:  Program it – see if you can edit your program from the first project to make them all turn on!

STEP 4:  Run, test, evaluate – get your project checked off by Benshoof!

Arduino Project 4: LED Color Cycler

Problem:  Using your LED Light Bar, make a program that can cycle the colors from left-to-right.  A video of the successful project is below:

filmIcon16 Color Cycler Video

STEP 1:  Think about it!  What new thing will you need to do?

STEP 2 & 3:  It’s already built, we just need a new program.  This could be tricky!

Step 4: Upload, test, and evaluate.  When you get a working project have Mr. Benshoof check it out!

Arduino Project 5: LED Nightrider Display

Problem:  Back in the ’80s there was a TV show called Nightrider.  In it, David Hasselhoff drove around in a cool car named “Kit” who that he could talk to.  They solved crimes.  It was cool.  The display on the radio had small lights that bounced back and forth when the car talked.  It was also cool.

Your problem for this mini-project is to make the LED Light Bar do the same thing, light up from left-to-right, then right-to-left, etc.  A video of the successful project is below:

filmIcon16 Nightrider Light Display

STEP 1:  Think about it!  What will be different about this compared to the Color Cycler?  What new thing will you need to program?

STEP 2 & 3: It’s already built, we just need a new program to do what needs to be done.  See what you can do!

STEP 4: Upload, test, and evaluate – let Mr. Benshoof know when it’s working!

Arduino Project 6: LED Randomizer

plusIcon16 COOL NEW THING

In Arduino, if you want to make some random numbers, you can do that with the method random( min, max ).  Using this will create a random number between the two numbers you use.  For example, if you use random( 3,7 ), then the program will generate a random number in the list {3,4,5,6}.  Note that the high number you enter is NOT a possible value for the random function!

PROBLEM:  Make a randomizer for your LED Light Bar.  Every LED should have a chance of turning on, and then should stay on for 1 second before turning off and another random LED turning on.  A video demonstrating what this would look like is available below:

filmIcon16 LED Randomizer Video

STEP 1:  THINK ABOUT IT – you’ve already built the Light Bar, you don’t need to change that.  You WILL need to use the random() function in Arduino.  You’ll also need to use some kind of variable or counter to keep track of which light is being chosen.  If you get stuck, talk to SHAWN in our class – he will have good insights!

STEP 2: BUILD it.  If you haven’t taken your LED Light Bar apart then it’s already built!

STEP 3: PROGRAM it.  This will be the challenge.  Here’s a hint:  you can store your random number as an integer variable, then use that to decide which light to turn on and off.

STEP 4:  Verify, Upload, and Test your program!

Arduino Project 7: LED Heart Beat

plusIcon16 COOL NEW THING

You can make LEDs brighter or dimmer using a different kind of write.  Instead of using digitalWrite( port, HIGH/LOW), you can use analogWrite( port, integer <256).  This will make an LED glow at different brightnesses.  For example, if I typed analogWrite( 10, 255 ) then the LED in port 10 would glow at max brightness.  If I typed analogWrite( 10, 127 ), then the LED at port 10 would glow at half brightness.

** In order for analogWrite() to work, the LED has to plugged into a pin with a ~ symbol next to it.  This includes ~3, ~5, ~6, ~9, ~10, and ~11.

PROBLEM:  Make a single LED glow brighter and softer kind of like a heart beat.  A short video file is attached below to show you what it would look like.  You have to look closely, but rather than blinking on and off, the light gets brighter and softer, then brighter and softer.

filmIcon16 LED Heartbeat Video

STEP 1:  Think about it.  We only need 1 LED, but you can leave the rest plugged in.  The tricky part here will be using the analogWrite() method.

STEP 2:  BUILD it.  There’s nothing new to build here, we can just write a new program.

STEP 3:  PROGRAM it.  This is the tricky part.  To help, I have included my program below.  If you don’t want that hint, then just don’t read it :)

int light = 11;

void setup() {

pinMode( light, OUTPUT);

}

void loop() {

for( int x = 0 ; x<256 ; x++) {

analogWrite( light, x);

delay(5);

}

for( int x = 255 ; x>=0 ; x- -) {

analogWrite( light, x );

delay(5);

}

}

 

STEP 4:  Verify, Upload, Test!

Arduino Project 8: LED Matching Heartbeats

PROBLEM:  Wire two LEDs to the analog pins (ones with the ~ symbol), and then have them get brighter and softer like heartbeats (see Project 7).  The special part is that as one gets brighter the other should get dimmer.  Then as the first one dims the other brightens.  A short video is linked below that shows this functioning.  The heartbeat rhythm is alternated.

filmIcon16LED Matching Heartbeat Video

STEP 1:  Think about it!  There isn’t anything more to build really, other than to double-check that you know which LEDs are plugged into the analog pins.  Analog pins are labeled with the ~ symbol.  Those pins are able to control the brightness of an LED.  All the other pins (ones without the ~ symbol) can only be on and off.

STEP 2:  BUILD it.  Again, nothing to build here, just check your pin locations.

STEP 3:  PROGRAM it.  This is the tricky part.  The same for loops or counters you used to make Project 7 work should also work well here.  You just need to make one analogWrite() value go up while the other one goes down.

STEP 4:  Verify, Upload, and Run it!

Arduino Project 9: LED Back-and-Forth

Problem:  Make two rows of 3 LEDs each (any color) that face each other.  Then, have each side blink together so that the left side lights up, then the right side, then the left side, then the right side, etc.  A short video is linked below so you can see it in action!

filmIcon16 LED Back-and-Forth Video

STEP 1:  Think about it!  The programming here is simple, we just need to dismantle most of the LED Light Bar and move some of the lights to another part.  The tricky part will be using multiple wires to jump to the other side.

STEP 2:  BUILD IT!  Keep in mind that we can’t put two LED’s into the same rows within the same column, then they’ll both light up simultaneously.  We’ll need one row of 3 to live in one of the 5-hole sections, and the other two to live in a different section.  Lots of wires in this one.

STEP 3:  PROGRAM it.  This part’s easy.  On and off with delays.

STEP 4:  Verify, Upload, and Run it!

Arduino Project 10: LED Rock-Paper-Scissors

starIcon SUPER BONUS PROJECT (this one’s pretty tough)

PROBLEM:  Make your two rows of LEDs play Rock-Paper-Scissors against each other.  Label (with paper) your 3 LEDs on the left as “rock”, “paper”, and “scissors”.  Do the same to the LEDs on the right.  Have the LED’s turn on-and-off together three times (like a count-down), then randomize which turns on for each side.  If they both give the same value (like both “scissors”), then both sides blink and they play again.  If the results are different, the program should decide which side won, and the winning side should blink three times before the game starts over.  A video of this project working successfully is attached below.  You should watch it a few times.  In the video, the game is played 3 times.  The first time the two sides tie.  In the second game, the left side wins because “rock breaks scissors”.  In the last game, the right side wins because “paper covers rock”.

filmIcon16 LED RPS Video

STEP 1:  Think about it!  The hard part here is the programming… but you’ll need some little paper labels for each light.

STEP 2:  Build it!  If you did Project 9 then you’ve already built it.

STEP 3:  PROGRAM IT!  This is the hard part. Hint:  It will take a complicated series of “if” statements to figure out which side won.  When you’re checking, you can use the combined symbols “&&” and “||” to mean “and” and “or”.  Talk to SHAWN if you need some help getting through this one!

STEP 4:  Verify, Upload, and Test!  Good luck!

ARDUINO PROJECTS PART 2: BUTTONS

For the second phase of our Arduino Projects, the tasks start to include more components and get more complicated.  As you work on these, take careful note of the diagrams provided (there aren’t many), or the programs provided (also not many).  Success on these next projects will come from careful thought, note-taking, and problem-solving!

Arduino Project 11: PUSH BUTTON light switch

PROBLEM:   Make a push button control a single LED.  The light should come ON when the button is being held down, and then turn back OFF when the button is released.  A video of this working is shown below:

filmIcon16 Push Button Video

STEP 1:  Think about it – we’ll need an LED/resistor combo,a push button switch, and a program.

STEP 2:  Build it – built a simple system that allows the push button to interrupt the flow of electricity.  The easiest place to put this is between the ground row on your breadboard and the ground pin on the Arduino.

STEP 3:  Program it – the program you need to write will not talk to the button at all.  Instead, the button will be used to interrupt the circuit.  We could describe this button as being hard-wired rather than programmed to do its job.

STEP 4:  Verify, Run, and Test your program!

Arduino Project 12: PUSH BUTTON toggle

PROBLEM:  Create a button system that uses the button to turn the light(s) on, then pushing it again will turn the lights off.  This is different from Project 11, because in Project 11 the button had to be held down in order for the lights to remain on.  Here, the button is clicked and the program knows to leave the lights on.  A video of this working is below:

filmIcon16 Push Button Toggle Video

STEP 1:  Think about it – we need our lights as always, as well as a button.  This button will need to be wired up differently so that it can talk to the Arduino as an INPUT.  Also, our program will need to handle the button’s input as well.

STEP 2:  Build it. Leave your lights where they are, but add the button to your breadboard as shown on the right.  This is different than simply interrupting the circuit like we did in Project 11.

STEP 3: Program it.  ADD the new parts given below to your program.  You’ll need to also include information about  your lights… this is just meant to give you an idea:

int button = 13;

int lightOn = 0;

void setup() {

pinMode( button, INPUT );

}

void loop() {

if(lightOn == 0 && digitalRead(button)==HIGH) {

lightOn = 1;

delay(500);

}

else if(lightOn == 1 && digitalRead(button) == HIGH) {

lightOn = 0;

delay(500);

}

if(lightOn == 0) {

//enter your own code to turn the light(s) off

}

else if(lightOn == 1) {

//enter your own code to turn the light(s) on

}

 

}

STEP 4: Verify, Upload, and Test.

Arduino Project 13: PUSH BUTTON Counter

Problem:  Make a push button control the number of LEDs that are lighting up.  Each time you push the button another LED should turn on.  When they are all lit up, another button push should turn them off so it can all start over again.  A video of this working is linked below:

filmIcon16 IMG_1351

STEP 1:  Think about it – You’ve already got a row of lights and a button wired up.  This is mostly a programming challenge!

STEP 2:  Build it – As long as you have multiple lights, then there’s nothing new to build for this one – just move on to the programming!

STEP 3:  Program it -this is the tricky part.  hint:  use the button to increase the value of a variable or counter.  Then, use the value of that variable/counter to tell your program how many lights to turn on.  This is a tricky one – don’t give up!

STEP 4:  Run, test, evaluate – get your project checked off by Benshoof!

What’s Due In Part 2: Arduino Challenges

  • Arduino Challenges
  • Arduino Notes
  • Mr. Benshoof’s Check-off

Here’s what’s due in Part 2: Sketching

  1. At least 8 completed Arduino challenges
  2. Extra notes from each challenge to make some helpful reminders
  3. Have Mr. Benshoof check-off each challenge as you complete it

Part 3: Arduino Mini-Project

Make something cool with an Arduino

Arduino Project Overview

For the last short part of this unit, you have the freedom to build what you’d like with Arduino.  If you’d prefer, you can continue working on the Arduino challenges from part 2.  If you want something new to work on, you can look through the mini project guidelines to choose a project to create, or you can come up with your own idea completely!  Document your process, and be ready to share with your classmates!

GRADING & PROCESS

 Proper documentation in your engineering notebook of your chosen project, your process, and a picture of what you ended up building.

 Build your project and get it working properly.

 Share your work with your classmates at the engineering roundtable.

 Have Mr. Benshoof check-off your completed project.

What’s Due In Part 3: Arduino Project

  • Notebook Documentation
  • Build Your Project
  • Communicate Your Work
  • Mr. Benshoof’s Check-Off

Here’s what’s due in Part 3: Arduino Project

  1. Notes in your engineering notebook that document your process.
  2.  Build your project and get it working.
  3.  Communicate your work in our engineering roundtable.
  4.  Have Mr. Benshoof check-off your completed project.

Double Check: Unit Expectations

Check what you need to have completed by the unit deadline

The purpose of this unit is to give an exposure to some simple digital electronics concepts.  For those that really enjoy this, we have an entire class devoted to digital electronics that you can take in the future!  You should have learned how to build some simple circuits with a breadboard, how to wire in your Arduino, and how to program in the Arduino language.

Engineering Notebook:

(Part 1) You should have taken at least 1 full page of notes on the Arduino basics Arduino programming.

(Part 2) You should have additional notes on your completed Arduino challenges for future reference.

(Part 3) You should have written at least 1 page of notes documenting your work on the Arduino project.

Building & Making:

(Part 1) Complete the first two basic Arduino challenges

(Part 2) Complete at least 8 Arduino challenges

(Part 3) Build your project and get it working correctly

 (Part 3) Share your work with your classmates

Benshoof Checkpoints

 (Part 1) Have Mr. Benshoof confirm your first basic challenges

(Part 2) Have Mr. Benshoof confirm each of your main Arduino challenges

(Part 3) Have Mr. Benshoof check-off your working project