Prototyping with Microcontrollers, Sensors, and Materials

From EG1004 Lab Manual
Jump to: navigation, search

Objective

The objective of this lab is to design a prototype thermal insulation device that reduces the rate of heat loss from a container of heated wax. The device will consist of a thermistor (an electrical component that can record variations in temperature via changes in electrical resistance) that will be operated by an Arduino microcontroller. The device will be entered into a lab-wide competition, and the performance of the prototype will be rated by a design equation that takes the cost of the device, insulating capacity, the ratio between the final temperature of the melted wax, and room temperature into consideration. The lowest equation value will win the competition.

Prototyping is the process of designing and building an early model of a product to test it. An essential part of engineering design processes; a prototype can serve as a proof of concept showing that the system or device can be built and will perform correctly (Jensen et al., 2016). Good prototypes should be cost effective, perm well, and use the fewest amount of resources needed while maintaining the safety and efficacy of the final product.

Heat and Heat Transfer

Prototyping a thermal insulation device requires an introductory understanding of heat transfer, the process of thermal energy moving from one body to another as a result of a temperature difference. Heat transfer can occur via three mechanisms: conduction, convection, and radiation.

Conduction occurs when there is a temperature difference within a solid body or between solid bodies in contact. During conduction, heat flows from a region of higher temperature to a region of lower temperature.

Convection is the transfer of heat within a fluid medium (fluids consist of gasses and liquids). Convection can occur as natural or forced. Forced convection (Figure 1) 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.

Figure 1: Air Circulation Diagram

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.

Just like an electrical insulator prevents electrical flow, a thermal insulator is a material (or a combination of materials) that reduces or prevents heat transfer between physical objects or areas with different temperatures. Thermal insulators are used in various everyday situations. For example a thermos/travel mugs, wall insulation in buildings, and even clothing. Creating a thermal insulation device means minimizing the amount of heat lost within the system. For example, keeping your coffee/tea warm within your travel mug.

Electricity and Thermistors

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 between 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.

A thermistor (the names of which is derived from combining the terms "thermal" and "resistor") is a component whose resistance varies with temperature, R(T). Thermistors can be used to record changes in temperature by monitoring changes in the current flow at a fixed applied voltage due to the variation in the magnitude of the resistance.

Microcontrollers

The insulation device will be controlled by a microcontroller. 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 perform specific functions in household appliances, medical devices, cars, and other systems and devices. Arduino boards (Figure 2), 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 a higher processing speed and more memory.

Figure 2: Arduino UNO

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

Figure 3: RedBoard

Arduino Hardware

All Arduino boards have a general layout that is similar to that shown in Figure 4. Not all the sections and pins will be used in this lab.

  • Reset Button: Resets 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
Figure 4: RedBoard Layout

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

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

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

  • A0-A5: Identical analog pins that can 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 switch between HIGH states and LOW states. Can only read/write values HIGH or LOW, unlike analog pins that allow a greater range of values
  • Digital Pin 13: Connected to the onboard LED, use it only as an input pin
Figure 6: RedBoard Digital (I) and Analog (r) Pins

The Arduino IDE (Integrated Development Environment)

Arduino IDE is a program that can be used to edit, compile, and upload code to a supported microcontroller. Figure 7 shows a screenshot of the program's interface.

  • Verify: Checks code for errors and points those errors
  • Upload: Verifies code and uploads it to the Arduino board
  • Console: Shows errors found in the hardware
  • Serial Monitor: Sends and receives messages to and from the board
Figure 7: Arduino IDE Interface

Arduino Programming

The Arduino IDE programming language is based on C/C++, but it is designed to be simpler and easier to learn. The 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 IDE are called sketches. A basic sketch can be broken up into three different areas: global, setup, and loop. These areas are shown in Figure 8.

  • Global: Contains constants and imported libraries
  • Setup: Functions that run once at the start of the program. Setup functions often are used to activate pins and sensors in the program
  • Loop: Function runs continuously after Setup function. Code in the Loop Area will continue to run until the Arduino loses power. Function often used in most of the program to read sensors and switch pins HIGH to LOW
Figure 8: Areas in Arduino IDE Sketch

Data Types

Data types are the different kinds of data values that can be used, manipulated, and stored using C++. The most basic and widely used data types are shown in Table 1.

