The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.
Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by feigenbaumel, 2022-09-02 10:24:31

Priinciples of Engineering 2022

Textbook for 9th grade STEM class

Principles of Engineering

Goal: In this lab you will create a vibrating jitterbug toy. The jitterbug will utilize a simple circuit
consisting of (1) a battery pack → (2) a switch → (3) and a motor. All the components, as well
as the paperclip legs will be soldered to and connected via a protoboard.

1. Define: In a sentence, what are the goals of the toy you will
be creating? E.g., To race the creatures across a finish line,
to see who can last longer inside of a circle, engage the
user, artistic goals. Etc.
_________________________________________________

_________________________________________________
2. Brainstorm: Discuss with your team

what your jitterbug will look like.
Does it need legs? If so, how many?
How will the motor be mounted?
3. Build: You have agreed on idea of
what it will look like. Draw a circuit
diagram that includes the motor,
battery and switch. Then solder your
electronics on the protoboard.
Secure the motor and attach the
structure (legs) to allow it to stand
and move.

4. Test: Does it work? How well does it work? Tinker as needed. You may need to adjust
the weight on the motor and the spacing of the legs to get the right vibration.

5. Assess: What worked or did not work? What materials do you wish you had available?
_____________________________________________________________________________

_____________________________________________________________________________

CIJE | Unit 4: Electricity and Ohm’s Law 51

Principles of Engineering

52 Unit 4: Electricity and Ohm’s Law | CIJE

Unit 5: Using
the
Multimeter

Principles of Engineering

Preface

We have learned about voltage, current, and resistance. To be able to use these quantities in
circuits, it is imperative that we can measure them. The most important tool for people working
with electronics is the multimeter. These devices come with a range of available features and
precision. The instruments used in this course are high quality, auto ranging units. They give
three digits of precision, and they automatically adjust to accommodate the measurement you
are trying to make.
The meters will measure voltage, current, and resistance. Each type of measurement is
different and requires an understanding of the process to get an accurate reading and to avoid
damaging the meter or your circuit components.

Unit Sections:

➢ Using the multimeter
o Measuring Voltage
o Measuring Resistance
o Measuring Current
o Testing Continuity

Learning Objectives:

After completion of this unit students will be able to:
➢ Describe how to the use of the digital multimeter to measure voltage, resistance,
current and continuity
➢ Understand how to setup the multimeter for measuring various electrical properties

54 Unit 5: Using the Multimeter | CIJE

Principles of Engineering

Lab: Using the Multimeter – Voltage

Voltage is a measure of the difference in potential energy between two points. All difference
measurements are made between two points. When we measure distance, we are talking
about the distance between two points. Voltage is the measure of the potential energy
difference between two places in a circuit. To do this we use two probes and each probe must
be placed in contact with a conductor.

Look at the front of the meter, the dial allows you to select the type of measurement you wish
to make.

There are two kinds of voltage measurements ACV (Alternating Current Voltage) and DCV
(Direct Current Voltage). We will be making Direct Current Voltage Measurements. Set the
dial to DCV as shown in the picture.

Attach the probes to

the meter by

plugging the banana

jacks into the holes

as shown. It is

traditional to plug

the black lead into

the common port

and the red lead into

the voltage port.

Set the Notice the voltage
multimeter to port is labeled “Volts
Ohms”. This is the
DC voltage. connection port for making both voltage and resistance measurements.
Attach the

probes to the Now touch the tips of the probes to the battery terminals. A small amount of

ports and touch pressure is required to insure a good electrical connection. In the picture the

the probes to a red probe is making contact with the ‘+’ terminal and the black probe is in

voltage source contact with the ‘-‘ terminal. The reading is 12.25. Since the dial is set to DCV,

this is a voltage measurement of 12.25 volts. Notice this is a positive number.

This means the ‘+’ terminal is at a potential energy level that is 12.25 volts

higher than the ‘–‘

terminal.

Swap the leads, red
on ‘-‘ and black on
‘+’. Notice the

If the voltage is negative switch
the probes

meter now: The
voltage is negative.
This means the

CIJE | Unit 5: Using the Multimeter 55

Principles of Engineering

voltage potential at terminal the red probe is touching is 12.25 volts below the terminal where
the black probe is touching.

We can measure the voltage difference between any two points in a circuit. This picture shows
the difference in potential across the circuit resistor. In this case, the red probe is measuring
10.15 volts less than the black probe.

The black probe is Voltage drop can be
connected to the measured across any
‘+’ terminal of the component of a live
battery. We know circuit, including resistors,
the voltage LED’s, battery packs and
between the ‘+’
terminal and the ‘-‘ potentiometers
terminal is 12.25
volts. If 10.15 volts
is across the
resistor. There
must be 2.15 volts
across the LED
(light).

Note, the resistance of a wire is very low, we assume 0 in circuit theory
analysis. If R equals 0, then the voltage drop from one end of the wire
to the other is also 0. In this picture the probes are connected by the
wire. The wire does
not absorb energy
so the potential
energy on both
ends is the same.

If the probes are placed
on the circuit with no
element between them,
the voltage drop across
the gap will be zero

56 Unit 5: Using the Multimeter | CIJE

Principles of Engineering

Measuring Voltage See the previous 2 pages on using a multimeter

1. Predict the voltage of an AA cell (Read the outside of the cell for clues): ______________ volts

2. Measure the voltage of a battery cell using the multimeter, making sure the meter is set to Vdc
or V , for DC voltage:

____________ volts

3. Why are the voltages in problems 1 and
2 different?

________________________________

________________________________
4. How much voltage would you expect to

see in a “dead battery”? __________.

5. Measure the voltage of a dead battery. What do you measure? __________ volts.
6. If you were to just touch the two probes of the multimeter together, what voltage would you

expect to see? ________________ What voltage does the meter read? ________________
7. Measure the voltage across your body by holding the probes between your fingers, one in

each hand. How much voltage do you measure? ___________________ (milli-volts or volts?)

8. What is causing the voltage in your body? ___________________________________________

_____________________________________________________________________________

9. Hold the probes in the air, not touching anything. What is the voltage? ___________________

10. What is causing the voltage you are reading? ________________________________________

_____________________________________________________________________________

11. *Measure the voltage of a solar panel in direct sunlight: _______V. Move your hand over it to

shade it. What is the voltage? _________How many of these solar panels would you need to

produce the same voltage you find in a wall socket (110 Volts)? ___________
12. *Put four cells into a 6V battery pack and turn it on. What does the voltage measure? ________

13. *Measure each individual cell without taking them out of the battery pack:

Cell 1 __________ Cell 2 __________ Cell 3 __________ Cell 4 __________

*Based on material availability

CIJE | Unit 5: Using the Multimeter 57

