Arduino - Basics of Electricity and Circuits
Experience
- This workshop is independent of any other workshops. No prior knowledge or experience is needed.
Requirements
- If done virtually, participants will need their own laptop and Arduino kit.
- If done in person, provide laptops and Arduino kits.
Time
- This workshop takes about 1 hour and 30 minutes to complete
Other Formats
This content is available in these other formats:
Guiding questions
- How will knowing how electronics work help you understand and improve your use of technology?
- What can you make to enhance your life? What tool can you make to do something for you, to provide information?
- Where can you find out more about electronics, working with Arduino, making things?
Workshop Objectives
At the end of this workshop, participants should know the following facts and procedures, understand the following concepts, and possess the following skills:
KNOW
The participant will know that...
- Conventional current states electrons move from positive terminal to the negative.
- Electron Flow is the term for the actual, real, physical flow of electrons, from negative to positive terminals.
- Electrical current is the rate of flow of electrons past a given point for a certain time, and is measured in amps.
- Resistors block/restrict flow of electrons
- Good resistors are glass, ceramics, wood, air
- Resistance is measured in ohms
- Conductors allow the flow of electrons.
- Good conductors are most metals like silver, copper, gold, aluminum, water
- Switches stop the flow of electrons.
- Motors create motion.
- LEDs create light. The long leg of an LED is positive and the short is negative. LEDs allow electrons to flow in only one direction.
- Photoresistors sense the amount of light.
UNDERSTAND
The participants will understand that...
- Electrical current can be understood similar to water flowing through pipes.
- Arduinos take in information from sensors (like temperature, sound, light, humidity, motion), do some logic on that info, and then do some output (like light, sound, motion).
- A breadboard makes it easy to put together a circuit by connecting positive holes in a column, negative holes in a column, and rows of holes together.
DO
The participant will be able to...
- Connect electrical components to a breadboard to make a functioning circuit.
- Write code in the Arduino IDE on a laptop.
- Send code from the Arduino software to the Arduino board.
- Identify several electrical components
- LED, resistor, button, photoresistor
WORKSHOP DIFFERENTIATION
- Beginner participants
- This workshop is geared towards those with no experience with electronics or Arduinos. The workshop facilitator should go slow enough to allow all participants to complete the steps.
- Intermediate participants
- This is really a workshop for beginners, so those with intermediate and expert knowledge may not find this a suitable workshop. If such participants remain in the workshop, praise them for their hard work in learning what they know and suggest that they can stay to help others who are struggling.
- Experienced participants
- This is really a workshop for beginners, so those with intermediate and expert knowledge may not find this a suitable workshop. If such participants remain in the workshop, praise them for their hard work in learning what they know and suggest that they can stay to help others who are struggling.
- Participants without physical resources
- Sign up for a free Autodesk account (student version) for access to TinkerCad and the Arduino Simulator in the Circuits section (as of September 2020). https://tinkercad.com
- Virtual Breadboard by Microsoft (only available for Windows OS, as of September 2020). https://www.microsoft.com/en-us/p/virtual-breadboard/9nblggh4tj3w
WORKSHOP SCRIPT
You can follow this script verbatim, or pick and choose what to talk about and how. The accompanying slide show goes along with the script. Everytime you see the [Show slide #] tag, you can go to the next slide. [Progress slide] tags let you know when to advance the animation/transition of the current slide.
Teacher Behavior |
Student Behavior |
Introduce the Workshop Facilitator
Introduce the workshop
Objectives of the workshop
|
Listen |
Participant introductions
|
|
In this workshop, we’ll go through the basics of electricity, learn about some of the components, and then put together a few circuits. Basics of Electricity
Sometimes it’s hard to grasp electrical current and what happens in a circuit because you can’t see what is happening inside the components. To help visualize the electrical concepts, you can imagine electrical current flowing through a circuit similar to water flowing through a system of pipes. 1. Electrons = water 2. Wires = pipes 3. Battery = Reservoir and pump 4. Voltage = The pump creates pressure in the system. In a house, your water pressure is usually between 50 and 80 psi. This is like the difference in electrical potential between the negative and positive side of the battery. This potential difference is called voltage. 5. Amperage = The rate that the water flows through the pump is like the rate at which the electrons travel in a circuit. 6. Resistance = making the pipe smaller or putting in a sponge or filter. Water pipes need to be all connected in order for the water to flow. If there is a break in a pipe, then the system is broken. Similarly, in an electronic circuit, all the components need to connect to each other in such a way that the electrons can freely flow from the negative to the positive side of the power source. If there is a break, the electrons don’t flow out like in a water circuit, they just don’t flow at all. Sometimes this is done intentionally, this is called a switch. Switch = intentionally opening and closing a gap in the circuit. This is perhaps the most important concept for this workshop and when working with Arduinos. If the circuit is not working, the circuit is probably incomplete somewhere. So that is the first thing to always check. Make sure everything is plugged in where it is supposed to be plugged in. Any questions so far? |
Look at slides, take notes, thoughtfully ponder how a system of water pipes is like an electrical circuit. |
The Components
|
Get out arduino kits and look at all the components as they are discussed. |
Assessment Pause for questions and assessment of knowledge and understanding. Ask questions like:
|
Ask questions or answer questions |
The Arduino IDE
Check The Board
Check The Port
Check Code and Upload
Writing Your Code
|
Download the Arduino IDE for your operating system and install. Select the correct board from the Board submenu. Connect the Arduino to the computer. Select the correct port from the Port submenu. |
Make a Circuit!
Finally, we get to do what we came here to do. Make a circuit!
Put together a circuit like this. An LED connected to a 100Ohm resistor connected to pin 12, and one lead connected to GND on the Arduino.
Next, write the code needed to turn on the LED.
Allow time for participants to put together the circuit, write the code, and troubleshoot any issues. Check in with each participant to make sure the LED turns on. Troubleshooting:
|
Connect the circuit. Write the code. Ask questions if it doesn’t work. |
Blinking Light!
Next, we’ll make the light blink. With just one more function and a few lines of code we can turn the LED into a blinking light.
After sufficient time for participants to try to write the code, and after working with participants individually to get their code working, you can progress the slide to show the solution.
Offer a challenge or exercise for further study:
|
Write code to make the LED blink. |
Assessment
|
Answer assessment questions. |
Night Light Circuit! Now we move on to the next component needed for making our nightlight, the photoresistor. Remember the photoresistor changes its resistance based on the amount of light it senses. We’ll use this ability to determine when to turn the LED on or off.
First, you’ll need to add the photoresistor to your circuit. This will need to be connected to a voltage output, the 5v pin, and to ground, the GND pin, with a 10K Ohm resistor. A third wire will connect to the photoresistor at the point where the resistor connects and then connect to analog pin zero on the Arduino, marked as A0. The Arduino can’t actually detect the amount of resistance a component is contributing to the circuit, but it can detect the difference in current or voltage. The photoresistor and the 10K Ohm resistor create a circuit called a voltage divider. Think of it as two sponges in a water pipe. If you know the flow of water going into the pipe and the “resistance” of one spong, then as the other sponge changes and you observe the new flow rate, you can calculate the resistance of the second sponge. In any case, we are able to use the change in potential current (the voltage) using the photoresistor and a second resistor, which allows us to calculate the change in resistance. We then use that number in the logic of our software to determine when to turn on the LED. |
Connect the photoresistor and 10K Ohm resistor to the Arduino following the diagram given. |
Night Light Code!
Now we can update our code in the Arduino IDE program. This sketch introduces two new programming concepts; variables and the if...else logic structure. The first, as seen on lines 3, 4, and 5 is that of creating a variable. A variable, in programming, is like a box that we put information in. There are four parts to making a variable in the Arduino language.
On line 3, we create a variable to hold the sensitivity value. The higher the number the more sensitive the nightlight is. The photoresistor will send a value from 0 to 1023. Let’s say that the amount of light in the room means the photoresistor gives us a value of 500. A value of 100 for the threshold means that when the value of the sensor drops below 400, then the LED will turn on. If we set the threshold to 20, then the LED would turn on when the photoresistor sends a value of 480. On lines 4 and 5, we create two variables that have no value. We create, or ‘instantiate’, the variables here so that we can use them later. This has to do with the scope of the variable, or which parts of the code can ‘see’ or recognize the variable and its value or not. The ‘resistance’ variable will eventually hold the value of the photoresistor everytime the code checks for it. The ‘initialPhotoValue’ will hold the value of the photoresistor when the code runs for the first time. On line 7, we start the setup function. On line 8, we set the mode for pin 12 to be output, we’ll be sending current to the LED on pin 12. On line 9, we grab the value of the photoresistor and assign the value to the variable ‘initialPhotoValue’ that we created on line 5. We want to grab the value of the photoristor here because this value totally depends on how much light there is in the room. This value is dependent upon the amount of light in the room each time the Arduino is turned on and the code is run. We use the analogRead() function, and pass zero as the parameter. This means we will read in the value of the photoresistor that is plugged into pin A0 on the Arduino. The A stands for Analog. On line 12, we start the loop function. On line 15, we read the current value of the photoresistor. This value possibly changes each time the code loops through. On line 19, we start the other new programming concept, the if...else statement. This is a logic statement that allows us to make a test of some values, and then based on the result the Arduino will run certain code. This line starts the if statement with the word ‘if’. Then in parenthesis we put the condition that is tested. In this case, we want to see if the current value of the photoresistor is less than the initial value minus the threshold. Let’s say that the current value of the photoresistor is 400, and the initial value was 645, and our threshold is 100. We can substitute those values in for the variables to test whether the equation is true or not. Is 400 less than 645 - 100? If that is true, the code on line 20 is run, or executed, and lines 21-23 are ignored. If that is false, then line 20 is ignored, and line 22 is executed. Notice the curly braces on lines 19, 21 and 23. Their purpose is similar to the curly braces used by the functions setup and loop. They let the program know what code is encapsulated, or enclosed, or belongs, to the ‘if’ or the ‘else’ part of the statement. So, if the current value of the photoresistor is less than the initial value minus the threshold, then line 20 is executed. The digitalWrite function, or method, is used to send current to pin 12 which is connected to the LED. Else/otherwise, line 22 is executed, and the digitalWrite method is used to stop current to pin 12. Troubleshooting Tips:
|
Type code into the Arduino IDE and send it to the Arduino. Cover the photoresistor with your hand, and the LED should light up. |
Assessment
|
Change the sensitivity of the circuit by changing the value of the ‘threshold’ variable in the code, line 3. |
Proclamation
Proclaim that the participants are not bonafide electrical engineers and coders! Thank each participant for coming. Answer any questions. |
Pack up and fill out survey. |
Resources
- Equipment Needed (determine beforehand if the instructor provides the equipment or if the participants must bring their own)
- Arduino kit, or Arduino with
- 1 USB cable
- 5 jumper wires, any color
- 1 LED
- 1 10K Ohm resistor
- 1 100 Ohm resistor
- 1 photoresistor
- 1 breadboard
- Laptop with Arduino IDE installed
- Power cable if needed and access to power outlet
- Slides: https://docs.google.com/presentation/d/1nAePGoZULM71w17anXhqHNs5JbMpbm6SNq2v2b3B24Y/edit#slide=id.g97cc113b5f_0_287
Assessment
- See assessment questions in the workshop script.
- Post Workshop Assessment Questions.
- These can be asked or presented as a survey on paper for quick feedback.
- What other things do you want to learn about?
- Was there anything you were hoping we would cover that we didn’t?
- Are you confused about anything that we did cover.
Homework
Take this project to the next level!
- Make the LED blink using the delay() function.
- Make a traffic light with red, green and yellow LEDs.
- Complete more experiments from
Promote
- This workshop showed you how to use an Arduino Micro controller. We have other workshops that show you how to use a Raspberry Pi. It’s very similar to a micro-controller, but the Raspberry Pi is a full computer but the size of an Arduino. So it opens up so many more possibilities.
- Throw in the DH angle, give examples of how technology is used in the humanities fields
Further Resources
- Arduino Guides and Projects
- https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-the-arduino-101genuino-101-board/all#experiment-1-blinking-an-led
- https://learn.sparkfun.com/tutorials/sparkfun-inventors-kit-experiment-guide---v40/all#project-1-light
- https://create.arduino.cc/projecthub/projects/tags/arduino
- https://www.instructables.com/Arduino-Projects/
- https://maker.pro/arduino
- https://www.hackster.io/arduino
- Arduino Software IDE
- ELEGOO Arduino Kit
- Online Arduino Simulator
- Dig deeper into how electricity works
Deeper Understanding
Q: Why are HIGH and LOW used to designate a pin as on or off?
A: https://www.arduino.cc/reference/en/language/variables/constants/constants/
Defining Pin Levels: HIGH and LOW
When reading or writing to a digital pin there are only two possible values a pin can take/be-set-to: HIGH and LOW.
HIGH
The meaning of HIGH (in reference to a pin) is somewhat different depending on whether a pin is set to an INPUT or OUTPUT. When a pin is configured as an INPUT with pinMode(), and read with digitalRead(), the Arduino (ATmega) will report HIGH if:
- a voltage greater than 3.0V is present at the pin (5V boards)
- a voltage greater than 2.0V volts is present at the pin (3.3V boards)
A pin may also be configured as an INPUT with pinMode(), and subsequently made HIGH with digitalWrite(). This will enable the internal 20K pullup resistors, which will pull up the input pin to a HIGH reading unless it is pulled LOW by external circuitry. This can be done alternatively by passing INPUT_PULLUP as argument to the pinMode() function, as explained in more detail in the section "Defining Digital Pins modes: INPUT, INPUT_PULLUP, and OUTPUT" further below.
When a pin is configured to OUTPUT with pinMode(), and set to HIGH with digitalWrite(), the pin is at:
- 5 volts (5V boards)
- 3.3 volts (3.3V boards)
In this state it can source current, e.g. light an LED that is connected through a series resistor to ground.
LOW
The meaning of LOW also has a different meaning depending on whether a pin is set to INPUT or OUTPUT. When a pin is configured as an INPUT with pinMode(), and read with digitalRead(), the Arduino (ATmega) will report LOW if:
- a voltage less than 1.5V is present at the pin (5V boards)
- a voltage less than 1.0V (Approx) is present at the pin (3.3V boards)
When a pin is configured to OUTPUT with pinMode(), and set to LOW with digitalWrite(), the pin is at 0 volts (both 5V and 3.3V boards). In this state it can sink current, e.g. light an LED that is connected through a series resistor to +5 volts (or +3.3 volts).