.boxed { border: 1px solid green ; }

Intersection Traffic Signals: Coding to Control Series and Parallel Circuits in Grade 12 College Physics and Grade 11 University Physics

Tim McCarthy, Teacher, St. Ignatius of Loyola Catholic Secondary School, Oakville, ON
mccarthyt@hcdsb.org

Coding is an important skill for physics students to learn. Grade 12 College and Grade 11 University physics students must build series and parallel circuits, so why not use coding to control them and model an everyday, real-world situation? This can be done by first using TinkerCAD simulations, followed by construction of the simulation using real components; Arduino UNO R3 microcontroller boards, breadboards, LEDs, resistors and wires. Students have a high level of satisfaction as they complete a task that is brand new to most and learn skills that they are likely to need in their post-secondary education.

The Rationale
Some years ago, I attended a Community of Physics Teachers event at McMaster University. The five or six students, both undergrad and post-grad, who presented their research indicated the importance of coding in university physics and said that they lacked that skill upon graduation from secondary school. Since that time I have been looking for ways to include coding in my physics classes.

I wanted to find a project that would allow students to design and build their own circuits and control them using computer coding. I stumbled upon Arduino when I was looking for an easy entry into robotics for my Grade 8 daughter. A typical early project built by those in the Arduino community is the creation of a circuit that will blink LEDs on and off in various patterns. The Intersection project came from that experience.

A kit can be assembled for between $25-40. The minimum components needed in a kit are: an Arduino UNO R3 microcontroller board, a small breadboard, 12-16 330 Ω or 270 Ω quarter-watt resistors, about 25 male to male flexible jumper wires, 4-8 5 mm LEDs of each colour (red, yellow, green and possibly blue) and power source (a USB cable (A-male to B-male) such as used on many models of printers, 9 V battery with adapter or a 9 V transformer). Amazon is a good source for components or starter kits.

The UNO R3 microcontroller boards may be branded with different names. I have found reference to “Arduino”, “Genuino” and various other “clone” microcontroller boards. I have bought suppliers for the UNO R3 microcontroller boards from Robot Shop and Amazon.

I asked my daughter, then in Grade 9, to create a pattern of LEDs blinking on and off, some in series and some in parallel. The “LEDs Blinking Sample” referred to below is her creation. I tell my Grade 11 and Grade 12 physics students that the sample was created by a student in Grade 9 so they should be able to complete the project without too much difficulty. Since Semester 2 2017-2018, two classes of SPH4C Grade 12 Physics and five classes of SPH3U Grade 11 University physics led by three different teachers have completed this project. This project is evaluated as a summative assessment of learning item that contributes to their final mark.

The SPH4C Grade 12 College Physics specific expectations covered by this project are: A1.1, A1.2, A1.5, A1.8, A1.10, A1.11, A1.12, A1.13, D2.1, D2.2, D2.3, D2.7, and D3.2.

The SPH3U Grade 11 University Physics specific expectations covered by this project are: A1.1, A1.2, A1.5, A1.8, A1.10, A1.11, A1.12, A1.13, F2.1, F2.2, F2.3, and F2.6.

Why Use Arduino and TinkerCAD?
Arduino is an open-source platform that combines an integrated development environment (Arduino IDE) for program (sketch) creation with several different microcontroller boards developed specifically for the Arduino environment. The UNO R3 microcontroller is small and inexpensive, is widely used by the Arduino community and is appropriate for the Intersection project. Many tutorials and videos exist to assist the students as they learn how to use Arduino. I have provided links below, for ones that I have found useful.

The programming language for Arduino is a variation of C/C++. It is quite easy to learn quickly. The code that is created to control the UNO R3 microcontroller is called a sketch. The code for a sketch can be typed directly into the Arduino IDE but TinkerCAD allows for blocks of code to be dragged and dropped so that non-coders can also easily create working sketches. This method of coding is almost the same as that used by Scratch by MIT Media Lab. Arduino is also used in some secondary computer engineering classes and in some college courses. It may also be used in some university courses but I do not have any first hand knowledge of that.

TinkerCAD by Autodesk, the creators of AutoCAD, is a free online platform that allows for the simulation of the intersection project. The simulation includes the build and programming of the intersection circuits. The “Circuits” section of TinkerCAD is used by the students to create their projects. The students must create their own account for TinkerCAD.