Principles of Engineering

Lab: Using the Multimeter – Resistance

Using the Multimeter

When a resistance Measure resistance by placing the
measurement is multimeter in the ohms (Ω) setting
needed the dial and probing the resistor. Resistance
must be moved to
the Ohms position. must be measured while the
Sometimes, the element is NOT in the circuit, and
meter will show the has NO voltage flowing through it
Ω symbol to
indicate the setting
for making
resistance
measurement.
When the meter is
in this mode, it will produce a current that is forced
through the resistor and measures the resulting voltage.
This meter is an auto-ranging unit. It will try different
current values until it gets a voltage it can accurately
measure.

When we understand how the measurement is made, it is obvious that we must not have any
other sources of current in the circuit. The resistor must be removed from the circuit to
measure it.

Using the Color-bands

The color band system allows you to read the resistance of a resistor without the use of a
multimeter. A system has been universally instituted where each color band represents a
different number in the resistor’s value. The first two bands represent the first two digits of
the value. The third band represents the number of zeros to add on afterwards. The fourth
band represents the tolerance, or accuracy, of the resistor but is not used in calculating its
value.

For example:

RED GREEN RED = 2 + 5 + 00 = 2,500
120,000
BROWN RED YELLOW = 1 + 2 + 0000 =

58 Unit 5: Using the Multimeter | CIJE

Measuring Resistance Principles of Engineering

See the previous page on using a multimeter

Photoresistor Thermistor Potentiometer

Alligator Clips Resistors Breadboard

1. Measure the resistance of three random resistors by both: 1) using the multimeter, 2) and then
using the color band system (as explained on the bottom of the previous page):

Color Bands on the Resistance value: Resistance value:
resistor Using color bands Using multi meter

Example Red – Orange – Green 2,300,000 Ω 2.268 MΩ

Resistor 1

Resistor 2

Resistor 3

2. Why are the two readings different? ______________________________________________
____________________________________________________________________________

3. Is it possible to get a resistor to measure its exact rated resistance? Why or why not? ______
____________________________________________________________________________

4. What are some physical parameters that would make a resistor have more or less resistance
(i.e. make it harder or easier for electrons to flow through it)? __________________________
____________________________________________________________________________

5. Using alligator clips to connect a photoresistor to the multimeter, measure the resistance of
a photoresistor uncovered: ____________Ω, covered ____________Ω

CIJE | Unit 5: Using the Multimeter 59

Principles of Engineering

6. What is the range (max minus min) of the photoresistor? ______________ Ω

7. Measure the resistance of the thermistor. _____________ Ω
8. Place the tip of the probe between your fingers to warm it up. What is the minimum resistance

you can obtain? ___________
9. How long (seconds) did it take the thermistor to return to “room temperature” resistance?

______________ Why does it take that long? _______________________________________
10. Attach all three resistors in a line to create a series circuit. What do you expect the total

resistance of the circuit to be? ____________

11. What is the resistance when measured with the multimeter? ____________
12. We classify things that can conduct electricity as conductors, and those that cannot as

insulators. Is the desk you are working on a conductor or insulator? Try and measure the
resistance across it. What readings do you get? Does it matter how far apart the probes are?

____________________________________________________________________________
13. Is the human body a conductor or an insulator? Measure the resistance from one finger to

another. And then from one hand to another, across your heart. Record your measurements:

Finger to finger: ___________________ Ω Hand to hand: ___________________ Ω
14. The color band system was invented in order to label resistors. Why would/could the

manufactures not simply write the actual resistance value on the resistors?

____________________________________________________________________________
15. What are some advantages and disadvantages to using the color bands over a multimeter to

measure the resistance of a resistor?

Advantages: __________________________________________________________________

Disadvantages: ________________________________________________________________
16. Record the resistive value of the following color band arrangements (note the gold/silver are

on the end and are not used to calculate the resistive values):

___________________Ω ___________________Ω

___________________Ω ___________________Ω

___________________Ω ___________________Ω

___________________Ω ___________________Ω
60 Unit 5: Using the Multimeter | CIJE

Principles of Engineering

Lab: Using the Multimeter – Current

In both the measurement cases previously, the meter was an open circuit .– An open circuit is
when no current flows, whereas a closed or short circuit is when current flows. When
measuring voltage the meter does not affect the circuit operation. When we measure current
the meter is configured as a short circuit. The current must be forced to go through the meter.

This means we need to
break the connection and
insert the meter. The
meter actually completes
the connection.

To measure current: BREAK
THE CIRCUIT AND COMPLETE

IT USING THE PROBES

Note the circuit above.
The current flows from the ‘+’ terminal of the battery into the red probe, into the 10 amp
terminal of the meter. It goes through the meter and exits the common terminal through the
black probe and into the resistor. From there the current follows the path through the LED and
back to the ‘-‘ terminal. The meter can only measure the current that flows through it.

Notice, on the left side of the meter there are 2 ports. One is for

measuring large currents, up to 10

Selecting mA (milli-amps) amps. The other port, the milli-amp
instead of A (amps) will give port is only for measuring smaller
a more precise reading when currents, usually less than ½ amp.
These ports are only used when
measuring small currents measuring current.

Note, when we use the current
measuring ports and we set the dial for measuring current, the
meter is a short circuit.

NEVER touch across the battery terminals when the meter is in

current mode.

Think about what would
happen if you connected
a short circuit across the
battery terminals. More
important, the very large
amount of current can
damage the meter.

When measuring current,
NEVER touch a multimeter
directly to a power supply

CIJE | Unit 5: Using the Multimeter 61

Principles of Engineering

Measuring Current See the previous page on using a multimeter

For measuring current the multimeter needs to be inserted into the “loop” of a complete circuit.

Never connect the battery
directly to the multimeter

while in ‘current’ mode

1. Measure the resistance of three resistors BEFORE placing it into a circuit.

2. Set the multimeter to mA-dc, or A , for DC voltage, and install the probes in the
appropriate ports.

3. Build the circuit on the left using a resistor from question 1, and measure the current.

4. Repeat and record the information in the chart below for each resistor.

Measured Voltage drop across Current of the circuit
Resistance resistor

Resistor 1

Resistor 2

Resistor 3

5. What is the relationship between voltage, current, and resistance? _________________

________________________________________________________________________

6. Write a formula comparing the three variables: _________________________________
7. Theoretically, DO NOT TRY, if the resistor was removed from the circuit so there was no

resistance, how much current would flow through the circuit? (V-I/R) _______________

8. If the maximum amount of current an LED can handle without burning out is 250 mA,
using the formula you obtained in question 7, what is the minimum resistance you would
need to prevent the LED from burning out while using a 6V battery pack?

