1.4: Introduction to Electronics - LED Circuit
- Page ID
- 370901
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)hypothes.is tag: s20iostiot4ualr
Download Assignment: S2020iot04
Learning Objectives
Students will be able to:
Content:
- Access the GPIO on the Raspberry Pi
- Build simple circuits
- turn an LED on and off with BPIOzero
Process:
- write code that turns on LED lights
Prior Knowledge
- Python and IoT concepts from previous activities
Further Reading
Task 1: Electricity and Electric circuit basics
The first link should be read in its entirety and the second two links as needed. Be sure to watch the videos in the Sparkfun link.
- https://learn.sparkfun.com/tutorials/voltage-current-resistance-and-ohms-law/al
- https://www.nde-ed.org/Physics/Electricity/electriccharge.xhtml
- http://hyperphysics.phy-astr.gsu.edu/hbase/emcon.html#emcon
Model 1: GPIO Pins
General Purpose Input/Output on the Raspberry Pi:
Your raspberry pi has a set of bi-directional input/output pins that allow you to interact with the physical world. There are two ways to address the numbers: Broadcom (BCM) pin numbering and board numbering. Board numbering goes from 1-40 corresponding to the pins on the device. Any pin marked GPIO can be used for input and output. Some pins are reserved as power outputs, electrical grounds, or for other purposes.
Critical Thinking Questions:
- What are the board numbers for GPIO pins that are closest to the USB ports on your Raspberry Pi?
- Provide the board pin number(s) for each of the following:
- Which board pins (numbers) provide 5V of electrical power potential?
- Which board pins provide 3V of electrical power potential?
- Which board pins are electrical ground?
- How many GPIO pins are available on your Raspberry Pi?
- What colors are used to represent
- Ground
- 5V
- 3V
- Input/output
- You have connected a device to board number 11. What GPIO number will you refer to for programming purposes?
Note
Whenever connecting/disconnecting items from your Raspberry Pi, you should always power off first to protect the Pi computer
Task 2: Setting up Pi and Cobbler
Setting up your Raspberry Pi to build circuits requires us to use prototyping board called a breadboard. Connect your cobbler to the 40 pin ribbon connector. Make sure your pins are not bent, and that the cobbler starts at line 1 of the breadboard.
If this is the first time setting up a breadboard you should watch the following video.
Companion video available here: https://youtu.be/Ljd3dpfa1JQ
The cobbler lets us connect the breadboard easily to the raspberry Pi. At this point, boot up your Raspberry Pi.
Note
There are two common types of cobblers, those with power pins (like the Vilros Cobbler) and those without power pins (like the AdaFruit Cobbler)
- Vilros Type cobbler that has 3.3V and 5V pins for the outer power rails
- Adafruit Type cobbler, which does not have these pins built into it, and so you need to run a line to the power rails
Task 3: Building your First Circuit
In this activity you will connect a red LED to a circuit on the bread board with either a 220 or 330 ohm resistor. The resister is needed to reduce the urrent so you do not burn out the LED (V=IR). Before building your first circuit watch the following YouTube. Then follow the procedures below for a Vilros Cobbler (part A) or an AdaFruit cobbler (part B), depending on which type of cobbler you have
Companion video available here: https://youtu.be/R-u0DTWCcXk
A. Vilros Type Cobler
- Start by placing one end of a black male-to-male jumper cable in the negative (ground) line connected to 3v3 of your vilros cobbler. Connect other end of the jumpber to slot 30a.
- Slightly bend a 330 ohm resistor to make a U shape. Put one end in the 30b slot, and the other end in the 34b slot.
- Take a red LED and connect the short end (cathode) to slot 34c. Connect the long end (anode) to slot 36c.
- Place one end of a red male-to-male jumper cable in slot 36a.
- Place the other end of the red jumper cable in the 3v3 + line.
B. AdaFruit Type Cobbler
- Start by placing one end of black male-to-male jumper cable in the negative (ground) line and connect it to a GND on the Adafruit Cobbler.
- Place one end of a red male-to-male jumper cable to the positive (+) line and connect it to 3V3 (Pin1) on the cobbler.
- Place one end of a black male-to-male jumper cable in the negative (ground) line connected to 3v3 of your cobbler. Connect other end of the jumper to slot 30a.
- Slightly bend a 330 ohm resistor to make a U shape. Put one end in the 30b slot, and the other end in the 34b slot.
- Take a red LED and connect the short end (cathod to slot 34c. Connect the long end (anode) to slot 36c.
- Place one end of a red male-to-male jumper cable in slot 36a.
- Place the other end of the red jumper cable in the 3v3+ line.
Note
For all subsequent builds with the Adafruit type cobbler you will need to hook up the power lines as in step 1 & 2. For the rest of the activities in this lesson you need to keep the cables to the 3.3 V pin connected, although in some subsequent activities you will be running power through the 5 V pin.
Important! If you don’t have a resistor in this circuit, you will send too much electricity to the LED. It will light up once briefly, and then not work again (much like a blown fuse or light bulb)!
Once you have built your circuit answer the following Critical Thinking Questions.
Critical Thinking Questions:
- What happened to when you connected the red jumper to the 3v3 line?
- Disconnect the end of the black jumper from the ground line leaving the other end in slot 30a.
- What happened? Why?
- Reconnect the black jumper to any point on the 3v3 ground line. What happens if you choose different slots?
- Disconnect the end of the red jumper from the 3v3 + line leaving the other end in slot 36c.
- What happened? Why?
- Reconnect the red jumper to any point on the 3v3 ground line. What happens if you choose different slots?
- What can you conclude about how the cobbler and the 3v3 lines on the breadboard work?
- Replace the resistor in you circuit with a different one from your kit, and test the circuit. What do you think would happen to the intensity of the light if you switched the 220 ohm resistor in this circuit to one of:
- Higher resistance (e.g. 1000 ohms)?
- Lower resistance (e.g. 100 ohms)?
- Remove the end of the red jumper from the 3v3+ line, and place it in the 5V +line. How does the difference in voltage affect the brightness of the red LED? Use the waterfall analogy to explain the differences you see.
- Disconnect the red jumper from the 5V line (leaving the other end connect to 36c). Describe what happens during each of these changes: (consult Model 1 for help)
- Connect the end of the jumper to GPIO pin 2.
- Connect the jumper to board pin 17.
- Connect it to GPIO 17. (Leave it plugged in here regardless of the outcome)
Task 4: GPIOZero Programs
Note
Included in the Raspbian OS is a library for interfacing to many simple input and output components called GPIOzero. It also has functions for more complex items such as sensors.
Remember: To stop any program from running you can use <Ctrl +C> to stop it.
Enter the following program into the Thonny IDE and run it.
IoCT Program 3.1 |
---|
|
Critical Thinking Questions:
- Change the value of each sleep line to 3. Rerun the program.
- Next to each line of code above, indicate what the statement does.
- Change your code to make a program that cycles your red light on and off 5 times.
Task 5: Add second LED Circuit
Connect a new yellow LED and resistor to create a new circuit connected to GPIO18.
Critical Thinking Questions:
- Alter your program to indicate a yellow LED is now on GPIO18, and it should blink in unison with the red light.
- Alter your program to have the yellow and red alternatively blink. That is when the red light is on, the yellow light is off.
Enter the following program and run it.
IoCT Program 3.2 |
---|
|
Critical Thinking Questions:
- Change the led.value to other numbers between 0 and 1 and rerun the code.
- What does the PWMLED function do?
Task 6: Common Anode RGB Circuit
Build the Following Circuit, Remember, whenever connecting/disconnecting items from your Raspberry Pi, you should always power off first, to protect the Raspberry Pi.
Instructions for setting up circuit in figure \(\PageIndex{4}\).
- Start by placing the LED into the breadboard. There are four legs. The longest one is the anode and will need to be connected to 3.3v on the rail. For simplicity, connect the longest leg into slot 45c. You should have one leg(pin) in slot 44c, one leg in slot 46c and one leg in slot 47c.
- Connect a 220 or 330 ohm resistor in slot 45b and jumper it directly to the 3v3 (+) rail.
- Connect a red jumper from GPIO6 to 44d.
- Connect a green jumper from GPIO13 to 46d.
- Connect a blue jumper from GPIO19 to 47d.
Note
RGB (Red Green Blue) is an additive color model based on 8 bits, see, https://rgbcolorcode.com/. (R,G,B) values of (0,0,0) corresponds to black and (255,255,255) corresponds to white. It is not important that you use slots 44-47, but the 4 pins on the common anode RGB LED are short/long/short/short, and in that order represent R/Anode/G/B. You then need to connect the Anode to hot, and the R,G & B to the gpio pins as defined in your code. The first line of code in IOCT Program 3.3 states: led=REBLED(red=6, green=13, blue=19), and so we are connecting the red to gpio6, green to gpio 13 and blue to gpio19. You can use any GPIO pin you want, as long as you properly assign it in your code.
Enter the following program and run it.
IOCT Program 3.3 |
---|
|
Critical Thinking Questions
- Next to each line of code above, indicate what that does.
- How does changing the values affect the program?
Enter the following program and run it
IoCT Program 3.4 |
---|
|
Critical Thinking Questions:
- Next to each led.color line in the code above, write the color the LED makes.
- Color mixed light in equal amounts of red and green should give a yellow light. Color mixed in equal amounts of red and blue should give a magenta/purple light. Alter the code above to have values in line 12 to have equal amounts of red and blue, and line 14 be equal amounts of red and green. Why did the original code not use equal values?
- Color mixed light in equal amounts of red, green, and blue should give a white light. Write a new program that will make the LED produce white light. Report your values to the class.