ArduinoTrafficLight Download 032020
ArduinoTrafficLight Download 032020
Prep Work
● Complete the “Morse Code with Arduino” lesson
Terminology
first. Make sure your Arduino Create Editor Breadboard
account is set up and works with the Arduino A board used to build electric
Uno: circuit models.
https://www.canadalearningcode.ca/lessons/m
orse-code-with-arduino/ Resistor
● Read this primer on circuits: A component that regulates the
https://learn.sparkfun.com/tutorials/what-is-a-ci flow of an electric circuit.
rcuit
● Work through the example project to get LED
familiar with the hardware and software, and A light-emitting diode (LED)
ensure everything is working correctly: emits visible light when an
http://bit.ly/arduino-traffic-light-eg electric circuit passes through
● Go over the slides for the lesson: it.
http://bit.ly/arduino-traffic-light-slides
● Print the solutions sheet:
http://bit.ly/arduino-traffic-light-solution Curricular Connections
Text-based coding, digital
Materials (per pair):
output devices, electronics,
components of an electric
● Laptop with administrator permissions
circuit, electrical components,
● Arduino Create account
PCB (printed circuit boards),
● Arduino Uno
input/output devices,
● A B USB cable (USB printer cable) to connect the
microcontrollers,
the Arduino Uno to the laptop
communication, impacts of
● Some basic electronics:
technology on societies
○ Breadboard
○ Wires References
○ 1000 ohm resistors x3
○ A red, yellow, and green LED Arduino Create
https://create.arduino.cc/
Lesson
Arduino Uno
Use the following slides for this lesson:
https://store.arduino.cc/usa/ar
http://bit.ly/arduino-traffic-light-slides
duino-uno-rev3
Introduction
Arduino Reference
Traffic lights are used all over the world to control the
https://www.arduino.cc/referen
flow of traffic. The first traffic light was installed in
ce/en/
London in 1868, before cars were created, to control
the movement of horse carriages in the area, so
pedestrians could safely cross the road. These original
traffic lights had only two colours, red for stop and
green for go. The three coloured traffic lights we know
today weren’t introduced until 1920.
Traffic lights are great examples of simple robotic systems that have had profound effects
on society.
Using the Arduino Uno and a simple circuit, we will create a model of a three coloured
traffic light. The circuit will consist of three lights - green, yellow, and red - that are each
connected to the Arduino Uno. The traffic light will be green for 5 seconds, yellow for 1.5
seconds, and red for 3 seconds.
Code Along
Open up the example project and show learners the code and physical output (blinking LED
on a circuit board).
Point out the main elements of the circuit: breadboard, LED, resistor, wires, digital pin 8 for
power on the Arduino Uno, GND on the Arduino for the electrical ground.
Have the learners pair up. Assign each pair one of the elements of the circuit to research.
The learners have 5 minutes to research their electrical component and explain it to the
class.
Walk through each of the components with the class to ensure understanding.
Show the learners the code for the example project. Notice that the code is very similar to
the Arduino Lesson 1 example project, Blink. The main differences are the variable “light”
and the setup function. Instead of setting up the built-in LED on the Arduino Uno, we are
setting up digital pin 8, which is called “light”, where the LED from our circuit is connected.
Check for understanding by asking learners what would happen if you changed the value of
‘light’ from 8 to 9?
Demonstrate the effect of changing the value of the variable ‘light’ in the code. This should
result in no lights blinking in the circuit as we are now changing the value of digital pin 9,
which is not connected to anything. Don’t forget to verify and upload the code each time
you want to show learners the effect of the change.
Activity
In this activity you’ll create a working model of a traffic light.
Assessment
● After reviewing the example project, co-construct success criteria with the class to
be used to evaluate their final projects.
● Have learners research the following programming concepts and explain how they
used them in their project: Variables, Functions, Loops.
Extensions
Program a 4 stage traffic light with the following pattern:
● Red for 3 seconds
● Red and yellow for 1.5 seconds
● Green for 5 seconds
● Yellow for 1.5 seconds
These four stage traffic lights are used in Britain and use the same 3 colours while letting
drivers know when the light will turn green.
Arduino | Solution Sheet
the blue line will be grounded through the common ground that is
connected to the blue line.
2. LED: a Light Emitting Diode emits lights when electricity passes through it.
It has a positive side (long side) and a negative side (short side).
Remember, electricity flows from positive to negative so the way you
connect the LED matters. If your LED won’t light up, try swapping the
connections.
4. Wires: Pieces of metal that are used to connect the electrical components
together to build a circuit.
a. The power pins provide power and ground to the breadboard. The
3V3 and the 5V pin are 3 volt and 5 volt power supplies,
respectively. The GND pin is the ground. This is where the circuit
ends. There are two GND pins on the Arduino Uno. One is with the
power pins and the other is with the digital pins. We will be using
the GND pin near the digital pins.
b. Digital pins can only have two states, on or off. When a digital pin is
on (HIGH or 1), it’s supplying power. When it’s off (LOW or 0), it’s not
supplying power. We can control whether the pin is on or off using
software. The digital pins are labeled 0 - 13. They can act either as
an input, receive sensor information, or output, send instructions or
power to a component, in the circuit. We will be using the digital
pins as outputs in this project. They will be supplying the LED with
power based on our software instructions.
c. Analog pins can have a variety of values beyond just off or on. They
can be any fraction between 0 and 1. The analog pins are labeled
A0 - A5.
2. Place the LED on the breadboard. The longer leg of the LED is the positive
side and is on the right side in the diagram.
6. Connect the ground rail of the breadboard to the GND pin on the Arduino
Uno.
4. The LED on the breadboard should be flashing on for 1 second and off for
1 second. (see example in slides)
2. Place the LED on the breadboard. The longer leg of the LED is the positive
side and is on the right side in the diagram.
6. Place the yellow LED on the breadboard. The yellow LED should not be in
the same line as either the red LED or its corresponding resistor. The
longer leg of the LED is the positive side and is on the right side in the
diagram.
7. Connect a 1,000 ohm resistor to the positive side of the yellow LED. The
resistor’s contacts shouldn’t be in the same line as the red LED or its
corresponding resistor.
10.Place the green LED on the breadboard. The green LED should not be in
the same line as the red or yellow LEDs or their corresponding resistors.
The longer leg of the LED is the positive side and is on the right side in the
diagram.
11.Connect a 1,000 ohm resistor to the positive side of the green LED. The
resistor’s contacts shouldn’t be in the same line as the red or yellow LED
14.Connect the ground rail to the GND pin on the Arduino Uno.