________________________________________________________________________
62 Unit 5: Using the Multimeter | CIJE

Principles of Engineering

Measuring Continuity

One of the most common uses of the multimeter is to look for places in the circuit where the
connection is broken. The meter is ideal for checking if the connection is complete and has a
special setting for this measurement. Sometimes solder joints look solid but will not be making

an electrical connection. Sometimes one might plug a wire
into the wrong column on the breadboard. Sometimes a
wire might be broken and the electrical connection will not
be complete.
Look at the possible dial settings. Find the symbol with
the sequence of curving lines representing sound coming
from a speaker.
In this mode, the meter will search for open or short
circuits. If there is an electrical connection, the meter will
beep. This feature is very useful for tracing through a
circuit and is most often used when troubleshooting a
circuit.
This is a resistance measurement. It must be made with
all the power disconnected from the circuit. (This might entail unplugging the Arduino from
the laptop or power supply, or simply turning off the batteries).

1. Put the meter in continuity mode. Plug the leads into the volt / ohm and common ports.
Measure the continuity between the ends of a male to male connecting wire.

Did you hear the audible sound? ______________

2. Use the multimeter in continuity mode to test an LED using the correct polarity

(“+” and “—“). Do you hear the audible sound when testing the LED? ______________

3. What about when you test it using the wrong polarity? ______________

4. How could you use continuity to check your alligator clips? Try it.

______________________________________________________________________

5. Hold one probe of the multimeter in each hand. Do you hear a noise? Is your body
considered to have continuity? Why or why not?

______________________________________________________________________

6. Using various resistors, try and determine the maximum resistance you can have in

which the meter will still consider there to be continuity. How much is it? ___________

CIJE | Unit 5: Using the Multimeter 63

Principles of Engineering

64 Unit 5: Using the Multimeter | CIJE

Unit 6: Ohm’s
Law

Principles of Engineering

Preface

In the previous unit, we learned the basis for analyzing electric circuits. In this unit, we will go
into further details about a simple type of circuit and characterize its electrical behavior. We will
then apply this knowledge to building a circuit and taking measurements that will be used in the
next unit to graph the electrical relationships. Later in the course, we will link this relationship
with the broader engineering phenomenon of linearity.

Unit Sections:

➢ Series circuit
➢ Worksheet: Series Circuits
➢ Lab: Capacitance

Learning Objectives

After completion of this unit students will be able to:
➢ Build a series circuit and measure its behavior
➢ Identify the voltage drops across each component in a series circuit
➢ Be able to analyze and evaluate a series circuit in its completeness for each component’s
voltage, current and resistance

Safety First

In this unit, you may conduct an experiment using a power source connected to an electrical
outlet. You should not tamper with the electrical outlets directly. Only the teacher should
connect and disconnect the devices to the outlets. In addition, make sure the power source
electrical cables are in good condition and are not frayed or exposed. Be sure to keep liquids
away from the devices.

66 Unit 6: Ohm’s Law | CIJE

Principles of Engineering

Series Circuit

The electrical units we have learned in the previous unit:

Unit: Symbol Name of units Symbol of units
Charge Q Coulombs, electrons 1 C = 6.24 · 1018 e
Current I
Voltage Amperes, Amps A
Resistance
V Volts V

R Ohms Ω

In the previous unit, we studied Ohm’s law, which describes the relationship between the
voltage, current and electrical resistance of a passive electrical component. We have learned that
the current through a component with electrical resistance is directly proportional to the voltage
drop between its ends and inversely proportional to its resistance:

Voltage is given in volts (V)
Resistance is given in Ohms (Ω) =
Current is given in amperes (I)

• When the voltage in a component is constant, the lower the resistance, the stronger the
current passing through it

• When the resistance of the component is constant, the higher the voltage, the stronger
the current passing through it

Remember:

When a number of factors are connected and we want to know the effect of one factor on
another, we consider all of the other factors as constant and then check how a change in one
factor is expressed in another.

For Example:

When the relationship is between three variables, as is the case for Ohm’s law, one variable must
be kept constant each time, as described previously.

This is also the case with the relationship you may already know of between distance (x), time (t)
and average velocity (v). In this case, speed is equal to the distance traveled over time, i.e. miles
per hour.

The equation describing the relationship between these variables is:


=

For example, to calculate the effect of time over speed, we will treat the distance as constant,
thus when time increases, the average velocity decreases.

CIJE | Unit 6: Ohm’s Law 67

Principles of Engineering

An electric circuit is a connection of electrical components that includes a power source. The
power source supplies the energy required to run the current through the circuit. The resistors
connected in the circuit represent consumers of the energy and restrict the current flow.

Example:

In the following circuit, there are four resistors connected in series to a power source:

Find the current in the circuit.

II

I

I
I

To solve a series circuit problem, the following three calculations must be made. The order is
dependent on what information is given in the question.

1 2 3

Apply V = I*R to each Apply V = I*R to the circuit The current at any point in a
individual resistor. as a whole. series circuit is equal to the

Once you know two of the VTotal = ITotal*RTotal. Once you current anywhere in the
variables for any resistor, you know two of the variables circuit.
you can solve for the 3rd
can solve for the 3rd ITotal = I1 = I2 = I3 = ...

VIR Once you know any
R1 two variables in a
R2 row you can solve for
R3 the 3rd using V=I*R
Total
RTotal is the sum
VTotal is the sum of the voltage at The current is the same of each individual
each individual resistor, and is throughout the circuit, so resistor
equal to the voltage of the battery once you know one ‘I’ it

68 Unit 6: Ohm’s Law | CIJE is the same everywhere

Principles of Engineering

Worksheet: Series Circuits

In the circuit below, the current from the positive terminal of the 9 volt battery has no choice but
to go through all of the resistors.

II

I

I
I

1. How many resistors are there in series? __________________
2. The 9 volts from the battery flows across the combination of resistors. What is the total

resistance of the combination of R1 + R2 + R3 + R4. Total resistance is __________ Ω
3. Understanding that the 9 volt flow is across the combination of resisters, what is the

total current flow in the circuit? Remember that VTotal = ITotal * RTotal. _______________A
4. Now that we know the current that flows through each of the resistors, we can calculate

the voltage drop across each resistor. From Ohm’s law:
VR1 = I * R1 = ______________ volts
VR2 = I * R2 = ______________ volts
VR3 = I * R3 = ______________ volts
VR4 = I * R4 = ______________ volts

5. Check your answers. We can think of voltages like heights. We start by going up 9 volts
(think of it as 9 feet) R1 causes a drop, R2 causes a drop, R3 causes a drop, and R4 causes
a drop. The amount we go up must equal the sum of all the drops. Add the results in
problem 4 to see if you got the correct drop values.

