Download Lesson Plan - Denver Public Library

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Ground loop (electricity) wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Surface-mount technology wikipedia , lookup

Opto-isolator wikipedia , lookup

Transcript
Lesson Plan
Arduino:
Traffic Light
A student with no experience working with circuitry and little experience working with coding learns the
fundamentals of using Arduino hardware.
Learning Objectives
At the end of the class, the student will:



Understand what a circuit is.
Be able to identify the hardware used in a circuit.
Be able to identify the similarities and differences between C++ and python (or other coding languages
you may have previously covered).
Materials
 7 Arduino Uno’s
 7 Breadboards
 21 - 35 Resistors (I used 200 ohm resistors)
 49 - 63 Jumper Wires
 7 Green LEDs
 7 Yellow LEDs
 7 Red LEDs
 7 Purple LEDs (suggested, not necessary)
 7 Blue LEDs (suggested, not necessary)
 7 Chromebooks.
Estimated Budget: $0 when borrowed from CTC
Room Setup




Push several tables together with chairs around them.
Charge and log into 7 Chromebooks.
Open the Chromebooks to codebender.cc and setup the website.
o You will need to add the app to Chrome. Make sure you log into the website and add the app
before class begins.
Setup each station with an Arduino Uno, a breadboard, 7 jumper wires, a red LED, A yellow LED, a
green LED, and 3 resistors.
Program Outline
The program is completed in one (120) minute session.
(5) Explain the project for today



Making a traffic light.
Made up of several circuits.
Once we have the hardware setup, then we’ll code it so the hardware knows what to do!
COMMUNITY TECHNOLOGY CENTER
10 W
14th
Ave Parkway | Denver, CO 80204 | 720.865.1706 | https://denverlibrary.org/ctc
08/13/2015 | sl | Page 1
(5) Explain a circuit



+ electricity
- electricity
Explain to the students that a circuit is when we take electricity in a loop to make something happen –
like turn on a light. Use your awesome skills of an artist to draw something like this on a board:
(5) Explain components






Arduino board - The motherboard of the operation. It’s where the code you write will live and what
generally controls the whole set of circuits you create. Basically, it’s an open source microcontroller that
is relatively easy to program.
Breadboard - Allows you to expand your circuitry from the Arduino board. Huzzah possibility!
Resistors - control the flow of electricity so you don’t blow out your components. Yay!
LEDs - light emitting diodes. They emit light.
o What is the difference in your circuit between a resistor and a diode? Resistor doesn’t care
about the direction of the flow of electricity. Diodes do. That’s why LEDs have a long leg and a
short leg. Power goes in the long leg (or anode) and out the short leg (or cathode). If your LED
is reversed, the circuit won’t work!
Jumper Wires - allow you to connect components to the Arduino board.
C/C++ - the language Arduino programming is based on.
(10) Software! What is the coding language?




What is codebender?
Arduino is coded in a language based on C and C++.
Walk through the code that appears when you first open codebender.
Explain all the variables:
o void = a function declaration.
o int = integer. Where data is stored. This allows you to define variables.
o pinMode = configures a specified pin as INPUT or OUTPUT.
o OUTPUT = allows the pin to provide a substantial current to the circuit. Do NOT connect to
ground or positive power.
o digitalWrite = works with pinMode to make the LED brighter or dimmer.
COMMUNITY TECHNOLOGY CENTER
10 W
14th
Ave Parkway | Denver, CO 80204 | 720.865.1706 | https://denverlibrary.org/ctc
08/13/2015 | sl | Page 2
o


Ask students what these features look like in other coding languages they know. How do you
declare a function in Python? How do you declare a variable in JavaScript?
EMPHASIZE TYPING PRECISION
EMPHASIZE THE SEMICOLON AT THE END OF ALMOST EVERY LINE
(20) Experiments with Circuits!




We’re gonna start with a simple circuit.
Put your first LED into your Arduino board
o Long leg in pin 13
o Short leg in ground
o The long leg is the anode. It needs to be on the positive side. The short leg is the cathode. It
needs to be grounded.
Plug your Arduino into your computer.
In codebender, start working on your code.
int LED01 = 13;
void setup(){
pinMode(LED01,OUTPUT);
}
void loop(){
digitalWrite(LED01,HIGH);
delay(1000);
digitalWrite(LED01,LOW);
delay(1000);
}

Every sketch for Arduino will have at least these 2 functions:
o setup ( )
 defines what’s happening on your board
 in this case, we are saying that we are going to be pushing data/energy to whatever is