The Task
Electric circuits are used to control many electrical devices in use in our everyday world. Traffic signals consist of coloured lights pointing in different directions and the electric circuit and computer coding that control the lights. Traffic signals regulate the flow of traffic through an intersection.

The students must design, simulate, construct, and analyze the traffic signals used at a roadway intersection. The complexity of the design is determined by the number of traffic directions (2-4) and the type(s) of electrical circuit(s) (series, parallel, mixed) that are used. They simulate the intersection using Autodesk TinkerCAD Circuits, which is a free program that has an Arduino simulator. The students then construct their actual prototypes using an Arduino UNO R3 microcontroller board, a small breadboard, 330 Ω resistors, coloured LEDs, and wires.

The students design an intersection, simulate the traffic signals using TinkerCAD, create the code and ensure that the simulation works properly. Diagrams, electrical schematics and a parts list are created. The students construct their intersection prototype after their simulation works successfully. Once the code is uploaded to their UNO R3 microcontroller, their intersection should operate as they have coded it. They are encouraged to video their working intersection.

The students must provide suggestions on means of improving their intersection. The students must also analyze the intersection by making measurements of current and electric potential difference using either the simulation or the constructed intersection prototype. They must provide four calculations, using the GRASS presentation format, that include the concepts of Ohm’s Law, Kirchhoff’s Current Law, Kirchhoff’s Voltage Law, and electrical power.

The students are provided a sample TinkerCAD project, SPH3U SPH4C LEDs Blinking Sample 2018 02 24, as a model. This TinkerCAD project is public. The link is provided in the “Resources” section below. The students may copy and tinker with this project to look at how the code controls the LEDs and to see how the construction is made. The code is available in the TinkerCAD project, is provided in the file “SPH3U_SPH4C_LEDs_Blinking_Sample_2018_02_24.ino” which will open in the Arduino IDE after it is placed in a folder named “SPH3U_SPH4C_LEDs_Blinking_Sample_2018_02_24”, and is provided as a Word document in the file “SPH3U_SPH4C_LEDs_Blinking_Sample_2018_02_24.docx”. The students are also given a video of the same project working. The TinkerCAD video is provided below.

The SPH3U SPH4C LEDs Blinking sample of a TinkerCAD project and an accompanying video is provided below.



The SPH4C Grade 12 College students are provided with two class periods to create their TinkerCAD simulations and to build their real intersection projects. Prepared SPH4C Grade 12 College students usually complete the build in 45-75 minutes. The SPH3U Grade 11 University Physics students are expected to complete their TinkerCAD projects at home and are give one class period to build their project. Prepared SPH3U Grade 11 University students usually complete the build in 20-30 minutes. Students who need more time use their lunch time or time after school to complete their intersection projects.

A SPH4C Grade 12 College sample of a TinkerCAD project and an accompanying video is provided below.



A SPH3U Grade 11 University sample of a TinkerCAD project and an accompanying video is provided below.



Resources
I provide the following information to my students. The Google Drive mentioned is the shared Google Drive for our class. The section on “Simulation and Build and Tips and Trouble Shooting” continues to evolve with each class as new issues are discovered and fixed. As the first class did this project, I experienced great frustration getting the UNO R3 microcontroller boards to communicate with my computer and upload code. Through trial and error and a lot of reading online, I finally found a sequence of steps that would allow my computer to upload code to many different UNO R3 microcontroller boards without any errors. The section on “Suggested Steps to Upload Code onto the UNO R3 Microcontroller Without Problems” gives the steps.

LEDs Blinking Sample
Refer to the file “SPH4C f19 U2 Str D EM d04-3 LEDs Blinking Sample 2018 09 24” found on the Google Drive. It contains the link to the TinkerCAD sample “SPH3U SPH4C LEDs Blinking Sample 2018 02 24”, a screen capture of the sample Arduino board, and a copy of the sample code. A video of the LEDs Blinking is also on the Google Drive.

Circuit diagrams

TinkerCAD



Arduino