VR1 + VR2 + VR3 + VR4 = _______________ volts
6. Does your total voltage drop from Problem 5 equal the battery’s starting 9V? Yes / No

If the sum of the total voltage drop is not equal to the original 9V supply voltage, then
you must go back to Problem 4 and check your math.

CIJE | Unit 6: Ohm’s Law 69

Principles of Engineering

7. When 100V is applied to the following circuit, a 4A current flows through the 5Ω
resistor.

100 V Hint:

In a series circuit,
the current, 4A, is
the same in each
element of the
circuit.

Additionally:

= ∙

What is the resistance of resistor X? ________________________
8. Consider the circuit:

Hint:

First find the total
current flowing in
the circuit using
V=IR.

24 V Then solve for
individual voltage

drops at each

resistor using V=IR

a. Calculate the voltage drop on each resistor in the illustration.
V1= __________ V2 = __________ V3 = __________

b. What is the sum of the voltage drops on the resistors? __________
c. If another circuit has a 24V power supply and three resistors, each with ½ the

respective resistance of those in the diagram, what is the ratio between the
currents of the two circuits? __________
9. Calculate the ratio of resistances of two resistors in series so that the source voltage is
divided equally between them (i.e. - V1= V2).
______________________________________________________________________
______________________________________________________________________

70 Unit 6: Ohm’s Law | CIJE

Principles of Engineering

10. A light bulb is connected to a dimmer as illustrated in the diagram. Calculate the missing
values for this circuit.

V = _____ V = 80 V Dimmer
I = _______ V = 14 V
R = 47Ω I = _______
R = 8.2Ω

11. The source voltage in the following circuit is 18V. The current in resistor R2 is 3mA.
a. What is the voltage drop on resistor R1? _______________
b. What is the resistance of resistor R1? _______________
R1

18v

12. For the following circuit:

36 V

a. Calculate the current in the circuit. __________
b. Calculate the voltage drop on each resistor. V1 = ______ V2 = ______ V3 = ______
c. If each resistor is replaced by a resistor of double its resistance, what will the

current in the circuit be? __________

CIJE | Unit 6: Ohm’s Law 71

Principles of Engineering

Additional Problems 17. What value of R2 should be selected if you
13. Solve for ITotal = __________ wanted 20mA in your circuit?
V1 = __________
V2 = __________ R2 = ________

14. Solve for ITotal = __________ 18. What voltage source should be used if
V1 = __________ you wanted 75mA of current in our
V2 = __________ circuit?

15. If ITotal = 50mA, solve for: V = ________
R1 = __________
V2 = __________ 19. Solve for ITotal = __________
V1 = __________
V2 = __________
V3 = __________

16. Solve for ITotal = __________ 20. What resistor for R2 will produce 10mA of
R2 = __________ current?
VTotal = __________
R2 = __________

V2 = __________

72 Unit 6: Ohm’s Law | CIJE

Principles of Engineering

Lab: Capacitance

Both capacitors and resistors are important components in circuits,
especially delay or timer circuits. Combining resistors and capacitors
in a circuit will increase / decrease a timing sequence.

A simple circuit is shown below with three capacitors and a LED in
parallel. On the right-hand side of the circuit the LED is shown, and
is protected by a potentiometer. As the button is closed, the
capacitors begin charging up while the LED is concurrently being lit
from the battery. When the switch is
opened, the LED stays on for a short
time and then begins to slowly fade.
This happens because each capacitor
has a charge of ‘electricity’. This is
released slowly when the battery is
switched off from the circuit.

Set up the circuit as shown in the above
diagram. Hold down the button and time
how long it takes the capacitor to charge.
Then release the button and see how long it
takes the LED to turn off.

To measure how long it takes a
capacitor to charge, place the two
probes of the DMM on the two pins
of the capacitor and set the meter
to read voltage. Using the readings
from the meter while charging the
capacitors, when do you think the
capacitor is fully charged?

Complete the table below.

Trial Potentiometer Time to charge capacitors Time LED remained lit after
Resistance to line voltage button was released

1

2

3

4

5

CIJE | Unit 6: Ohm’s Law 73

Principles of Engineering

Conclusion

1. Does more resistance make the capacitor charge faster or slower? Why?
________________________________________________________________________
________________________________________________________________________

2. Does more resistance make the LED stay lit longer or shorter? Why?
________________________________________________________________________
________________________________________________________________________

3. What are some devices you currently use that might utilize capacitors to store
energy? Why?
________________________________________________________________________
________________________________________________________________________

4. What are some benefits to capacitors over batteries?
________________________________________________________________________
________________________________________________________________________

5. What are some benefits to batteries over capacitors?
________________________________________________________________________
________________________________________________________________________

6. What would happen to the LED if the capacitors were aligned in series instead
of parallel?
________________________________________________________________________
________________________________________________________________________

7. Try building and testing the circuit. What happens?
________________________________________________________________________
________________________________________________________________________

74 Unit 6: Ohm’s Law | CIJE

Unit 7:
Arduino

Microcontrollers

Principles of Engineering

Preface

This unit introduces the Arduino microcontroller (MCU), which is sometimes referred to as a
microprocessor due to its onboard chip. The Arduino is a multifunctional device because, in
addition to being a MCU, it also has different types of ports for electronic components. When
hooked up to a computer, the Arduino can be programmed so that various electronic
components wired into it can be selectively activated by the program.

Unit Sections

➢ The Arduino Platform
➢ Why Use an Arduino MCU?
➢ Layout of the Arduino Board
➢ Lab: Introduction- the Arduino Microcontroller
➢ Compiling and Running an Arduino Program
➢ The Basic Structure of Arduino Code
➢ The Blink Program in Detail
➢ Lab: Basic Structure of Blink
➢ Lab: Traffic Light

Learning Objectives

After completion of this unit students will be able to:
➢ Describe what the Arduino is used for
➢ Understand the physical layout of the Arduino UNO
➢ Describe what the voltage levels of the digital I/O pins are for the UNO
➢ Describe what is meant by open source and open hardware
➢ Setup the Arduino program to work with a specific Arduino board
➢ Compile and upload the Blink program
➢ Describe the two ways to include comments and why comments are used
➢ Describe when to include semicolon at the end of a line
➢ Describe the operation of the pinMode(), digitalWrite(), and delay() commands

76 Unit 7: Arduino Microcontrollers | CIJE

Principles of Engineering

Section 1 The Arduino Platform:

The Arduino platform was specifically designed to allow students, artists, and other non-
experts to be able to build projects using LEDs, motors,
robots, drones, etc. Microcontrollers have been around for
decades, but Arduino revolutionized access to these by
creating a much easier to use package of hardware and
software that was very low cost compared to the many
hundreds of dollars required in the past. In addition, a large
and supportive community of enthusiasts contribute
software and advice to individuals new to the Arduino and
experts alike.