Table 1: Basic Data Types
Data Type 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: Common 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 used to cascade multiple Boolean operations Usually used in conditionals

Constants and Variables

Constants and variables (Figure 9) 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 9 shows how to create different constants and variables.

Figure 9: Constants and Variables

Conditional Statements

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

Figure 10: Conditional Statements

Loops

Loops run the code enclosed by 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 11, 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 stop running.

Figure 11: While and For Loops

Commonly Used Functions

Table 3 shows commonly used functions in Arduino IDE that are specifically used to work with the digital and analog pins of the board. The digital pins on the board can input or output only two values: HIGH or LOW. While analog pins can process numerical values from 0 to 1023.

Table 3: Common 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

Electrical Prototyping

Several basic electrical components are used to build simple circuits such as the one used to test the thermal insulation devices in this lab. The circuits built in this lab will require a breadboard, Arduino, temperature sensor, and a resistor.

Breadboards

Breadboards (Figure 12) 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 stripes on the sides of the board (sections A and D) are called power rails and are connected down the board, 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. Sections B and C are not connected to each other across the bridge in the middle of the board.

Figure 12: 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, which are a type of microcontroller, 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.

Thermistor - Temperature Sensor

A TMP36 sensor (Figure 13) is a thermistor device that can be used to measure temperature. The voltage across the diode of the thermistor will change proportionally to the temperature and the output voltage can be converted to a temperature reading.

Figure 13: TMP36 Sensor

Resistors

Resistors (Figure 14) are components that reduce the current flowing through a circuit and convert the excess current into 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 current in the circuit to ensure the LED is not damaged.

Figure 14: Resistor (I) & Resistor Symbol (r) used in Circuit Diagrams

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

Figure 15: Resistor Color Codes (zachpoff.com)

Prior to building the insulation device, there will be a teaching activity using a push button, switch, and LED.

Push-Buttons and Switches

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

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

Diodes

Diodes allow current to pass in only one direction (Figure 17). 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 17: A Diode and its Corresponding Symbol Showing the Direction of Current Flow from the Anode to the Cathode. Note that current flow in the opposite direction is blocked.

An LED is a small electric light that uses low voltage and current (Figure 18). The longer lead of an LED is the anode, and the shorter lead is the cathode. The orientation of an LED is important since they are polarized. Most LEDs also require a resistor because they will burn out almost instantly when they encounter high current.

Figure 18: An LED and its Corresponding Symbol

Materials and Equipment

  • Arduino UNO microcontroller and USB cable
  • Computer with Arduino IDE
  • Breadboard
  • Jumper wires
  • Resistors
    • 220 Ω
    • 10 kΩ
    • 2.2 kΩ
  • LED
  • Push-button
  • Thermistor (Temperature sensor)
  • Insulating device materials

Procedure

1. Building an LED Circuit and Button Circuit

  1. 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 19 and 20.
    Figure 19: Programming Flowchart
    Figure 20: Circuit Diagram
  2. Before breadboarding the circuit, look at the bottom side (pin side) of the button to determine which pins are connected. Note which pins are for power, ground, and digital input into the Arduino. There is a wire internally connecting the pins across the sides of the push-button (Figure 21). While the button is not pressed, pins 1 and 2 are connected, and pins 3 and 4 are connected. Make sure the button straddles the gap between the electrical contact strips on the breadboard.
    Figure 21: Button Circuit Diagram
  3. Breadboard the circuit following the circuit diagram in Figure 22. Remember, since LEDs are polarized, their orientation matters. The shorter leg of the LED should be connected to the same row as GND. The 220 Ω resistor for the LED is needed, otherwise too much current would flow and the LED will burn out. The 2.2k Ω resistor for the button is needed to get a stable input. Make sure the correct resistor is used for both the LED and the button.
    Figure 22: Circuit
  4. Write the Arduino program to implement the flowchart. Include comments explaining what the code is doing. The code must have comments to be approved by a TA.
    1. Start a new sketch in the Arduino IDE
      1. Open the Arduino IDE
      2. Plug the Arduino/RedBoard into the computer
      3. In the Arduino IDE toolbar, go to Tools > Board > Select Arduino/Genuino Uno
      4. In the toolbar, go to Port and select the correct port (not COM1)
    2. In the Global Area, create the constants used to hold the pin numbers for the button and the LED (Figure 23).
      Figure 23: Constants
    3. 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 (Figure 24).
      Figure 24: LED and Button Setup
    4. Change to the next student to write the following lines of code.
    5. In the Loop Area, 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 (Figure 25).
        Figure 25: ButtonState Variable
      2. Use digitalRead() to set the buttonState variable to the current state of the button (Figure 26).
        Figure 26: DigitalRead ButtonState Variable
      3. Change to the next student to write the following lines of code.
      4. Set up the conditional statement that will be used to control the LED. In this code, the conditional is controlled by the button state (Figure 26).
        Figure 27: Conditional Statement
      5. Change to the next student to write the following lines of code.
      6. Use digitalWrite() to control the LED. Remember, the LED should be on when the button is pressed, and off otherwise.
        1. This line will turn the LED on (Figure 28).
          Figure 28: LED On
        2. This line will turn the LED off (Figure 29).
          Figure 29: LED OFF
    6. A TA must approve the code and comments. Verify and upload the code in the Arduino IDE.

