Difference between revisions of "Prototyping with Microcontrollers, Sensors, and Materials (Virtual)"

From EG1004 Lab Manual
Jump to: navigation, search
(1003 --> 1004)
 
(51 intermediate revisions by one other user not shown)
Line 43: Line 43:
Resistors are color coded to indicate their resistance in ohms (Figure 3). They are not polarized, meaning the orientation of the resistor does not affect the circuit.
Resistors are color coded to indicate their resistance in ohms (Figure 3). They are not polarized, meaning the orientation of the resistor does not affect the circuit.


[[Image:resistor.jpg|center]]
[[Image:Resistor_and_symbol.png|thumb|center|375px|Figure 2: Resistor (Left) & Resistor Symbol (Right) used in Circuit Diagrams]]
<center><p>Figure 2: Resistor (Left) & Resistor Symbol (Right) used in Circuit Diagrams</p></center>


[[Image:Resistor color code.png‎|thumb|center|500px|Figure 3: Resistor Color Codes]]
[[Image:Resistor color code.png‎|thumb|center|500px|Figure 3: Resistor Color Codes]]
Line 50: Line 49:
=== Push-Buttons and Switches ===
=== Push-Buttons and Switches ===
<b>Push-buttons</b> and <b>switches</b> (Figure 4) are mechanical devices that interrupt or divert current. Basic push-buttons are polarized while basic switches are not.
<b>Push-buttons</b> and <b>switches</b> (Figure 4) are mechanical devices that interrupt or divert current. Basic push-buttons are polarized while basic switches are not.
[[Image:Lab_Push_button_Proto.png|375px|thumb|center|Figure 4: A Push Button, and its Internal Switch Circuit]]
[[Image:Lab_Push_button_Proto.png|475px|thumb|center|Figure 4: A Push Button, and its Internal Switch Circuit]]


=== Diodes ===
=== Diodes ===
Diodes allow current to only pass in one direction. The anode is the positive terminal of the diode, and the cathode is the negative terminal. Diodes can also be used to amplify signals.
<b>Diodes</b> allow current to only pass in one direction. The anode is the positive terminal of the diode, and the cathode is the negative terminal. Diodes can also be used to amplify signals.


[[Image:diode_transistor.jpg|350px|thumb|center|Figure 5: TMP36 Sensor]]
[[Image:Anode_cathode_current_flow.png|475px|thumb|center|Figure 5: A Diode and its Corresponding Symbol]]


A <b>Light emitting diode (LED)</b> is a small electric light that uses low voltage and current (Figure 7). The longer lead of the LED is the anode, and the shorter lead is the cathode. The orientation of an LED is important since they are polarized and only allow current to flow in one direction. Most LEDs also require a resistor because they will burn out almost instantly when they encounter high current.
A <b>Light emitting diode (LED)</b> is a small electric light that uses low voltage and current (Figure 6). The longer lead of the LED is the anode, and the shorter lead is the cathode. The orientation of an LED is important since they are polarized and only allow current to flow in one direction. Most LEDs also require a resistor because they will burn out almost instantly when they encounter high current.


[[Image:Lab_LED_Proto.png|375px|thumb|center|Figure 7: An LED and its Corresponding Symbol]]
[[Image:Lab_LED_Proto.png|475px|thumb|center|Figure 6: An LED and its Corresponding Symbol]]


A <b>TMP36 sensor</b> (Figure 8) uses the voltage-temperature relationship of diodes to measure temperature. The voltage across the diode of the sensor will change proportionally to the temperature. The output voltage can then be converted to a temperature reading.
A <b>TMP36 sensor</b> (Figure 7) uses the voltage-temperature relationship of diodes to measure temperature. The voltage across the diode of the sensor will change proportionally to the temperature. The output voltage can then be converted to a temperature reading.


[[Image:Lab_TMP36_sensor_Proto.png|375px|thumb|center|Figure 8: TMP36 Sensor]]
[[Image:Lab_TMP36_sensor_Proto.png|200px|thumb|center|Figure 7: TMP36 Sensor]]


== Microcontrollers ==
== Microcontrollers ==
Line 71: Line 70:
[[Image:arduino.jpg|300px|thumb|center|Figure 8: Arduino UNO]]
[[Image:arduino.jpg|300px|thumb|center|Figure 8: Arduino UNO]]


This lab will use an Arduino UNO board created by SparkFun called a RedBoard (Figure 9). A RedBoard has many of the basic functions of a computer.
This lab will use an Arduino UNO board created by SparkFun called a RedBoard (Figure 9).
   
   
[[Image:redboard.jpg|250px|thumb|center|Figure 9: RedBoard]]
[[Image:redboard.jpg|250px|thumb|center|Figure 9: RedBoard]]
Line 77: Line 76:
=== Arduino Hardware ===
=== Arduino Hardware ===


All Arduino boards have a general layout is similar to that shown in Figure 10. Not all the sections and pins will be used in this lab or for the Semester Long Design Projects.
All Arduino boards have a general layout similar to that shown in Figure 10. Not all the sections and pins will be used in this lab or for the Semester Long Design Projects.


[[Image:redboard_info.jpg|500px|thumb|center|Figure 10: RedBoard Layout]]
[[Image:redboard_info.jpg|500px|thumb|center|Figure 10: RedBoard Layout]]
Line 99: Line 98:
[[Image:Lab 5 Figure 11.png|200px|thumb|center|Figure 12: RedBoard Digital (Left) and Analog (Right) Pins]]
[[Image:Lab 5 Figure 11.png|200px|thumb|center|Figure 12: RedBoard Digital (Left) and Analog (Right) Pins]]


* <b>A0-A5:</b> Identical analog pins that can be used to read sensors or control analog devices. Pins A0-A3 are more stable than A4 and A5
* <b>A0-A5:</b> Identical analog pins that can be used to read sensors or control analog devices. Analog pins can read/write values from 0 to 1023
* <b>Pins 0-1:</b> Transmitter and receiver pins. Do not use these pins for this lab
* <b>Digital Pins 0-1:</b> Transmitter and receiver pins. Do not use these pins for this lab
* <b>Pins 2-12:</b> Digital pins that can be switched between HIGH states and LOW states
* <b>Digital Pins 2-12:</b> Digital pins that can be switched between HIGH states and LOW states. As such, they can only read/write values HIGH or LOW, unlike analog pins which allow for a greater range of values
* <b>Pin 13:</b> Connected to the onboard LED, use it only as an input pin
* <b>Digital Pin 13:</b> Connected to the onboard LED, use it only as an input pin


=== Arduino IDE ===
=== Arduino IDE ===
Line 115: Line 114:
* <b>Serial Monitor:</b> A tool used to send messages to and receive messages from the board
* <b>Serial Monitor:</b> A tool used to send messages to and receive messages from the board


== Arduino Programming ==


Programs written in Arduino are called sketches. A basic sketch can be broken up into three different areas: global, setup, and loop. These areas are pictured in Figure 14.
The <b>Arduino programming language</b> is based on C/C++, but it is designed to be simpler and easier to learn. The most intuitive way to think about programming is like building with LEGO blocks: certain rules must be followed and different building blocks can be used to build bigger parts.