The Arduino hardware is an example of a microcontroller development board. A
microcontroller (MCU for short) is a computer chip that has the processor, memory, and input
and output functions contained
inside a single package. MCUs are
usually much less powerful than the
computer chips in desktop computers
in terms of processing power, but
they are inexpensive and easily
adaptable to a wide range of
applications. This means that MCUs
are everywhere—power tools,
kitchen appliances, traffic lights, toys,
and dozens in a single car—and they
are only becoming more prevalent
with the rise of mobile devices since
MCUs do not use a lot of power.
There are billions of MCUs sold every
year.

In addition to the hardware, Arduino provides a free software platform that is specifically
designed for those who do not know how to code. The Arduino integrated development
environment (IDE) can be downloaded from

https://www.arduino.cc

The IDE is available in Windows, OSX, and Linux. It works equally well on all platforms.

Why Use an Arduino MCU?

The Arduino microcontroller allows us to collect data from sensors, and by using computer
programming, determine the behavior of the outputs. For example, the Arduino measures the
temperature with a thermometer (an input) and then if the temperature is too low (the turn-on
temperature is set via computer code), it turns on a heater (an output). The temperature sensor
and heating element are wired into the Arduino, so the code that is written using the IDE controls
them. Therefore, the Arduino allows for easy interaction between code and any electrical
components that are wired into it.

CIJE | Unit 7: Arduino Microcontrollers 77

Principles of Engineering

Here is a graphic demonstrating the process:

Input Arduino Output

• Temperature • If temperature is • Heating
Sensor less than 68, turn element
on the heater.
otherwise, turn it
off.

An INPUT is a device that puts information into the microcontroller, while an OUTPUT is a
device that is controlled based on instructions from the microcontroller

The Arduino determines the behavior of the system. If we want a system to respond to its
environment, meaning that the outputs will not always be the same, then an Arduino is an
excellent tool for this.

Do we need to use an Arduino if we want a light to be on 24 hours a day? No. The output (the
light) does not need to respond to the environment. Do we need use an Arduino (or similar
device) if we want the light to turn on automatically if it is dark? Yes! How do we know it is dark?
There is a sensor that detects light. The Arduino reads this sensor (the input) and then depending
on the value of the sensor, the Arduino will turn the light on or keep it off.

Layout of the Arduino Board

Now, let us take a tour of the Arduino UNO board that we will be using throughout this course.
We will only discuss the features that we will use earlier in the course... Other features will be
introduced later as needed.

78 Unit 7: Arduino Microcontrollers | CIJE

Principles of Engineering

Microprocessor Chip: (HIGH) and 0V (LOW). An analog signal can
have voltage values between 0V and 5V, for
The brain of the Arduino UNO is the Atmel example, 3.2V or 1.9V. The analog pins only
ATMega328P. It is an 8-bit processor with 32 measure analog inputs. They cannot output
kB of general memory, 23 general analog voltages!
input/output (I/O) ports as well as several
other features that make it a very useful tool Alternative Functions of the Pins:
for controlling systems. The UNO only allows
access to 20 of the I/O ports. Most of the pins on the Arduino board have
alternate functions. For instance, digital pin 0
Arduino Pins: and pin 1 are used for serial communications
(one of the ways that the Arduino can talk to
Next, the group of pins in the bottom left of other devices like your laptop). Another
the picture are the power pins. From right to example is analog pin A4 and A5 can be used for
left, Vin can be used to attach a battery or I2C communication (another way for the
other power source to run the Arduino Arduino to communicate). For now, the
board without it being attached to the USB important thing to understand is not what each
cable. It can accept power supplies from 6V- pin specifically does, but that you can only use
20V but no more than 12V is recommended. it in one way. You cannot use pin 0 and pin 1 for
The two next to it are both ground pins LEDs and also for serial communication at the
(GND). Then there is a 5V output pin (as if it same time!
were a 5V battery). There is also a 3.3V
output pin. The reset pin and the VIO Additional Parts of the UNO Board:
reference pin will not be used or discussed in
this book. The USB connector allows connect the UNO to
the computer. However, the MCU and USB
Along the top of the board are 14 digital I/O speak a different electrical language and
pins labeled 0-13. Digital pins have two, and therefore there must be a translator to allow
only two, states. The digital pin can be either them to communicate. The other small chip on
HIGH or LOW. On the UNO, when the pin is the board is this translator.
used as an output, if a pin is HIGH it is
sending out 5V. When it is LOW, it is at 0V. Additionally, there are dozens of small parts on
When used an input, the pin will read HIGH the boards. These are mostly resistors and
if the input voltage is close to 5V and LOW if capacitors. The small silver oval is the crystal
it close to 0V. Additionally, there is another oscillator. This keeps time for the MCU. The
ground (GND) pin next to digital pin 13. The Arduino board runs at 16MHz which means that
AREF pin and others will not be used for now. the processor ticks once every 62 billionths of a
second. This is very fast, but about 100 times
At the bottom right, there are six analog slower than most modern central processing
pins. Recall that digital means there are units (CPU’s)!
only two voltage states on the UNO, 5V

Shields and Expanding the Powers Arduino Board

Beyond its ease of use, one of the factors that makes the Arduino so useful is the number of
expansion boards that allow you to build much more complicated.

projects with ease. Do you need Wi-Fi for your project? Bluetooth? Speech recognition? The
Arduino UNO alone is not powerful enough to do these things, but by using shields and breakout
boards we can.

CIJE | Unit 7: Arduino Microcontrollers 79

Principles of Engineering

A shield is an additional board that has the same form factor
as the UNO. You use the shield by plugging it directly into
the pins of the UNO. It will usually cover the entire
board. For example, let’s look at the Arduino Wi-
Fi shield attached to an UNO.

From the picture on the right, you can see that
the UNO is underneath the Wi-Fi shield. The
additional microcontroller chip on the top board
(the big black square in the middle) contains all
of the hardware and code necessary to allow the
UNO to access the internet. Notice that
although the pins of the UNO are covered up by
the shield, they are still accessible. For example,
in the above shield, we can use the analog pins
by plugging in to the pins on the bottom right.

A breakout board has the same purpose as a
shield: to expand the capabilities of the Arduino
board. The difference is that it does not have the
same form factor. It will almost always be
smaller than the UNO board and will be plugged
directly into a few pins of the board.

Pictured is an SD breakout board from Adafruit
(shown in green). As you can see, a breakout
board is not necessarily less complex than a
shield. It is simply a matter of physical space and
how the additional board is connected to the
Arduino.