2. Prototyping a Thermal Insulation Device

Competition Rules

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 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 s of it being received
  • The jar of beeswax cannot be returned (no restarts)
  • A minimum of $0.40 must be used in the design of the insulating device
  • The 10 min run starts from the same temperature (±1°F) for all insulators.

The competition will be judged by the minimal design equation (MDE) (2) of the design. The design with the lowest MDE result wins. In (2), IC is the insulating capacity (which will be a negative value - hence the absolute value is used as an input), Cost is the cost of the container, TR is the temperature of the room, and TF is the final temperature read by the thermistor. A TA will provide the final room temperature.

(2)

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 design equation before purchasing materials

Table 4: Available Materials
Material Unit Cost Per Unit
Large foam cup 1 $0.50
Pack of clay 1 bag $0.20
Wool fabric 2 pieces $0.10
Cotton balls 3 balls $0.05
Popsicle sticks 1 $0.01
Styrofoam pieces 5 $0.05
Tape 1 ft $0.10
Aluminum foil 1 ft2 $0.30
Plastic wrap 1 ft2 $0.02

NO RETURN POLICY: 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.

3. Competition Procedure

Wiring the Thermistor

Using the Arduino, the temperature change of the hot wax will be recorded over 10 min. The Arduino will read the temperature through the thermistor and print the values into the serial monitor.

  1. Carefully remove the existing circuit and wire the circuit according to the configuration in Figure 30. A 10 kΩ (If four-banded, Brown, Black, Orange, and Gold). If five-banded, (Brown, Black, Black, Red, and Gold) resistor should be used. Make sure that pin A0 is used, and the circuit is powered to the 5V pin and grounded. The thermistor is not polarized so the orientation of the two leads do not matter.
    Figure 30: Arduino Thermistor Wiring Diagram
  2. Download the Arduino program to be used to operate the thermistor.
  3. There are missing components in the code. Read through the comments and insert code where necessary. After the program is completed and uploaded, open the Serial Monitor to check if the readings are correct (should be at or near 70°F). Keep the circuit intact since it will be used to measure the temperature of the wax.
  4. The Arduino should be taking a temperature reading every 15 s. 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

  1. Analyze the materials and consider the design options, keeping in mind the lab's specifications. Make preliminary sketches during this process.
  2. 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.
  3. Build the insulating device based on the completed sketch. The TA will provide the materials needed for the design. If the design is modified during construction, note the changes and describe the reasons for them. If the modifications required more materials, update the price list and obtain approval. A reminder, materials that are purchased but are not ultimately used in the final design are still counted towards the final cost of the device.