Simulation and Build and Tips and Trouble Shooting
  1. In TinkerCAD, when LEDs are facing "upwards" the cathode (negative short leg of LED that must go back to ground on the UNO R3 microcontroller board) is on the left and the anode (positive long leg of LED that must go back to a digital pin on the UNO R3 microcontroller board) is on the right.
  2. Current can only flow in one direction through a LED.
  3. Connect only one item (leg of LED, end of resistor, wire) to any one hole in the breadboard. (TinkerCAD will allow multiple connections on the simulated breadboard but a real breadboard will only accept one connection per hole.
  4. Any item (LED, resistor, wire) that has both connections in the same row of the breadboard shorts itself out.
  5. It is suggested to use no more than two LEDs in a series or parallel.
  6. A LED that shows an exclamation point when the TinkerCAD simulation is running indicates over voltage of the LED. A 330 Ω resistor should be placed in series with the LED to prevent the LED from burning out due to over voltage.
  7. If LEDs work in the TinkerCAD simulation but appear dim on breadboard then it is likely that insufficient voltage exists for the LEDs. Blue LEDs require more voltage than red LEDs (in order from greatest to least: blue, green, yellow, red). Reduce the number of LEDs or change the colour towards red.
  8. If a LED is not operating on the TinkerCAD simulation, check for:
    1. Reversed polarity of leads of LED (remedy by flipping LED)
    2. An incomplete circuit for that LED often due to a connection being placed in an incorrect hole on the breadboard (remedy by confirming all connections are in the correct locations)
    3. A coding error (wrong pin used in code or no pin used in code or code incorrect).
  9. If a LED is not operating on the breadboard but the same LED works in the TinkerCAD simulation, check for:
    1. Reversed polarity of leads of LED (remedy by flipping LED)
    2. An incomplete circuit for that LED often due to a connection being placed in an incorrect hole on the breadboard (remedy by confirming all connections are in the correct locations)
    3. A damaged breadboard connection (remedy by using a different hole in the breadboard row).
  10. Each digital pin output acts as an individual 5.0 V DC power source. A common ground is used for all digital pins. Each digital output pin will require its own individual circuit schematic.
  11. When creating the code in TinkerCAD, use the Block and Text option. This will allow for block coding for students and allow the teacher to take the text code to create the Arduino file for the UNO R3 microcontroller board.
  12. Students must make their TinkerCAD project public and provide the URL to the teacher so that the teacher can:
    1. Confirm operation of the simulation
    2. Take the code for upload to the UNO R3 microcontroller board.
When the teacher has the code, the student may make the TinkerCAD project private again.

Suggested Steps to Upload Code onto the UNO R3 Microcontroller Without Problems
  1. Open the Arduino IDE (Arduino program) and open the sketch (code program) that is to be uploaded to the UNO R3 microcontroller board.
  2. Remove the ground wire from the ground pin to cut power from the UNO R3 microcontroller board to the breadboard as code may not upload to an UNO R3 microcontroller board that has power supplied to the breadboard.
  3. Use the USB cable to connect the UNO R3 microcontroller board to the computer.
  4. From the “Tools” drop down menu, select “Board”, mouse over to the right and left click on Arduino/Genuino Uno.
  5. From the “Tools” drop down menu, select “Port”, mouse over to the right and left click on the available COM port (if multiple COM ports appear, select the COM port for that particular UNO R3 — for example, it might be labelled as COM 10 (Arduino/Genuino Uno)). Each UNO R3 microcontroller that is plugged into a computer will be assigned its own unique COM Port number.
  6. From the “Sketch” drop down menu, select and left click on “Verify/Compile”. This will confirm that no code errors exist in the sketch (code).
  7. From the “Sketch” drop down menu (or “arrow” shortcut”), select and left click on “Upload” to upload the sketch (code) to the UNO R3 microcontroller.
  8. Provide a power source to the UNO R3. The USB cable may remain connected or an alternate source may be used, for example, a 9 V battery with the correct adapter.
  9. Reconnect the ground wire to the ground pin to provide power to the breadboard and watch the results!
If the above steps do not work, then turn close the Arduino IDE, turn off the computer, unplug all USB devices, restart the computer and begin from step 1 again.

Conclusion
Arduino is an easily accessible entry into the world of coding for physics students. Many resources exist to assist physics students as they learn to code. Most students enjoy the project as summed up by one student, “I thought it was really cool to build it on TinkerCAD and put it on the breadboard to see our own designs work.” I hope to bring Arduino into my SPH4U Grade 12 Physics course next year.

Editor’s Note: If you want to learn more about using Arduinos in physics, you should attend this year’s OAPT Conference. On May 53rd, Dwight Robinson and Geoff Shore will be leading a workshop at 10:00 that will let you try it out.
©Ontario Association of Physics Teachers Contact the Newsletter