Arduino Uno Arduino Leonardo Arduino Due/Mega Arduino Nano

80 Unit 7: Arduino Microcontrollers | CIJE

Principles of Engineering

Other Arduino Boards
The UNO is not the only Arduino board. The Arduino MEGA has larger number of I/O pins and
more memory. The Arduino ZERO is a more powerful chip for more computationally intensive
projects. The Arduino NANO is a much smaller version for projects where size is critical. These
are just a few examples.
Clones and Open Source
When you are shopping for Arduino boards, you will find that there are dozens of unofficial
Arduino boards. In fact, the board we use in this course is one of these.
This is a clone board. It is
completely compatible with the
UNO. And yes, these clones are
perfectly legal. Arduino releases
the full layout of all of their boards
to the public to copy and alter as
the user/manufacturer sees fit.
Arduino is part of the open
hardware movement, which holds
that innovation is accelerated and
expanded when product designs
are public. This is the hardware
analog of the open source
movement in software which
believes in making the code for
software available to the public to
change and use. While open hardware is less developed, open source software has a long and
important history. The backbone of the internet, the security protocols that keep your bank
account information safe, and the operating system that runs most of the servers on the internet
are all examples of open source software.
The Arduino platform is completely open, both in hardware and software. This has allowed
people to adapt it to their purposes freely and has been one of the main reasons that Arduino
has become very popular in the last 10 years. But before anything else, it is Arduino’s ease of use
that has made it popular. Now that you have been introduced to the platform, let’s learn how to
use it so you can make amazing things!

CIJE | Unit 7: Arduino Microcontrollers 81

Principles of Engineering

Lab: Introduction – The Arduino Microcontroller

1. What is the definition of a microcontroller? ____________________________________

________________________________________________________________________

2. Label the parts of the board on
the right.

3. Find one shield online that will
enable a project to use GPS.
Copy the link or post a picture
from the site.

(Hint: adafruit.com and
sparkfun.com are excellent
resources)

4. Find one breakout board online
that will enable a project to use
GSM (to communicate with cell
phone towers). Copy the link or
post a picture from the site.

(Hint: adafruit.com and
sparkfun.com are excellent resources)

5. What is the recommended voltage range for powering the Arduino board? __________

6. What is the difference between a digital input and an analog input? ________________

________________________________________________________________________

7. What is the open source movement? How does it apply to Arduino? ________________

________________________________________________________________________

8. Indicate whether the following devices are inputs or outputs:

a. ______ Lights

b. ______ Buttons

c. ______ Screens

d. ______ Keyboards A) INPUT – sends information to the Arduino

e. ______ Speakers B) OUTPUT – gets information from the Arduino

f. ______ Microphones

g. ______ Temperature sensor

h. ______ GPS

i. ______ Fingerprint scanner

82 Unit 7: Arduino Microcontrollers | CIJE

Principles of Engineering

Section 2: Compiling and Running an Arduino Program

There is no limit to the number of things that one can do using a microcontroller based system.
In this course, we will use the Arduino microcontroller family. This is one of the of the simplest
microcontroller systems to work with because of its simplified programming environment and
extensive community.

In order to use any microcontroller, we must program it. Without knowing how to program, the
Arduino board is a very poor paperweight. The following sections are intended to give you the
background necessary to begin creating a program of your own. It is intended to be a beginner’s
guide, specifically for students without any programming experience, and is only a fraction of
what can be accomplished. The purpose of this chapter is to provide instruction on the principles
of programming, and the sections focus on how programming can be used and identify where
problems can occur. To begin:

1. Start by plugging in your unit to any USB port using the cable provided. You should see
the red power light on the Arduino come on. Also, if this is the first time you are
connecting a new Arduino, you should also see another red LED blinking once per second.

2. Launch the Arduino program.

3. Next you need to
tell your
computer what
type of Arduino
you are using.
Select Tools ->
Board and select
your board. Most
of us use the
UNO processor.
The red boards
provided are
UNO clones. If
you don’t know
what you have,
look on the board
for a clue.

4. Next we must tell the computer which computer port the Arduino is plugged into. To do
this select Tools -> Port -> Arduino.

5. First, let’s verify that you are able to communicate with the Arduino. Click on Files ->
Examples -> Basic -> Blink. Then click on the arrow Button just below the word Edit in the
command line.

6. This will load a basic program into the Arduino board and start it running. This will take a
few seconds. If successful the lower portion of the screen will say “Done Uploading” and
will be the words “Binary sketch size: 1084 bytes…”.

CIJE | Unit 7: Arduino Microcontrollers 83

Principles of Engineering

Section 3: The Basic Structure of an Arduino Code

Let us now analyze the Blink code in more detail. First, we are only going to look at the structure
of the code. Do not worry about understanding the specific commands right now.
The three main parts that every Arduino program must include are in boxes in the figure below.

We will discuss variables in much more detail later, but for now, we need to know that the space
above the setup function is where we will put variables.
The setup function will include all operations that we only need to happen once. As we can see
from above, it has a form like,

void setup( )
{

// do the things we only want to happen once
}

After the setup function, we have the loop function. The loop function includes all operations
that we want to happen continuously, for example, a temperature sensor that makes sure our
refrigerator is staying cool enough for food not to spoil. This sensor will need to make
measurements more than once throughout the day. In fact, the loop function will run forever
until we unplug the Arduino. It has the form,

void loop( )
{
//commands we want to happen more than once
}

Again, all Arduino programs must have these three elements even if they are empty.
84 Unit 7: Arduino Microcontrollers | CIJE

Principles of Engineering

Section 4: The Blink Program in Detail

Now we are ready to delve into the Blink program. The code before the setup function is shown
below. All of this text is a comment. A comment is only for the human readers of the program.
It is completely ignored by the computer. Comments are essential to help you and (more
importantly) other programmers understand what the program is doing.