[[Image:Sketchareas.jpg‎|thumb|center|Figure 14: Areas in Arduino IDE Sketch]]
Every line must end with a semicolon (;) unless it is a conditional, loop, or function. Comments start with two backslashes (//). <b>Comments</b> are text that the program ignores and are used to label and explain code.


* <b>Global:</b> Constants and imported libraries go here
=== Arduino Programs ===
* <b>Setup:</b> Activate the pins and sensors used. This code only runs once
* <b>Loop:</b> The code that runs continuously for reading sensors and turning pins HIGH or LOW


== Arduino Programming ==
Programs written in Arduino are called <b>sketches</b>. A basic sketch can be broken up into three different areas: global, setup, and loop. These areas are pictured in Figure 14.


The <b>Arduino programming language</b> is based on C/C++, but it is designed to be simpler and easier to learn. The most intuitive way to think about programming is like building with LEGO blocks: certain rules must be followed and different building blocks can be used to build bigger parts.
[[Image:Sketchareas.jpg‎|thumb|center|Figure 14: Areas in Arduino IDE Sketch]]


Every line must end with a semicolon (;) unless it is a conditional, loop, or function. Comments start with two backslashes (//). <b>Comments</b> are text that the program ignores and are used to label and explain code.
* <b>Global:</b> Constants and imported libraries go here
* <b>Setup:</b> This function will only run once, at the very beginning of the program. The setup function is often used to activate the pins and sensors that will be used in the program
* <b>Loop:</b> This function will run continuously after the Setup function. Code included in the loop function will continue to run until the Arduino loses power. This function is often used for the majority of the program, such as reading sensors and turning pins HIGH or LOW


=== Datatypes ===
=== Datatypes ===
Line 197: Line 197:
=== Loops ===
=== Loops ===


<b>Loops</b> (Figure 17) run the code enclosed by their curly brackets a specific number of times or until a condition is met. <b>While loops</b> are used to perform a task until a condition is met. In Figure 17, the while loop runs only if the state of the button is HIGH. When the state of the button becomes LOW, the while loop will immediately stop running. <b>For loops</b> are used when an action must run a specific number of times. Although they seem complicated at first, the structure of most for loops is the same. In Figure 16, the first part of the for loop sets a variable (usually i for index) to a value used to begin a count, the middle sets the condition to make the loop stop, and the third part is where the variable is incremented or decremented with each run of the loop. The first time the loop runs, i = 0 which does not meet the loop end condition (i > 10) and the code will run. At the end of the loop code, i is incremented by 1 and becomes i = 1. For the second time the loop runs, i = 1 which again does not meet the loop end condition and the code runs once again. i then becomes i = 2 at the end of the loop. This repeats until i = 10.
<b>Loops</b> (Figure 17) run the code enclosed by their curly brackets a specific number of times or until a condition is met.


[[Image:Fig15lab3.png|thumb|center|500px|Figure 17: While and For Loops]]
<b>While loops</b> are used to perform a task until a condition is met. In Figure 17, the while loop runs only if the state of the button is HIGH. When the state of the button becomes LOW, the while loop will immediately stop running.
 
[[Image:Lab_while_loop_Proto.png|thumb|center|500px|Figure 17: While Loop]]
 
<b>For loops</b> are used when an action must run a specific number of times. They are extremely useful when the code is being repeated multiple times throughout a program. A for loop has three parts: initialization, condition, and increment. Figure 18 is an example of a for loop. Here, the initialization variable is an integer i, which is set to 0. The condition for the loop is that i is less than 10. The increment for this loop is that i will increase by one every time the code is run.
 
In this example, the code within the loop will run 10 times. The first time, the value of i will be 0. The second time, the value will be 1. This will continue until i equals 10, in which it will stop executing the code. Once all the loops are complete, it will have printed out numbers from 0 to 9.
 
[[Image:For_loop_proto.png|thumb|center|500px|Figure 18: For Loop]]


=== Commonly Used Arduino Functions ===
=== Commonly Used Arduino Functions ===
Line 228: Line 236:
Tinkercad is a cloud-based, in-browser software that will be used for the simulation of microcontrollers and associated electrical components. Additionally, code can be programmed in-browser in the Arduino programming language and simulated with the virtual circuit. A link to the Tinkercad website can be found [https://www.tinkercad.com here]. You can sign into Tinkercad with your Autodesk account, which you should have created in Lab 1.
Tinkercad is a cloud-based, in-browser software that will be used for the simulation of microcontrollers and associated electrical components. Additionally, code can be programmed in-browser in the Arduino programming language and simulated with the virtual circuit. A link to the Tinkercad website can be found [https://www.tinkercad.com here]. You can sign into Tinkercad with your Autodesk account, which you should have created in Lab 1.


Once a new circuit has been created, the interface appears like that in Figure 18. Components can be dragged and dropped from the sidebar into the work area.
Once a new circuit has been created, the interface appears like that in Figure 19. Components can be dragged and dropped from the sidebar into the work area.


[[File:Vc2.png|700px|thumb|center|Figure 18: Tinkercad Interface]]
[[File:Vc2.png|700px|thumb|center|Figure 19: Tinkercad Interface]]


To simulate the program, the Code block can be opened and the code typed into it. To run the simulation with the code and virtual circuit, click Start Simulation (Figure 19).
To simulate the program, the Code block can be opened and the code typed into it. To run the simulation with the code and virtual circuit, click Start Simulation (Figure 20).


[[File:Vc3.png|400px|thumb|center|Figure 19: Tinkercad Simulation]]
[[File:Vc3.png|400px|thumb|center|Figure 20: Tinkercad Simulation]]


== Heat and Heat Transfer ==
== Heat and Heat Transfer ==
Line 240: Line 248:


<b>Heat transfer</b> is the process of thermal energy moving from one body to another as a result of a temperature difference. <b>Temperature</b> is the measure of the average kinetic energy of atomic motion. The faster the atoms are moving, the higher the temperature. The main mechanisms of heat transfer are conduction, convection, and radiation.
<b>Heat transfer</b> is the process of thermal energy moving from one body to another as a result of a temperature difference. <b>Temperature</b> is the measure of the average kinetic energy of atomic motion. The faster the atoms are moving, the higher the temperature. The main mechanisms of heat transfer are conduction, convection, and radiation.
=== Types of Heat Transfer ===


<b>Conduction</b> occurs when there is a temperature difference within a solid body or between solid bodies in contact. During conduction, energy (heat) will flow from the region of higher temperature to the region of lower temperature. Imagine a metal rod that is heated at one end. The atoms of the rod collide at the point where the temperature differs, transferring heat until the temperature of the rod becomes uniform.
<b>Conduction</b> occurs when there is a temperature difference within a solid body or between solid bodies in contact. During conduction, energy (heat) will flow from the region of higher temperature to the region of lower temperature. Imagine a metal rod that is heated at one end. The atoms of the rod collide at the point where the temperature differs, transferring heat until the temperature of the rod becomes uniform.


<b>Convection</b>  is the transfer of heat within a fluid medium (fluids consist of gasses and liquids). Convection can occur as natural or forced convection. Forced convection (Figure 20) occurs when the main mechanism for heat transfer is due to an outside force causing the fluid to move. Natural convection results from the natural difference in density between fluids, causing a liquid or gas to rise.
<b>Convection</b>  is the transfer of heat within a fluid medium (fluids consist of gasses and liquids). Convection can occur as natural or forced convection. Forced convection occurs when the main mechanism for heat transfer is due to an outside force causing the fluid to move. Natural convection results from the natural difference in density between fluids, causing a liquid or gas to rise.


[[Image:lab_hegg_2.jpg|frame|center|Figure 20: Air Circulation Diagram]]
<b>Radiation</b> is the process by which energy in the form of electromagnetic radiation is emitted by a heated surface in all directions. It does not require an intervening medium to carry it. The heating of the Earth by the Sun is an example of heat transfer by radiation. Electromagnetic radiation is a means of energy transfer that occurs when an atom absorbs energy. This electromagnetic wave can propagate as heat, light, ultraviolet, or other electromagnetic waves depending on the type of atom and the amount of energy absorbed.


<b>Radiation</b> is the process by which energy in the form of electromagnetic radiation is emitted by a heated surface in all directions. It does not require an intervening medium to carry it. The heating of the Earth by the Sun is an example of heat transfer by radiation. Electromagnetic radiation is a means of energy transfer that occurs when an atom absorbs energy. This electromagnetic wave can propagate as heat, light, ultraviolet, or other electromagnetic waves depending on the type of atom and the amount of energy absorbed.
[[Image:Types_of_heat_transfer_diagram.jpeg|475px|thumb|center|Figure 21: Conduction, Convection, and Radiation]]


<b>Color</b> is a property of light. When an object appears white, it virtually reflects all the electromagnetic waves coming to it while a black object absorbs the waves. Color (reflectivity) should be considered when choosing materials for thermal insulation.
=== Thermodynamic Systems ===


The container that will be built in the lab is a <b>thermodynamic system</b> (Figure 21), which is a part of the Universe separated from the surroundings by an imaginary boundary. There are three types of systems: open systems, closed systems, and isolated systems.
The container that will be built in the lab is a <b>thermodynamic system</b> (Figure 22), which is a part of the Universe separated from the surroundings by an imaginary boundary. There are three types of systems: open systems, closed systems, and isolated systems.


[[Image:lab_hegg_5.png|frame|center|Figure 21: Thermodynamic System]]
[[Image:lab_hegg_5.png|frame|center|Figure 22: Thermodynamic System]]


<b>Open systems</b> allow the transfer of mass and heat. For example, an open pot of boiling water is an open system. It exchanges heat and water vapor with the air around it. If collected, the water vapor can be condensed back to liquid water that has some mass.
<b>Open systems</b> allow the transfer of mass and heat. For example, an open pot of boiling water is an open system. It exchanges heat and water vapor with the air around it. If collected, the water vapor can be condensed back to liquid water that has some mass.
Line 260: Line 270:


<b>Isolated systems</b> do not interact with the surroundings at all. No exchange of heat or mass is possible. An ideal Thermos® is an isolated system. If hot chocolate is poured within, the same amount at the same temperature will be poured out later. No such system can be fabricated, but they can be approximated.
<b>Isolated systems</b> do not interact with the surroundings at all. No exchange of heat or mass is possible. An ideal Thermos® is an isolated system. If hot chocolate is poured within, the same amount at the same temperature will be poured out later. No such system can be fabricated, but they can be approximated.
[[Image:Thermodynamic_system_types.jpeg|frame|center|Figure 23: From Left to Right, an Open, Closed, and Isolated System]]
=== Designing Insulating Containers ===


Understanding how to minimize heat loss is the key to designing a successful insulating container. The first consideration is the materials chosen. Using materials that are poor conductors of heat, such as glass, will minimize heat loss. Plastic is also a poor conductor of heat. Foam cups are made of plastic that has tiny air bubbles suspended in it. Air is among the poorest conductors of heat. A vacuum, or the complete lack of air, is the best insulator of all. This is the principle employed in the Thermos® design.
Understanding how to minimize heat loss is the key to designing a successful insulating container. The first consideration is the materials chosen. Using materials that are poor conductors of heat, such as glass, will minimize heat loss. Plastic is also a poor conductor of heat. Foam cups are made of plastic that has tiny air bubbles suspended in it. Air is among the poorest conductors of heat. A vacuum, or the complete lack of air, is the best insulator of all. This is the principle employed in the Thermos® design.


The other important consideration in creating the container is its cost. Minimal design uses the fewest resources while maintaining the safety and efficacy of a product.
The other important consideration in creating the container is its cost. <b>Minimal design</b> uses the fewest resources while maintaining the safety and efficacy of a product.


= Materials and Equipment =
= Materials and Equipment =
Line 269: Line 283:
* Computer with internet access
* Computer with internet access
* Arduino IDE
* Arduino IDE
* The following are the materials that can be used in Tinkercad:
* The following are the materials that are used in Tinkercad:
** Arduino UNO microcontroller
** Arduino UNO microcontroller
** Tinkercad code block with Arduino IDE
** Tinkercad code block with Arduino IDE
Line 283: Line 297:
= Procedure =
= Procedure =


<span style="color: red;"><b>IN-PERSON STUDENTS will be following the [[Prototyping with Microcontrollers, Sensors, and Materials|  standard procedure]] for this lab, and should not be following the instructions on this page.</b></span>
<!--== 1. Starting a New Circuit in Tinkercad ==
<!--== 1. Starting a New Circuit in Tinkercad ==
Tinkercad is an online 3D modeling program and will be used in this lab to simulate the circuits.
Tinkercad is an online 3D modeling program and will be used in this lab to simulate the circuits.
Line 296: Line 309:


[[Image:breadboard.jpg|500px|thumb|center|Figure 1: Breadboard Connections]]-->
[[Image:breadboard.jpg|500px|thumb|center|Figure 1: Breadboard Connections]]-->
== 1. LED with Button Circuit ==
== 1. LED Circuit ==
# Copy the [https://www.tinkercad.com/things/ltcFAatwjUO Part 1] template to the Tinkercad workspace using the steps in Starting a New Circuit in Tinkercad.
# Copy the [https://www.tinkercad.com/things/ltcFAatwjUO Part 1] template to the Tinkercad workspace using the steps in Starting a New Circuit in Tinkercad.
## Go to tinkercad.com and sign in with an Autodesk account.
## Go to tinkercad.com and sign in with an Autodesk account.
## Open the Tinkercad link for the part of the lab you want to work on. The links are provided in the procedure below.
## Open the Tinkercad link for the part of the lab you want to work on. The links are provided in the procedure below.
## Select the Copy & Tinker option. This will copy the template to the workspace so it can be edited.
## Select the Copy & Tinker option. This will copy the template to the workspace so it can be edited.
# A circuit using an LED and a button will be made in Part 1. The LED should be on when the button is pressed, and off when the button is not pressed. The programming flowchart and circuit diagram are shown in Figures 22 and 23. [[Image:programmingflowchart.png|400px|thumb|center|Figure 22: Programming Flowchart]][[Image:circuitdiagram.png|400px|thumb|center|Figure 23: Circuit Diagram]]
# A circuit using an LED will be created in Part 1. This LED should blink on and off every second. The programming flowchart and circuit diagram are shown in Figures 24 and 25.[[Image:LED_flowchart.jpg|600px|thumb|center|Figure 24: LED Flowchart]]
# Before breadboarding the circuit, look at the button to determine which pins are connected. With an actual button, this is done by checking the bottom side (pin side) of the button (Figure 24). Note which pins are for power, ground, and digital input into the Arduino. In Tinkercad, the button is depicted with the pins extending from the sides, which shows the direction of the pin orientation.
# Wire the LED circuit as shown in Figure 25.
# Place the button on the breadboard and make sure it straddles the bridge down the center of the breadboard (Figure 24). [[Image:Lab_5_Part_2_Fritz_Diagram.png|400px|thumb|center|Figure 24: Button Circuit Diagram]]
#: [[Image:LED_circuit.png|375px|thumb|center|Figure 25: LED Circuit]]
# Wire the circuit diagram as shown in Figure 25. [[Image:breadboardcircuitdiagram.png|400px|thumb|center|Figure 25: Circuit]]
## Click and drag the LED and resistor to the breadboard as shown in Figure 25.
# Write the Arduino program to implement the flowchart. Code can be added by clicking the “Code” button at the top of the workspace. Include comments explaining what the code is doing. The code must have comments to be approved by a TA
## Click on the resistor, and set its resistance value to 220 Ω. The resistor is necessary, otherwise too much current would flow through the LED and cause it to short circuit.
## Wire the signal from digital pin 7 on the Arduino board to the LED directly. To wire these two components, simply click on a hole in the same row as the negative terminal of the LED, and click once again on the GND pin of the Arduino.
### Remember, since LEDs are polarized, their orientation matters. The shorter leg (negative end) of the LED should be connected to the same row as GND on the Arduino board.
# Write the code for the circuit as shown in Figure 26.[[Image:LED_code.jpg|375px|thumb|center|Figure 26: LED Circuit Code]]
## Click the “Code” button in Tinkercad to open the code editor. Ensure that the code type is set to Text
## The flowchart uses digital pin 7 on the Arduino board as an output, so create a constant that holds the number 7 (top line of code in Figure 25).
## In the setup area, set pin 7 as an output using pinMode (second block of code in Figure 25).
## Turn the LED on by using digitalWrite, have a delay of one second, turn the LED off by using digitalWrite, and then set another delay of one second (third block of code in Figure 25). The delays are necessary as the LED is a bit slow to react.
## Use the debugger (the small bug icon) on the Code block. This allows you to see errors in your code so you can fix them before you run the simulation.
## Fix all errors found by the debugger. Once you fix all errors, click Start Simulation.
# If the code is correct, the LED will turn on and off after every second. If that doesn’t happen, check the wiring and code again.
# Screenshot the final code, circuit, and results (with the LED lighting up).
 
== 2. LED with Button Circuit ==
# Copy the [https://www.tinkercad.com/things/ltcFAatwjUO Part 2] Template to the Tinkercad workspace.
# A circuit using an LED and a button will be made in Part 1. The LED should be on when the button is pressed, and off when the button is not pressed. The programming flowchart and circuit diagram are shown in Figures 27 and 28. [[Image:programmingflowchart.png|400px|thumb|center|Figure 27: Programming Flowchart]][[Image:circuitdiagram.png|400px|thumb|center|Figure 28: Circuit Diagram]]
# Before breadboarding the circuit, look at the button to determine which pins are connected. With an actual button, this is done by checking the bottom side (pin side) of the button (Figure 29). Note which pins are for power, ground, and digital input into the Arduino. In Tinkercad, the button is depicted with the pins extending from the sides, which shows the direction of the pin orientation.
# Place the button on the breadboard and make sure it straddles the bridge down the center of the breadboard (Figure 29). [[Image:Lab_5_Part_2_Fritz_Diagram.png|400px|thumb|center|Figure 29: Button Circuit Diagram]]
# Wire the circuit diagram as shown in Figure 30. [[Image:breadboardcircuitdiagram.png|400px|thumb|center|Figure 30: Circuit]]
# Write the Arduino program to implement the flowchart. You can reuse much of the code written for Part 1. Include comments explaining what the code is doing. The code must have comments to be approved by a TA.
## In the Global Area, create the constants used to hold the pin numbers for the button and the LED.[[Image:globalareacode.png|300px|left]]
## In the Global Area, create the constants used to hold the pin numbers for the button and the LED.[[Image:globalareacode.png|300px|left]]
## In the Setup Area, use pinMode() to set up the LED and Button. The LED will be set to OUTPUT since it will be controlled by the program. The button will be set to INPUT since the program will receive data from the button. [[Image:setupareacode.png|300px|left]]
## In the Setup function, use pinMode() to set up the LED and Button. The LED will be set to OUTPUT since it will be controlled by the program. The button will be set to INPUT since the program will receive data from the button. [[Image:setupareacode.png|300px|left]]
## In the Loop Area, use digitalRead(), digitalWrite(), and a conditional to write the code that controls the button
## In the Loop function, use digitalRead(), digitalWrite(), and a conditional to write the code that controls the button.
### Create a variable named buttonState, that will hold the input from the button [[Image:loopareacode1.png|200px|left]]
### Create a variable named buttonState, that will hold the input from the button [[Image:loopareacode1.png|200px|left]]
### Use digitalRead() to set the buttonState variable to the current state of the button [[Image:loopareacode2.png|500px|left]]
### Use digitalRead() to set the buttonState variable to the current state of the button [[Image:loopareacode2.png|500px|left]]
### Next, set up the conditional statement that will be used to control the LED. In this code, the conditional is controlled by the button state. [[Image:conditionalstatement.png|400px|left]]
### Next, set up the conditional statement that will be used to control the LED. In this code, the conditional is controlled by the button state. [[Image:conditionalstatement.png|400px|left]]
### Last, use digitalWrite() to control the LED. Remember, we want the LED to be on when the button is pressed, and off otherwise
### Last, use digitalWrite() to control the LED. Remember, we want the LED to be on when the button is pressed, and off otherwise.
#### This line will turn the LED on [[Image:dw1.png|400px|left]]
#### This line will turn the LED on [[Image:dw1.png|400px|left]]
#### This line will turn the LED off [[Image:dw2.png|400px|left]]
#### This line will turn the LED off [[Image:dw2.png|400px|left]]
# Click Start Simulation to check your code. Fix any errors and ensure the code is working correctly before moving on to the next step.  
# Click Start Simulation to check your code. Fix any errors and ensure the code is working correctly before moving on to the next step.  
# Screenshot the final code, circuit, and results (the LED state when the button is pressed and is not pressed).  
# Screenshot the final code, circuit, and results (the LED state when the button is pressed and is not pressed).  
<!--# Type the code shown in Figure 24.  
<!--# Type the code shown in Figure 31.  
# Copy and paste the code from the Arduino IDE into the Code block at the top of the Tinkercad workspace.
# Copy and paste the code from the Arduino IDE into the Code block at the top of the Tinkercad workspace.
#: [[Image:LED_code.jpg|350px|thumb|center|Figure 24: LED Circuit Code]]  
#: [[Image:LED_code.jpg|350px|thumb|center|Figure 31: LED Circuit Code]]  
# The flowchart uses digital pin 7 on the Arduino board as an output, so create a constant that holds the number 7 (top line of code in Figure 24).
# The flowchart uses digital pin 7 on the Arduino board as an output, so create a constant that holds the number 7 (top line of code in Figure 31).
# In the setup area, set pin 7 as an output using pinMode (second block of code in Figure 24).  
# In the setup area, set pin 7 as an output using pinMode (second block of code in Figure 31).  
# Turn the LED on by using digitalWrite, have a delay of one second, turn the LED off by using digitalWrite, and then set another delay of one second (third block of code in Figure 24). The delays are necessary as the LED is a bit slow to react.
# Turn the LED on by using digitalWrite, have a delay of one second, turn the LED off by using digitalWrite, and then set another delay of one second (third block of code in Figure 31). The delays are necessary as the LED is a bit slow to react.
# Use the debugger on the Code block. This allows you to see errors in your code so you can fix them before you run the simulation.   
# Use the debugger on the Code block. This allows you to see errors in your code so you can fix them before you run the simulation.   
# Once you fix all errors, click Start Simulation.
# Once you fix all errors, click Start Simulation.
Line 344: Line 376:
# Screenshot the final code, circuit, and results (the LED state when the button is pressed and is not pressed), and send the files to yourself.-->
# Screenshot the final code, circuit, and results (the LED state when the button is pressed and is not pressed), and send the files to yourself.-->


== 2. Prototyping a Thermal Insulation Device ==
== 3. Prototyping a Thermal Insulation Device ==
 
=== Using a Temperature Sensor ===
 
Using the Arduino, the temperature change of the hot wax will be recorded over 10 minutes. The Arduino will read the temperature through the TMP 36 sensor and print the values into the Serial Monitor in the Arduino IDE. Because this lab is performed virtually, you will create the TMP 36 circuit virtually in Tinkercad, but will not be able to measure a thermal insulation device. You will complete the circuit for collecting data and test it as if you were to collect the data for 15 minutes in-person and then receive the Serial Monitor readings from a Lab TA.
 
# Copy the [https://www.tinkercad.com/things/bi2jVfomCmm Part 3] template to the Tinkercad workspace using the steps in Starting a New Circuit in Tinkercad.
# Wire the circuit according to the configuration in Figure 31.
## Make sure that pin A0 is used, and the circuit is powered to 5V and grounded. [[Image:arduinoTMP36Circuit.jpg|500px|thumb|center|Figure 31: Arduino TMP 36 Circuit]]
# Complete the code to measure temperature.
## There are missing components in the code. Read through the comments and insert code where necessary. After the program is completed, click Start Simulation and open the Serial Monitor to check if the readings are correct.
## When the code is complete, the TMP 36 sensor should take a temperature reading every 5 seconds. The analog voltage value read through pin A0 should then be converted to degrees Fahrenheit. The temperature reading should be printed to the Serial Monitor along with the seconds timestamp of the reading.


=== Competition Rules ===
=== Competition Rules ===
<b>Data will be provided to you for this portion of the lab as it cannot be conducted virtually. Review the rules for creating an insulating device. You will need to understand the competition rules to analyze your assigned insulating device.</b>


The following rules must be observed at all times during the competition. Violation of any of these rules will result in disqualification.
The following rules must be observed at all times during the competition. Violation of any of these rules will result in disqualification.
* The placement of the thermistor with respect to the lid may not be changed
* The placement of the temperature sensor with respect to the lid may not be changed
* The thermal insulating device may not be held while testing
* The thermal insulating device may not be held while testing
* External heat sources are prohibited
* External heat sources are prohibited
Line 390: Line 435:


<!--<b><font color=#ff0000>NO RETURN POLICY</font>: When calculating cost, ALL materials requested must be included, even if they were not used. Choose the materials carefully to avoid increasing the cost unnecessarily.</b>-->
<!--<b><font color=#ff0000>NO RETURN POLICY</font>: When calculating cost, ALL materials requested must be included, even if they were not used. Choose the materials carefully to avoid increasing the cost unnecessarily.</b>-->
Note that in a non virtual lab, a thermistor is used instead of a TMP 36 sensor. A thermistor also converts an analog reading to a temperature, similar to the TMP 36 sensor. A TMP 36 sensor will now be built in the following section.
== 3. Competition Procedure ==
=== Using a Temperature Sensor ===
Using the Arduino, the temperature change of the hot wax will be recorded over 10 minutes. The Arduino will read the temperature through the TMP 36 sensor and print the values into the Serial Monitor in the Arduino IDE. Because this lab is performed virtually, you will create the TMP 36 circuit virtually in Tinkercad, but will not be able to measure a thermal insulation device. You will complete the circuit for collecting data and test it as if you were to collect the data for 15 minutes in-person and then receive the Serial Monitor readings from a Lab TA.
* Copy the [https://www.tinkercad.com/things/bi2jVfomCmm Part 3] template to the Tinkercad workspace using the steps in Starting a New Circuit in Tinkercad.
* Wire the circuit according to the configuration in Figure 29. Make sure that pin A0 is used, and the circuit is powered to 5V and grounded. [[Image:arduinoTMP36Circuit.jpg|500px|thumb|center|Figure 29: Arduino TMP 36 Circuit]]
* There are missing components in the code. Read through the comments and insert code where necessary. After the program is completed, click Start Simulation and open the Serial Monitor to check if the readings are correct.
* Clicking the TMP sensor shows a slider for the temperature of the “surroundings” in degrees Celsius.
* The Serial Monitor reading is in Fahrenheit, comment out the line for converting Celsius to Fahrenheit (type // before the line that has the conversion) and check that your Serial Monitor reading matches the number on the slider (please be aware that a small error ± 1°C is expected).
* The TMP 36 sensor should take a temperature reading every 5 seconds. The analog voltage value read * through pin A0 should then be converted to degrees Fahrenheit. The temperature reading should be printed to the Serial Monitor along with the seconds timestamp of the reading.
=== Insulating Device Design ===
* Analyze the materials and consider the design options, keeping in mind the lab's specifications. Make preliminary sketches during this process.
* Sketch the design. Label the drawings clearly. Prepare a price list and write down the total cost for the insulating container based on the materials chosen. Receive approval of the design sketch from a TA.
* The TA will build the insulating device based on the completed sketch. They will send the data received from testing the device, which will then be used in Part 4.


== 4. Data Analysis ==
== 4. Data Analysis ==


# Open the Lab 3 datasheet.
# Since this lab is performed virtually, the competition data for various designs, including pictures, a cost table, and Serial Monitor readings, are provided to you in this spreadsheet. The Lab TA will assign you a group number. Complete the data analysis for your assigned group number.
# The data pasted from the Serial Monitor into Excel is not correctly separated into columns. To present the data in the correct format, highlight all the data, and go to the Data tab and select “Text to Columns”. [[Image:datatab.png|700px|center]]
# The data pasted from the Serial Monitor into Excel is not correctly separated into columns. To present the data in the correct format, highlight all the data, and go to the Data tab and select “Text to Columns”. [[Image:datatab.png|700px|center]]
# In the Text-to-Columns wizard, select Delimited as the data type and click Next. Then select “Comma” as the delimiter, and hit “Finish”. Ensure that the data has been separated into two separate columns.   
# In the Text-to-Columns wizard, select Delimited as the data type and click Next. Then select “Comma” as the delimiter, and hit “Finish”. Ensure that the data has been separated into two separate columns.   
# Create a graph of the data using the X, Y Scatter template. First, select the data starting from the where the temperature readings stop increasing (example below). Next go to the Insert tab, and click on the first Scatter option under the Charts group.This should create a new scatter plot, as seen below. [[Image:charts.png|400px|center]]
# Create a graph of the data using the X, Y Scatter template. First, select the data starting from the where the temperature readings stop increasing (example below). Next go to the Insert tab, and click on the first Scatter option under the Charts group.This should create a new scatter plot, as seen below. [[Image:charts.png|400px|center]]
# Next add axis labels and a trendline. First click on the graph, and then the green “+” icon next to it. Then, check off “Axis Titles, Chart Titles, and Trendline”. Click on the added labels to edit the text.  When finished, the graph should look similar to Figure 29. Figure 29: Temperature vs. Time Graph of the Thermal Insulation Device [[Image:charttitle.png|400px|center]]
# Next add axis labels and a trendline. First click on the graph, and then the green “+” icon next to it. Then, check off “Axis Titles, Chart Titles, and Trendline”. Click on the added labels to edit the text.  When finished, the graph should look similar to Figure 32. [[Image:charttitle.png|400px|thumb|center|Figure 32: Temperature vs. Time Graph of the Thermal Insulation Device]]
# Calculate the insulating capacity (IC) of the design. This will be done using the trendline equation. Right-click on the trendline and select “Format Trendline”. On the “Trendline Options” tab, ensure that the trendline is linear. Select the “Display Equation on Chart option”. The slope of this linear equation is the IC.
# Calculate the insulating capacity (IC) of the design. This will be done using the trendline equation. Right-click on the trendline and select “Format Trendline”. On the “Trendline Options” tab, ensure that the trendline is linear. Select the “Display Equation on Chart option”. The slope of this linear equation is the IC.
# Give the IC, final temperature, and total cost to the TA to enter the design's performance into the competition score sheet and calculate the MDR.
# Give the IC, final temperature, and total cost to the TA to enter the design's performance into the competition score sheet and calculate the MDR.
The lab work is now complete. Please clean up the workstation. Return all unused materials to a TA.
<!--== 7. Extra Credit: Build a Thermal Insulating Device  ==
<!--== 7. Extra Credit: Build a Thermal Insulating Device  ==


Line 443: Line 467:
# Add a trendline to the graph. To do so, click on the chart to get the Design tab on the ribbon. Under the Chart Layouts group, click on the chart template that has a trendline. As before, right click on the various items to present them accurately, including deleting items. Right click on the trendline. This will bring up the Format Trendline window. On the left side, the Trendline Options item should be highlighted. If it is not, click on it to highlight it. On the right side near the bottom is Display Equation on Chart. Click on the check box to the left of this item and click Close. Click on the equation that is on the chart to place it correctly on the graph.
# Add a trendline to the graph. To do so, click on the chart to get the Design tab on the ribbon. Under the Chart Layouts group, click on the chart template that has a trendline. As before, right click on the various items to present them accurately, including deleting items. Right click on the trendline. This will bring up the Format Trendline window. On the left side, the Trendline Options item should be highlighted. If it is not, click on it to highlight it. On the right side near the bottom is Display Equation on Chart. Click on the check box to the left of this item and click Close. Click on the equation that is on the chart to place it correctly on the graph.
# Give the IC, final temperature, and total cost to the TA to enter the design's performance into the competition scoresheet and calculate the MDR.-->
# Give the IC, final temperature, and total cost to the TA to enter the design's performance into the competition scoresheet and calculate the MDR.-->
# Analyze the final MDR and competition rankings for all groups. Since the data is given to you, the rankings should be compared to see which designs worked better or worse for the competition and what to discuss in the analysis section of your lab report.
== Extra Credit: Build a Thermal Insulating Device ==
# For optional extra credit, design a thermal insulation container from household materials using the steps below.
# Preferably, materials from Table 4 should be used so that a price can be easily estimated, but it is not necessary. If you have something similar to the materials in Table 4, such as paper towels rather than wool fabric, be creative, and use it.
# Analyze the materials and consider the design options, keeping in mind the specifications of this lab.
# Sketch the design. Label the drawings clearly including the materials used.
# Prepare a cost table and write down the total cost for the thermal insulating device based on the materials chosen.
# If a material used is not in Table 4, approximate the price of the material based on the pricing of the rest of the materials (the exact number used is not important). It can be approximate but not outlandish, such as 2 cents for a glass mug, or $1,000 for a piece of toilet paper.
# Build the insulating device based on the completed sketch.
# Take pictures of the labeled sketch, cost table, and the device prototype.
# Include the above pictures in the lab report. Give a brief explanation of why the design would be successful (based on conclusions drawn from comparisons with lab designs) in the lab report.
The lab work is now complete. Please clean up the workstation. Return all unused materials to a TA.


= Assignment =
= Assignment =
Line 448: Line 485:
== Individual Lab Report ==
== Individual Lab Report ==
<!--
<!--
* For EG1003: This is a REQUIRED Lab Report
* For EG1004: This is a REQUIRED Lab Report
*
*
-->
-->

Latest revision as of 18:23, 22 August 2022

Objective

The objective of this lab is to utilize electrical components and an Arduino board to control an LED with a button, to take temperature readings, and to evaluate the design of a prototype for a product. The Arduino IDE will be used to program the Arduino board.

The prototyping will focus on the design of a thermal insulation device, the testing of the device, and the analysis of the resulting data. The designs will be measured by their capacity to slow the rate of heat loss from hot wax placed inside them. The design will be entered in a competition that will be judged by a ratio that uses the cost of the device, its insulating capacity, the final temperature of the melted wax inside the device, and the room temperature. The lowest design ratio wins.

For the virtual semester, the competition will not be conducted, but a predetermined thermal insulation device design and its associated data will be given to you to analyze. You will still have to conduct the data analysis for the design that is given to you. Extra credit will be offered in the form of constructing your thermal insulation device with materials at home.

Overview

Prototyping

Prototyping is the process of designing and building an early model of a product to test a concept or process. Any system or device that will be sold to consumers, government agencies, or businesses will begin as a prototype that typically does not have all of the components or functions that will be used in the product that is eventually brought to market. A prototype can serve as a proof of concept showing that the system or device can be built and will perform correctly.

In this lab, a prototype of a thermal insulation device will be built. Its function will be to reduce the rate of heat loss from a container of heated wax placed in the device. The prototype insulating device will use a TMP 36 sensor to measure heat loss and it will be operated by a microcontroller.

Electricity

Electricity is the movement of electrons. Electrons flow through a conductive wire when there is a difference in charge between two points in the wire. This flow of electrons is the electrical current and it is measured in amperes (A). Electrical current flows in the opposite direction of the electrons. The difference in charge is the electrical voltage and is measured in volts (V). Certain materials resist the flow of electrons. This property is electrical resistance and is measured in ohms (Ω).

Ohm’s Law (1) describes the relationship of the voltage across a resistor, the current (I) flowing through a resistor, and the resistance (R) of the resistor.

(1)

Variations in voltage and current are used in digital signal processing to operate complex systems and devices and simpler devices, such as microcontrollers and household digital instruments.

Electrical Components

Several basic electrical components are used to build simple circuits.

Breadboards

Breadboards (Figure 1) are small boards that are commonly used for circuit prototyping. They allow the circuit’s components to be connected without making permanent connections. The red and blue strips on the sides of the board (sections A and D) called power rails are connected down the board and are usually used for powering and grounding. The non-colored rows between the power and ground strips (sections B and C) are connected across and are usually used for making the connections between components and sensors. Sections B and C are not connected to each other across the bridge in the middle of the board.

Figure 1: Breadboard Connections

DC (Direct Current) Voltage Sources

DC voltage sources are used to power circuits because they have a voltage difference across their terminals. DC voltage sources are usually batteries (e.g. AA, AAA). Arduino boards can be powered by a battery, a USB cable, or an AC adapter. When the Arduino is powered, it can be used as a 5V DC voltage source.

Resistors

Resistors (Figure 2) are components that reduce the current flowing through a circuit and convert the excess current to thermal energy. They are one of the most common components in electrical circuits. Resistors are mainly used to limit the current flowing through a component. For example, when connecting an LED to a battery, a resistor helps limit the circuit to ensure the LED isn’t damaged.

Resistors are color coded to indicate their resistance in ohms (Figure 3). They are not polarized, meaning the orientation of the resistor does not affect the circuit.

Figure 2: Resistor (Left) & Resistor Symbol (Right) used in Circuit Diagrams
Figure 3: Resistor Color Codes

Push-Buttons and Switches

Push-buttons and switches (Figure 4) are mechanical devices that interrupt or divert current. Basic push-buttons are polarized while basic switches are not.

Figure 4: A Push Button, and its Internal Switch Circuit

Diodes

Diodes allow current to only pass in one direction. The anode is the positive terminal of the diode, and the cathode is the negative terminal. Diodes can also be used to amplify signals.

Figure 5: A Diode and its Corresponding Symbol

A Light emitting diode (LED) is a small electric light that uses low voltage and current (Figure 6). The longer lead of the LED is the anode, and the shorter lead is the cathode. The orientation of an LED is important since they are polarized and only allow current to flow in one direction. Most LEDs also require a resistor because they will burn out almost instantly when they encounter high current.

Figure 6: An LED and its Corresponding Symbol

A TMP36 sensor (Figure 7) uses the voltage-temperature relationship of diodes to measure temperature. The voltage across the diode of the sensor will change proportionally to the temperature. The output voltage can then be converted to a temperature reading.

Figure 7: TMP36 Sensor

Microcontrollers

A microcontroller is an inexpensive, programmable computer without any peripherals, such as a mouse, keyboard, or screen. Microcontroller boards have direct access to the input and output pins of their processing chips so that the user can directly read from sensors and perform actions. Microcontrollers are used in many electrical appliances, such as microwaves. Arduino boards (Figure 8), which use a microcontroller, were designed to be easily programmed and assembled into larger projects. These boards come in many shapes and sizes and some contain additional features, such as WiFi or Bluetooth connectivity. Different boards can also have different features, such as processing speed and memory.

Figure 8: Arduino UNO

This lab will use an Arduino UNO board created by SparkFun called a RedBoard (Figure 9).

Figure 9: RedBoard

Arduino Hardware

All Arduino boards have a general layout similar to that shown in Figure 10. Not all the sections and pins will be used in this lab or for the Semester Long Design Projects.

Figure 10: RedBoard Layout
  • Reset Button: Restarts the board
  • USB Connector: Provides power and connects it to the computer
  • Pin 13 LED: Usable LED without making an LED circuit
  • Serial LEDS: Shows if the Arduino is transmitting or receiving data from pins 0, 1, or the USB connection

The power pins are used to supply voltage to other pins, and are also used to ground pins (Figure 11).

Figure 11: RedBoard Power Pins
  • 3.3V: Usually used to power low-voltage sensors
  • 5V: Most common power pin used to power circuits
  • GND: Ground pin, which is 0V
  • VIN: Voltage-in can be used to power the board using a battery or other external voltage source

The digital and analog pins are used for input and output commands to the microcontroller and electrical components (Figure 12). They can be used with both analog and digital devices, as the Arduino board converts analog inputs to a digital input.

Figure 12: RedBoard Digital (Left) and Analog (Right) Pins
  • A0-A5: Identical analog pins that can be used to read sensors or control analog devices. Analog pins can read/write values from 0 to 1023
  • Digital Pins 0-1: Transmitter and receiver pins. Do not use these pins for this lab
  • Digital Pins 2-12: Digital pins that can be switched between HIGH states and LOW states. As such, they can only read/write values HIGH or LOW, unlike analog pins which allow for a greater range of values
  • Digital Pin 13: Connected to the onboard LED, use it only as an input pin

Arduino IDE

The Arduino IDE is a program that can be used to edit, compile, and upload code to a supported microcontroller. Figure 13 is a screenshot of the program.

Figure 13: Arduino IDE Interface
  • Verify: Checks code for errors and points to the errors after it finishes
  • Upload: Verifies code and then uploads it to the Arduino board if there are no errors
  • Console: Shows any errors the software found in the hardware
  • Serial Monitor: A tool used to send messages to and receive messages from the board

Arduino Programming

The Arduino programming language is based on C/C++, but it is designed to be simpler and easier to learn. The most intuitive way to think about programming is like building with LEGO blocks: certain rules must be followed and different building blocks can be used to build bigger parts.

Every line must end with a semicolon (;) unless it is a conditional, loop, or function. Comments start with two backslashes (//). Comments are text that the program ignores and are used to label and explain code.

Arduino Programs

Programs written in Arduino are called sketches. A basic sketch can be broken up into three different areas: global, setup, and loop. These areas are pictured in Figure 14.

Figure 14: Areas in Arduino IDE Sketch
  • Global: Constants and imported libraries go here
  • Setup: This function will only run once, at the very beginning of the program. The setup function is often used to activate the pins and sensors that will be used in the program
  • Loop: This function will run continuously after the Setup function. Code included in the loop function will continue to run until the Arduino loses power. This function is often used for the majority of the program, such as reading sensors and turning pins HIGH or LOW

Datatypes

Datatypes are the different kinds of data values that can be used, manipulated, and stored using C++. Table 1 shows the most basic and widely used datatypes.

Table 1: Datatypes
Datatype What It Stores (Examples) Default Value Notes
Boolean
True value (1, HIGH) or
false value (0, LOW)
0, FALSE, LOW -
int
Integer number (e.g. -5, 15, 1047) 0 Positive or negative
double
Decimal number (e.g. -0.5, 123.77) 0 Positive or negative
char
Single character (e.g. ‘c’, ‘A’, ‘5’, ‘?’) Indeterminate Enclosed in single quotes
string
Sequence of characters (e.g. “Hello World!”, “10”, “157+5”) Empty (“”) Enclosed in quotes

Operators

Operators perform operations on variables and constants. The results of these operations are usually stored in a variable. Table 2 displays common operators.

Table 2: Operators
Operator What it Does Notes
= Assigns a value to a variable -
+ Adds two or more values -
- Subtracts two or more values -
* Multiplies two or more values -
/ Divides two or more values -
++ Increment by 1 Usually used in loops
-- Decrement by 1 Usually used in loops
== Checks if two values are equal Usually used in conditionals
!= Checks if two values are not equal Usually used in conditionals
> or < Less than, greater than comparison Usually used in conditionals
<= or >= Less than, greater than, or equal to comparison Usually used in conditionals
&& or || Boolean AND or Boolean OR ssed to cascade multiple Boolean operations Usually used in conditionals

Constants and Variables

Constants and variables (Figure 15) hold data according to their datatype. They must be given a name so they can be referred to later. Constants hold data that will not change while a program is running. Constants usually contain pin numbers or sensor threshold values. Variables contain data that will change while a program is running. Variables usually contain sensor values and other values that must have mathematical operations done on them. Figure 15 shows how to create different constants and variables.

Figure 15: Constants and Variables

Conditional Statements

Conditional statements (Figure 16) run code enclosed by their curly brackets when a condition is met.

Figure 16: Conditional Statements

Loops

Loops (Figure 17) run the code enclosed by their curly brackets a specific number of times or until a condition is met.

While loops are used to perform a task until a condition is met. In Figure 17, the while loop runs only if the state of the button is HIGH. When the state of the button becomes LOW, the while loop will immediately stop running.

Figure 17: While Loop

For loops are used when an action must run a specific number of times. They are extremely useful when the code is being repeated multiple times throughout a program. A for loop has three parts: initialization, condition, and increment. Figure 18 is an example of a for loop. Here, the initialization variable is an integer i, which is set to 0. The condition for the loop is that i is less than 10. The increment for this loop is that i will increase by one every time the code is run.

In this example, the code within the loop will run 10 times. The first time, the value of i will be 0. The second time, the value will be 1. This will continue until i equals 10, in which it will stop executing the code. Once all the loops are complete, it will have printed out numbers from 0 to 9.

Figure 18: For Loop

Commonly Used Arduino Functions

Table 3 shows commonly used functions in the Arduino IDE that are specifically used to work with the digital and analog pins of the board.

Table 3: Commonly Used Arduino Functions
Function What it Does
pinMode(pin, mode) Sets a pin as an input or output
digitalWrite(pin, value) Sets a digital output pin to HIGH or LOW
digitalRead(pin) Reads a digital input pin as HIGH or LOW
analogWrite(pin, value) Sets an analog output pin to a value 0-1023
analogRead(pin) Reads an analog output pin as a value 0-1023
delay(milliseconds) Pauses program for a certain amount of time
Serial.print(value) Prints the value (variable) to the Serial Monitor

Tinkercad

Tinkercad is a cloud-based, in-browser software that will be used for the simulation of microcontrollers and associated electrical components. Additionally, code can be programmed in-browser in the Arduino programming language and simulated with the virtual circuit. A link to the Tinkercad website can be found here. You can sign into Tinkercad with your Autodesk account, which you should have created in Lab 1.

Once a new circuit has been created, the interface appears like that in Figure 19. Components can be dragged and dropped from the sidebar into the work area.

Figure 19: Tinkercad Interface

To simulate the program, the Code block can be opened and the code typed into it. To run the simulation with the code and virtual circuit, click Start Simulation (Figure 20).

Figure 20: Tinkercad Simulation

Heat and Heat Transfer

Heat is a form of energy. Heat can be beneficial and it can be destructive. For example, the heat created by the combustion of fossil fuels in a combustion engine or the heat generated by the friction between parts of an engine in contact can destroy an engine. A heating, ventilation, and air conditioning (HVAC) system in a home keeps the home warm at cooler temperatures and cool at warmer temperatures. Many systems and devices use components and materials that are designed to remove heat from the system or retain heat in the system.

Heat transfer is the process of thermal energy moving from one body to another as a result of a temperature difference. Temperature is the measure of the average kinetic energy of atomic motion. The faster the atoms are moving, the higher the temperature. The main mechanisms of heat transfer are conduction, convection, and radiation.

Types of Heat Transfer

Conduction occurs when there is a temperature difference within a solid body or between solid bodies in contact. During conduction, energy (heat) will flow from the region of higher temperature to the region of lower temperature. Imagine a metal rod that is heated at one end. The atoms of the rod collide at the point where the temperature differs, transferring heat until the temperature of the rod becomes uniform.

Convection is the transfer of heat within a fluid medium (fluids consist of gasses and liquids). Convection can occur as natural or forced convection. Forced convection occurs when the main mechanism for heat transfer is due to an outside force causing the fluid to move. Natural convection results from the natural difference in density between fluids, causing a liquid or gas to rise.

Radiation is the process by which energy in the form of electromagnetic radiation is emitted by a heated surface in all directions. It does not require an intervening medium to carry it. The heating of the Earth by the Sun is an example of heat transfer by radiation. Electromagnetic radiation is a means of energy transfer that occurs when an atom absorbs energy. This electromagnetic wave can propagate as heat, light, ultraviolet, or other electromagnetic waves depending on the type of atom and the amount of energy absorbed.

Figure 21: Conduction, Convection, and Radiation

Thermodynamic Systems

The container that will be built in the lab is a thermodynamic system (Figure 22), which is a part of the Universe separated from the surroundings by an imaginary boundary. There are three types of systems: open systems, closed systems, and isolated systems.

Figure 22: Thermodynamic System

Open systems allow the transfer of mass and heat. For example, an open pot of boiling water is an open system. It exchanges heat and water vapor with the air around it. If collected, the water vapor can be condensed back to liquid water that has some mass.

Closed systems only allow heat to be transferred to the surroundings. A hermetically sealed bottle of soda is a closed system. If placed in a hot environment, it absorbs energy in the form of heat, but the amount of liquid within does not change.

Isolated systems do not interact with the surroundings at all. No exchange of heat or mass is possible. An ideal Thermos® is an isolated system. If hot chocolate is poured within, the same amount at the same temperature will be poured out later. No such system can be fabricated, but they can be approximated.

Figure 23: From Left to Right, an Open, Closed, and Isolated System

Designing Insulating Containers

Understanding how to minimize heat loss is the key to designing a successful insulating container. The first consideration is the materials chosen. Using materials that are poor conductors of heat, such as glass, will minimize heat loss. Plastic is also a poor conductor of heat. Foam cups are made of plastic that has tiny air bubbles suspended in it. Air is among the poorest conductors of heat. A vacuum, or the complete lack of air, is the best insulator of all. This is the principle employed in the Thermos® design.

The other important consideration in creating the container is its cost. Minimal design uses the fewest resources while maintaining the safety and efficacy of a product.

Materials and Equipment

  • Computer with internet access
  • Arduino IDE
  • The following are the materials that are used in Tinkercad:
    • Arduino UNO microcontroller
    • Tinkercad code block with Arduino IDE
    • Breadboard
    • Wires
    • Resistors
      • 220 Ω
      • 10 kΩ
    • LED
    • Push-button
    • TMP 36 Sensor

Procedure

1. LED Circuit

  1. Copy the Part 1 template to the Tinkercad workspace using the steps in Starting a New Circuit in Tinkercad.
    1. Go to tinkercad.com and sign in with an Autodesk account.
    2. Open the Tinkercad link for the part of the lab you want to work on. The links are provided in the procedure below.
    3. Select the Copy & Tinker option. This will copy the template to the workspace so it can be edited.
  2. A circuit using an LED will be created in Part 1. This LED should blink on and off every second. The programming flowchart and circuit diagram are shown in Figures 24 and 25.
    Figure 24: LED Flowchart
  3. Wire the LED circuit as shown in Figure 25.
    Figure 25: LED Circuit
    1. Click and drag the LED and resistor to the breadboard as shown in Figure 25.
    2. Click on the resistor, and set its resistance value to 220 Ω. The resistor is necessary, otherwise too much current would flow through the LED and cause it to short circuit.
    3. Wire the signal from digital pin 7 on the Arduino board to the LED directly. To wire these two components, simply click on a hole in the same row as the negative terminal of the LED, and click once again on the GND pin of the Arduino.
      1. Remember, since LEDs are polarized, their orientation matters. The shorter leg (negative end) of the LED should be connected to the same row as GND on the Arduino board.
  4. Write the code for the circuit as shown in Figure 26.
    Figure 26: LED Circuit Code
    1. Click the “Code” button in Tinkercad to open the code editor. Ensure that the code type is set to Text
    2. The flowchart uses digital pin 7 on the Arduino board as an output, so create a constant that holds the number 7 (top line of code in Figure 25).
    3. In the setup area, set pin 7 as an output using pinMode (second block of code in Figure 25).
    4. Turn the LED on by using digitalWrite, have a delay of one second, turn the LED off by using digitalWrite, and then set another delay of one second (third block of code in Figure 25). The delays are necessary as the LED is a bit slow to react.
    5. Use the debugger (the small bug icon) on the Code block. This allows you to see errors in your code so you can fix them before you run the simulation.
    6. Fix all errors found by the debugger. Once you fix all errors, click Start Simulation.
  5. If the code is correct, the LED will turn on and off after every second. If that doesn’t happen, check the wiring and code again.
  6. Screenshot the final code, circuit, and results (with the LED lighting up).

2. LED with Button Circuit

  1. Copy the Part 2 Template to the Tinkercad workspace.
  2. A circuit using an LED and a button will be made in Part 1. The LED should be on when the button is pressed, and off when the button is not pressed. The programming flowchart and circuit diagram are shown in Figures 27 and 28.
    Figure 27: Programming Flowchart
    Figure 28: Circuit Diagram
  3. Before breadboarding the circuit, look at the button to determine which pins are connected. With an actual button, this is done by checking the bottom side (pin side) of the button (Figure 29). Note which pins are for power, ground, and digital input into the Arduino. In Tinkercad, the button is depicted with the pins extending from the sides, which shows the direction of the pin orientation.
  4. Place the button on the breadboard and make sure it straddles the bridge down the center of the breadboard (Figure 29).
    Figure 29: Button Circuit Diagram
  5. Wire the circuit diagram as shown in Figure 30.
    Figure 30: Circuit
  6. Write the Arduino program to implement the flowchart. You can reuse much of the code written for Part 1. Include comments explaining what the code is doing. The code must have comments to be approved by a TA.
    1. In the Global Area, create the constants used to hold the pin numbers for the button and the LED.
      Globalareacode.png
    2. In the Setup function, use pinMode() to set up the LED and Button. The LED will be set to OUTPUT since it will be controlled by the program. The button will be set to INPUT since the program will receive data from the button.
      Setupareacode.png
    3. In the Loop function, use digitalRead(), digitalWrite(), and a conditional to write the code that controls the button.
      1. Create a variable named buttonState, that will hold the input from the button
        Loopareacode1.png
      2. Use digitalRead() to set the buttonState variable to the current state of the button
        Loopareacode2.png
      3. Next, set up the conditional statement that will be used to control the LED. In this code, the conditional is controlled by the button state.
        Conditionalstatement.png
      4. Last, use digitalWrite() to control the LED. Remember, we want the LED to be on when the button is pressed, and off otherwise.
        1. This line will turn the LED on
          Dw1.png
        2. This line will turn the LED off
          Dw2.png
  7. Click Start Simulation to check your code. Fix any errors and ensure the code is working correctly before moving on to the next step.
  8. Screenshot the final code, circuit, and results (the LED state when the button is pressed and is not pressed).

3. Prototyping a Thermal Insulation Device

Using a Temperature Sensor

Using the Arduino, the temperature change of the hot wax will be recorded over 10 minutes. The Arduino will read the temperature through the TMP 36 sensor and print the values into the Serial Monitor in the Arduino IDE. Because this lab is performed virtually, you will create the TMP 36 circuit virtually in Tinkercad, but will not be able to measure a thermal insulation device. You will complete the circuit for collecting data and test it as if you were to collect the data for 15 minutes in-person and then receive the Serial Monitor readings from a Lab TA.

  1. Copy the Part 3 template to the Tinkercad workspace using the steps in Starting a New Circuit in Tinkercad.
  2. Wire the circuit according to the configuration in Figure 31.
    1. Make sure that pin A0 is used, and the circuit is powered to 5V and grounded.
      Figure 31: Arduino TMP 36 Circuit
  3. Complete the code to measure temperature.
    1. There are missing components in the code. Read through the comments and insert code where necessary. After the program is completed, click Start Simulation and open the Serial Monitor to check if the readings are correct.
    2. When the code is complete, the TMP 36 sensor should take a temperature reading every 5 seconds. The analog voltage value read through pin A0 should then be converted to degrees Fahrenheit. The temperature reading should be printed to the Serial Monitor along with the seconds timestamp of the reading.

Competition Rules

Data will be provided to you for this portion of the lab as it cannot be conducted virtually. Review the rules for creating an insulating device. You will need to understand the competition rules to analyze your assigned insulating device.

The following rules must be observed at all times during the competition. Violation of any of these rules will result in disqualification.

  • The placement of the temperature sensor with respect to the lid may not be changed
  • The thermal insulating device may not be held while testing
  • External heat sources are prohibited
  • The jar of beeswax must be inside the container within 30 seconds of it being received
  • The jar of beeswax cannot be returned (no restarts)
  • At least one material must be used in the design of the insulating device
  • The competition will be judged by the minimal design ratio (MDR) (2) of the design. The design with the lowest MDR wins.

(2)

  • In (2), IC is the insulating capacity, Cost is the cost of the container, TR is the temperature of the room, and TF is the final temperature read by the thermistor. Ask a TA for the room temperature
  • The insulating container will be built using the materials in Table 4. Select the materials carefully. Consider their cost and their use as an insulator. Review the competition ratio before purchasing materials.
Table 4: Materials and Costs
Material Unit Cost Per Unit
Large foam cup 1 $0.50
Lid 1 $0.25
Pack of clay 1 bag $0.20
Wool fabric 2 pieces $0.10
Cotton balls 3 balls $0.05
Popsicle sticks 1 $0.01
Paper cup 1 $0.40
Styrofoam pieces 5 $0.05
Tape 1 ft $0.10
Aluminum foil 1 ft2 $0.30
Plastic wrap 1 ft2 $0.02


4. Data Analysis

  1. Open the Lab 3 datasheet.
  2. Since this lab is performed virtually, the competition data for various designs, including pictures, a cost table, and Serial Monitor readings, are provided to you in this spreadsheet. The Lab TA will assign you a group number. Complete the data analysis for your assigned group number.
  3. The data pasted from the Serial Monitor into Excel is not correctly separated into columns. To present the data in the correct format, highlight all the data, and go to the Data tab and select “Text to Columns”.
    Datatab.png
  4. In the Text-to-Columns wizard, select Delimited as the data type and click Next. Then select “Comma” as the delimiter, and hit “Finish”. Ensure that the data has been separated into two separate columns.
  5. Create a graph of the data using the X, Y Scatter template. First, select the data starting from the where the temperature readings stop increasing (example below). Next go to the Insert tab, and click on the first Scatter option under the Charts group.This should create a new scatter plot, as seen below.
    Charts.png
  6. Next add axis labels and a trendline. First click on the graph, and then the green “+” icon next to it. Then, check off “Axis Titles, Chart Titles, and Trendline”. Click on the added labels to edit the text. When finished, the graph should look similar to Figure 32.
    Figure 32: Temperature vs. Time Graph of the Thermal Insulation Device
  7. Calculate the insulating capacity (IC) of the design. This will be done using the trendline equation. Right-click on the trendline and select “Format Trendline”. On the “Trendline Options” tab, ensure that the trendline is linear. Select the “Display Equation on Chart option”. The slope of this linear equation is the IC.
  8. Give the IC, final temperature, and total cost to the TA to enter the design's performance into the competition score sheet and calculate the MDR.
  9. Analyze the final MDR and competition rankings for all groups. Since the data is given to you, the rankings should be compared to see which designs worked better or worse for the competition and what to discuss in the analysis section of your lab report.

Extra Credit: Build a Thermal Insulating Device

  1. For optional extra credit, design a thermal insulation container from household materials using the steps below.
  2. Preferably, materials from Table 4 should be used so that a price can be easily estimated, but it is not necessary. If you have something similar to the materials in Table 4, such as paper towels rather than wool fabric, be creative, and use it.
  3. Analyze the materials and consider the design options, keeping in mind the specifications of this lab.
  4. Sketch the design. Label the drawings clearly including the materials used.
  5. Prepare a cost table and write down the total cost for the thermal insulating device based on the materials chosen.
  6. If a material used is not in Table 4, approximate the price of the material based on the pricing of the rest of the materials (the exact number used is not important). It can be approximate but not outlandish, such as 2 cents for a glass mug, or $1,000 for a piece of toilet paper.
  7. Build the insulating device based on the completed sketch.
  8. Take pictures of the labeled sketch, cost table, and the device prototype.
  9. Include the above pictures in the lab report. Give a brief explanation of why the design would be successful (based on conclusions drawn from comparisons with lab designs) in the lab report.

The lab work is now complete. Please clean up the workstation. Return all unused materials to a TA.

Assignment

Individual Lab Report

Follow the lab report guidelines laid out in the EG1004 Writing Style Guide in the Technical Writing section of the manual. Use the outline below to write this report.

  • Describe the basics of Arduino and its application
  • Explain heat, heat transfer, and all the mechanisms that perform heat transfer. Discuss which of these mechanisms applied to the design
  • Define thermal insulation and the different types of thermodynamic systems
  • Discuss minimal design and its importance
  • Describe the container's design. Explain the choices made. Include a discussion of the materials chosen and why. Talk about the strategy for winning the competition
  • What changes would have increased/decreased the MDR or IC?
  • How was the IC value derived?
  • Should the Temperature vs. Time graph be smooth or should it have spikes? Explain how closely the curve approximates the ideal and what would affect the data recorded
  • Describe how the design succeeded or failed. Discuss design improvements
  • Include the spreadsheet with the competition results. Describe the results and talk about other designs in the class
  • Discuss what part of the lab you completed for the group and how it was important to the overall experiment.

Note: It is not unusual to experience instrumentation errors in this lab, leading to incorrect temperatures being recorded. Be sure to read How to Handle Unusual Data in the manual to learn how to handle this.


Team PowerPoint Presentation

Follow the presentation guidelines laid out in the EG1004 Lab Presentation Format in the Technical Presentations section of the manual. When preparing the presentation, consider the following points.

  • What is the importance of prototyping and using Arduino?
  • What is the importance of minimal design?
  • What is the importance of materials in prototyping?
  • Why is it important to minimize heat loss?
  • How can the design be improved?

References

There were no references used.