connected to LED01 (which is pin 13).
o loop ( )
 you won’t keep your Arduino connected to a computer, so it needs instructions on what
to do and how to interact without you there



Click the verify code button.
Read through the errors. Help students debug problems in their script.
Most likely problems:
o Missed one or more semicolons.
o Didn’t close a function.
o Didn’t type something correctly (e.g. needed capitals instead of lowercase).
Click the upload button.
Troubleshoot any problems.
Now you should have a light on your board that turns on for one second, then off for one second. Neat!
But we want to add more LEDs to our circuit! Our ground is already used up with just one! What are we
to do!?!?!?




(25) Create more LED circuits
COMMUNITY TECHNOLOGY CENTER
10 W
14th
Ave Parkway | Denver, CO 80204 | 720.865.1706 | https://denverlibrary.org/ctc
08/13/2015 | sl | Page 3





We can use the breadboard to expand the capacity of our Arduino.
UNPLUG YOUR ARDUINO.
o Safety and all that. Talk about how it feels to be electrocuted. It doesn’t always just end with you
looking like Doc on Back to the Future. 
First run the ground.
o Jumper from GND on the Arduino board to the - channel on your breadboard.
o This makes the entire - channel on your breadboard become your ground! Neat!
st
1 Circuit
o Jumper from Arduino Uno pin 13 - breadboard hole J54
o Resistor from F54 - E54
o LED
 Long leg in A54
 Short leg in A55
o Jumper E55 to ground (- channel on breadboard)
Plug your Arduino back in.
o The light is already blinking. We didn’t write more code. What happened?
o We connected the LED through pin 13. It’s still running the code we wrote earlier!
(20) Do it all again!



Students have everything they need to create their own traffic light. Ask them to use what you’ve
already created to finish the circuits and the code for their lights.
Team safety says: MAKE SURE THEY UNPLUG THEIR ARDUINOs.
Ideally, here’s what their code will look like:
int red = 13;
int yellow = 12;
int green = 11;
void setup(){
pinMode(red,OUTPUT);
pinMode(yellow,OUTPUT);
pinMode(green,OUTPUT);
}
void loop(){
digitalWrite(red,HIGH);
delay(1000);
digitalWrite(red,LOW);
delay(10);
digitalWrite(yellow,HIGH);
delay(1000);
digitalWrite(yellow,LOW);
delay(10);
digitalWrite(green,HIGH);
delay(1000);
digitalWrite(green,LOW);
delay(10);
COMMUNITY TECHNOLOGY CENTER
10 W
14th
Ave Parkway | Denver, CO 80204 | 720.865.1706 | https://denverlibrary.org/ctc
08/13/2015 | sl | Page 4
}

And here’s what their board will look like:


Walk around the room and assist students who are struggling.
Most common problems:
o LED turned the wrong way
o Circuit not grounded
o Problems with code (listed above)
(30) Independent practice






Hand out purple and blue LEDs. Ask students to add them to the sequences.
Demonstrate how to write your own function. Instead of having all of the digitalWrite( ) & delay in the
loop function, make a new function called changeLights( ). Move all of the content currently in the loop
to changeLights( ) and call changeLights( ) in the loop function.
Ask students to make new functions to have the lights do different things. Make sure they call them in
the loop.
o Make all the lights come on at once and turn off at once.
o Make each light turn on in sequence without turning any off. Make them turn off in sequence.
Demonstrate how to make a comment in the code. Ask students to make comments in their code telling
you what each section of code does. If they are really ambitious, have them define each line.
Ask students to adjust the code to make some lights flash longer than others.
Remind them they have to re-upload the code every time they make a change to see the effect of the
change.
Instructor’s Notes
COMMUNITY TECHNOLOGY CENTER
10 W
14th
Ave Parkway | Denver, CO 80204 | 720.865.1706 | https://denverlibrary.org/ctc
08/13/2015 | sl | Page 5
1. We use Chromebooks. If you use laptops instead, download and install the Arduino software on each of
your computers. Link below.
Links
Learning Arduino coding vocabulary: https://www.arduino.cc/en/Reference/HomePage
Arduino software: https://www.arduino.cc/en/Main/Software
Explanation of Arduino by Make: https://www.youtube.com/watch?v=CqrQmQqpHXc
COMMUNITY TECHNOLOGY CENTER
10 W
14th
Ave Parkway | Denver, CO 80204 | 720.865.1706 | https://denverlibrary.org/ctc
08/13/2015 | sl | Page 6