There are two types of comments in the Arduino IDE, a single-line comment and a multi-line
comment. A single-line comment starts with two forward slashes (//) and only goes to the end
of the line. A multi-line comment begins with the /* and will continue to be a comment until a
closing */ is typed regardless of how many lines you write.
In the above figure, we see an example of a multi-line comment. The first line has a /* and after
many lines there is a closing */ (after "Scott Fitzgerald"). Notice that the IDE turns all comments
gray!
To review, a multi-line comment will look like,

/* text and more text,
even the full text of
War and Peace */

And a single line comment will look like this:

//text and more text, even the full text of War and Peace

After this comment and before the setup() function, we would include any global variables we
need. In the blink program, there are none.
Next we have the setup() function,

CIJE | Unit 7: Arduino Microcontrollers 85

Principles of Engineering

The setup() function for the blink program for this program does only one thing: it uses the
pinMode() function to set the "pinMode" of pin 13. To understand what this function is doing,
recall that the digital pins (pins 0-13 on the Uno) can either send out a voltage (for example, to
turn on an LED) OR it can read the value of the voltage sent to it by an external device (for
example, a button). We have to create a statement to tell the Arduino how we are going to use
the pin. The pinMode() function is how we do this.
To use pinMode() we have to give it two pieces of information (called parameters), the pin
number, and whether the pin is sending out a voltage or reading a voltage.
In Blink, since we want to turn on the on-board LED located at pin 13, we set pin 13 to OUTPUT.
The word OUTPUT (or INPUT) must be in all-caps. This information must be typed in in this order.
At the end of the pinMode() function, there is a semicolon. Anytime we use a function or set a
variable, we must put a semicolon at the end. Forgetting to put the semicolon at the end of a
statement is one of the most common mistakes a programmer will make!
One last thing note that after void setup and after the pinMode statement there are curly
brackets { and }. These section off the code instructions for setup and allow the IDE to now
move on the the next part of the program void loop. If they were not there the IDE would not
be able to move on. The { and } have to come in pairs, beginning with { and then finishing with
}. They do not have to be on the same line as the code but need to be there to section off the
code. Again this is a common mistake that a programmer might make.

Since the setup() function only runs once, when we get to the bottom of the setup() function,
and have added a }, the program will continue to the loop() function. Notice that the pair of {}
are also used for the same reason in the void loop function below.
In Blink, the loop function is:

Here we see two different types of functions, digitalWrite() and delay(). digitalWrite() is the
function we use to turn a pin on and off, that is to send out a voltage or stop that voltage. HIGH,
meaning high voltage (5V in our case) is the equivalent to turning on the pin. LOW, meaning
low voltage (0V in our case) is the equivalent to turning off the pin. So the digitalWrite()
function has the form:

86 Unit 7: Arduino Microcontrollers | CIJE

Principles of Engineering

digitalWrite(pin #, HIGH or LOW);

Just as before, since this is a command statement, we must end the line in a semicolon.
After the first digitalWrite(), we use the delay() function. This does what you think it does, it
waits. It has the form,

delay(time in milliseconds);

remembering that 1000 milliseconds = 1second.
So let's walk through the loop() function line-by-line.

1. digitalWrite HIGH turns on digital pin 13.
2. delay(1000) freezes the code for 1 second, so the light stays on for 1 second.
3. digitalWrite LOW turns off digital pin 13.
4. delay(1000) freezes the code for 1 second, so the light stays off for 1 second.
5. There are no more commands, so the code returns to the top of the loop() function and
repeats.
Remember that the loop() function repeats indefinitely. It will only stop when you unplug the
Arduino!

CIJE | Unit 7: Arduino Microcontrollers 87

Principles of Engineering

Lab: Sections 1-4 - Basic Structure and Blink

1. What is a comment? _______________________________________________________

2. What are the two ways to indicate a comment in a code? __________ and __________

3. What are the three sections every Arduino code must contain? ______ ______ _____

4. How many times does the code in the 'setup' run? ________ In the 'loop'? ________
5. What does the code do after it reaches the final " } " of the 'void loop()'?

________________________________________________________________________

6. For the following items, hypothetically, plugged into Arduino pin 7, determine if the
'pinMode' function should declare the pin as an OUTPUT or an INPUT:

a. _____ Motor

b. _____ Push-Button

c. _____ Speaker a) pinMode(7, OUTPUT);
d. _____ Motion Sensor b) pinMode(7, INPUT);
e. _____ Microphone

f. _____ Light Sensor

g. _____ Temperature Sensor

h. _____ Heating element
7. Complete the line of code so that the comment will hold true:

a. delay( __________ ); //will pause for three seconds
b. delay( __________ ); //will pause for a half second
c. delay( __________ ); //will pause for a quarter second
d. delay( __________ ); //will pause for one hour

8. Suppose a motor was plugged into Arduino pin 5, and a siren into pin 7. Complete the
line of code so that the comment will hold true:

a. digitalWrite( _____,_______ ); //will turn off the motor
b. digitalWrite( _____,_______ ); //will turn on the siren
c. digitalWrite( _____,_______ ); //will turn off the siren

d. digitalWrite( _____,_______ ); //will turn on the motor
88 Unit 7: Arduino Microcontrollers | CIJE

Principles of Engineering

9. Build the following circuit using a breadboard, wires, an LED and a resistor.
When using a breadboard, note these 3 important rules:
A. Wires that are in the same short row are connected
B. Wires that are in a long red or blue column along the sides are connected to each
other
C. The left side of the breadboard is not connected to the right side of the
breadboard

Note: the
longer leg of
an LED must
be the side

that is
connected to

power

10. Type the following code into
the Arduino IDE

11. Tell the computer what
type of microcontroller you
are using. We use the
Arduino Uno for this
course. Navigate to:
tools > Board > Arduino
Uno

CIJE | Unit 7: Arduino Microcontrollers 89

Principles of Engineering

12. Tell the computer which port the Arduino is plugged into. Navigate to:
For MAC:

For WINDOWS:

Important: If the previous step is not performed correctly, the Arduino IDE will
return the following error when trying to upload a code

13. Click the UPLOAD button (the right arrow) and wait for the IDE to
say “Done Uploading” on the bottom

90 Unit 7: Arduino Microcontrollers | CIJE

Principles of Engineering

14. Change the code so that the LED blinks every 1/10 of a second (i.e. – 100 microseconds).
15. Change the code so that the LED is on for twice the length of time it is off.
16. Change the code so that the LED performs 1 one-second blink, followed by 3 half-second

blinks.
Note: To complete this task additional 'digitalWrite' and 'delay' commands must
be added to the code
17. What do the following text font colors represent in the Arduino IDE?

a. Orange: _________________________________________________________
b. Blue: _________________________________________________________
c. Gray: _________________________________________________________
18. Change the code so that the LED blinks on and off so fast you can't see it change.
19. Through trial and error, what is the fastest speed an LED can blink where the human eye
can still perceive it blinking? ____________________________
20. If you try to blink the light faster, what does it appear to be doing? _________________
21. Look up the concept of persistence of vision on the internet. Explain how this concept
relates to the speed of the blinking light in this experiment.
________________________________________________________________________
An LED works by aligning negative and positive charges in close proximity to each
other. The positive charge side is actually a consequence of ‘missing’ electrons, and
consists of ‘holes’. The electrons jump into these ‘holes’, which are at a lower energy
state. The excess energy they no longer need is given off as light.