Competition Procedure

  1. Have a TA verify the fixed Arduino code. Run the program for approximately 30 s to obtain an average room temperature. The data from the Arduino can be seen in the Serial Monitor on the top right corner of the Arduino IDE.
  2. Stop the program after 30 s and check to ensure that the data was collected. Record the average room temperature provided by the TAs.
  3. The TA will bring the heated wax. Place the lid with the thermistor attached over the top of the wax. Be sure the top of the container is loosely covered with the lid.
  4. Do not adjust the thermistor from its position in the lid. Do not screw on the lid, just place it over the container. Warning: Be careful! The melted wax is hot!
  5. Restart the Arduino program. Once the temperature readings stop increasing, tell the TAs what the highest temperature was. Let the Arduino program run until the TAs say stop. The 10 min run will start from the lowest peak temperature reading recorded among all insulators.
  6. The data from the thermistor will allow for further analysis. The Arduino data from the Serial Monitor will be used to calculate the IC for the MDR. DO NOT CLOSE OUT OF THE SERIAL MONITOR WINDOW. This will reset and erase all data previously displayed. There is no way to recover erased Serial Monitor data. After 10 min time is complete, copy and paste the relevant data from the Serial Monitor into a Microsoft Excel file.

4. Data Analysis

  1. 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” (Figure 31).
    Figure 31: Text to Columns
  2. In the Text-to-Columns wizard, select Delimited as the data type and click Next. Select “Comma” as the delimiter, and click “Finish”. Ensure that the data has been separated into two separate columns.
  3. Create a graph of the data using the X, Y Scatter template. Select the data starting from where the temperature readings stop increasing. Go to the Insert tab, and click on the first Scatter option under the Charts group. This should create a new scatter plot, as shown in Figure 32.
    Figure 32: Scatter plot
  4. Add axis labels and a trendline. Click on the graph, and then the green “+” icon next to it. Check “Axis Titles, Chart Titles, and Trendline”. Click on the added labels to edit the text. When finished, the graph should be similar to Figure 33.
    Figure 33: Temperature Change over 10 min for Thermal Insulating Container Graph
  5. Calculate the 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.
  6. Give the IC, final temperature, and 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.

Assignment

Note: Part 2: Thermal Insulation Device Competition must be included in both lab report and team presentation. Part 1: Building an LED and Button Circuit SHOULD NOT be included in the lab report and team presentation.

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. The LED and button circuit procedure should not be discussed.

  • Abstract
    • Briefly summarize the lab exercise. Include the competition results
  • Introduction
    • Discuss prototyping, the hardware and software components used in the lab, heat and heat transfer, all elements of the competition, and the design strategy and impact of rules, materials, and design equation on design strategy
  • Procedure
    • Materials
    • Describe the steps taken in the competition exercise in sufficient detail so that another person could follow the description and replicate the results
  • Data/Observations
    • Present and discuss all data collected during the exercise
  • Conclusion
    • Analyze the competition results using the data from the competition
    • Describe how the design’s performance could be improved. Recalculate using the deisgn equation to prove that design modifications would improve performance
    • Discuss the factors that could affect the design equation and the IC
    • Describe the Temperature vs Time graph. Discuss potential factors that could affect the graph readings that were recorded and the shape of the graph
  • Contribution Statement


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.

Remember: Lab notes must be taken. Experimental details are easily forgotten unless written down. EG1004 Lab Notes paper can be downloaded and printed from the EG1004 Website. Use the lab notes to write the Procedure section of the lab report. At the end of each lab, a TA will scan the lab notes and upload them to the Lab Documents section of the EG1004 Website. One point of extra credit is awarded if the lab notes are attached at the end of the lab report. Keeping careful notes is an essential component of all scientific practice.

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?
  • How are materials selected in prototyping?
  • What design considerations should be considered in a thermal insulation device?
  • What is the importance of the automation of proper data collection methods?
  • How can the design be improved?

References

Natesan, Karthikeyan. (2018). Investigate the Thermal Conductivity of Insulating Powders.

Jensen et al. 2016. “Prototypes in engineering design: Definitions and strategies.” Accessed 22 December 2023 from https://www.designsociety.org/publication/38892/PROTOTYPES+IN+ENGINEERING+DESIGN%3A+DEFINITIONS+AND+STRATEGIES

OpenStax. (n.d.). “16: Thermodynamics.” Accessed 22 Decembr 2023 from https://chem.libretexts.org/Courses/University_of_Kentucky/UK%3A_General_Chemistry/16%3A_Thermodynamics#:~:text=Thermodynamics%2C%20the%20study%20of%20relationships,processes%2C%20provides%20this%20predictive%20ability.

Poff, Zach. (n.d.). “Resistor Color Code Chart.” Accessed August 11, 2021 from zachpoff.com