22. An LED offers no resistance to the flow of electrons. This makes them very efficient, but
susceptible to short circuits and burn out. If we are supplying the LED with 5V, and the
maximum current the LED can handle is 30mA (.030A), what minimum resistance should
we place in line with the LED? (Hint: V = I * R) ________________________
CIJE | Unit 7: Arduino Microcontrollers 91

Principles of Engineering

Lab: Traffic Light

In this section, we will start with a small project. Using the Arduino, a breadboard, and external
LEDs, we are going to build a simple traffic light.

Objectives

➢ To build a working model traffic light
➢ Write your first program!
➢ Learn to expand the functionality of a simpler code

Procedure

1. Wire three different color LEDs to pins 13, 12, and 11,
respectively. Make sure these have a common ground, i.e.
use the Arduino GND pin.

2. Open the 'blink' example in the Arduino IDE and edit it to
control the three LEDs independently.

Note that each pin must be independently setup using the 'pinMode' function in the
'void setup()'.

3. Develop a code that operates the
traffic light automatically in the
standard routine pattern using the
'delay' and 'digitalWrite' functions.

This is a major step! You have written your
first full program.

4. It is often the case that we need to
change the pins that we have a
sensor wired to. Change the LEDs to
pins 4, 5, and 6.

5. Change the code so the traffic light
works as above.

Challenge

6. Add two more LED's to represent the See Appendix for
pedestrian 'walk' and 'don't walk' a soldering
lights. Incorporate them into the
code so they operate as a standard version of this lab
traffic signal would. Don't forget that
the pedestrian 'don't walk' light must
blink before it changes to a steady
'don't walk'.

92 Unit 7: Arduino Microcontrollers | CIJE

Principles of Engineering

Worksheet: Datasheets

Background
Datasheets are used to provide you with vital information needed to understand how a part or
component might work. The datasheet for each component will differ based on what
information is needed for that part. For instance, a breadboard datasheet might tell you what
is the maximum amount of voltage you can use on that board, or at what temperature the
board can be used before it will fail. For a resistor, the datasheet might tell you how much the
resistance will fluctuate with temperature, a vital piece of information if you were designing a
refrigerator. A datasheet for a more complex piece of equipment, such as an Arduino, might
include the dimensions, complete circuit diagram, power rating, voltages at various pins,
maximum and mini voltages it can be used at, etc.

1. List three pieces of information you would expect to find on the datasheet for an LED.

_____________________ _____________________ _____________________
The following two pages contain portions of an LED datasheet for an LED similar to the ones in
your classroom. Use the information on the datasheets to answer the following questions:

2. How much voltage, called “forward voltage”, is needed to illuminate the LEDs? ______
3. Voltage can normally only flow through an LED in one direction. How much voltage

would be needed to overcome that restriction and have “reverse” voltage? __________

4. What is the maximum allowable current for these LEDs? _________
5. If powering the LEDs from a 5V source, what is the minimum resistance required to

ensure the LEDs do not exceed their maximum allowable current (hint: V = I x R)? _____

6. What is the maximum allowable temperature when soldering these LEDs? __________

7. At what temperature does the current flowing through the LEDs suddenly drop off? ___

8. If standing directly in front of the LED, at 0° off of center, what will be the luminous

intensity of the light? ________ At 10°? ________ At 15°? ________

9. Will the LEDs appear brighter or dimmer when used below freezing? ______________

10. What temperate range is recommended for these LEDs? ________________________

11. Should these LEDs be used outdoors? Why? __________________________________

CIJE | Unit 7: Arduino Microcontrollers 93

Principles of Engineering

94 Unit 7: Arduino Microcontrollers | CIJE

Principles of Engineering

CIJE | Unit 7: Arduino Microcontrollers 95

Principles of Engineering

96 Unit 7: Arduino Microcontrollers | CIJE

Unit 8:
Arduino
Coding Tools

Principles of Engineering

Preface

This unit introduces the students to errors in code, how they can be detected and fixed. It also
introduces global variables and provides and shows how they can be used for the Blink
program.

Unit Sections

➢ 1 Debugging- Finding and Correcting Errors in Computer Code
➢ Lab: Debugging
➢ 2 Global Variables a Better Way
➢ Lab: Global Variables

Learning Objectives

After this unit students should be able to:
➢ Describe what a syntax error is
➢ Describe how Arduino shows syntax errors
➢ Describe the difference between structural error and syntax error
➢ Describe how variables are used in programming
➢ Describe the three parts of a variable declaration
➢ Be able to incorporate variables in the Blink program

98 Unit 8: Arduino Coding Tools | CIJE

Principles of Engineering

Section 1: Debugging - Finding and Correcting Errors in
Computer Code

Programmers often comment that a computer is actually the least intelligent thing in the world.
Regardless of whether this is true, it is certainly the most literal thing. A computer will do exactly
what you tell it to do—not what you think you told it to do, but what you actually told it to do.
Given this, learning how to efficiently correct code, called debugging, is a vital skill for any
programmer.
There are two main types of errors, syntactic and structural. A syntactic error means that you
didn't follow the rules of the programming language. For instance, you didn't put a semicolon at
the end of a statement, or you didn't capitalize letters you should have. Structural errors are
where the code compiles and runs but the behavior is incorrect. For instance, you wanted an LED
to blink 20 times and stop and instead it keeps blinking, or you wanted your code to add two
numbers and instead it multiplies them.
Syntactic errors are the easiest to fix and what we will focus on here, and the IDE helps us a lot
in this regard. Let's look at what happens when there is a syntactic error in Arduino. Here is the
Blink code where a semicolon is missing after the pinMode() function in the setup() function,

When an error occurs that prevents the code from compiling, the IDE will throw up error
messages in an orange bar and in orange font in the console. Notice that in the code there is a

CIJE | Unit 8: Arduino Coding Tools 99

Principles of Engineering

yellow highlight indicating where it has found an error. In this case, it has shown us the exact line
where we forgot our semicolon. But beware, this is not foolproof! Often the error will be located
in a previous line, so if you are certain the line indicated is correct, then work your way back up
the code until you find the error.
Let's look at another common error, in capitalization. Here we wrote digitalwrite() instead of
digitalWrite(),

The error message says, "digitalwrite was not declared in the scope". This is a message we will
see often. We will talk more about scope later, but fundamentally, it means that the computer
can't find the thing we told it to use. Here, the computer has no idea what digitalwrite() is. It only
knows what digitalWrite() is. Capitalization matters! Spelling matters! (Except where it doesn't,
such as in comments.)
These are two examples of the more common syntax errors. Sometimes the messages will make
no sense. In those cases, always check spellings, that parentheses and brackets are paired, and
that semicolons are in the right place. The topic of debugging is much broader than this short
section, but let's get back to writing code.

100 Unit 8: Arduino Coding Tools | CIJE


Click to View FlipBook Version