0% found this document useful (0 votes)
9 views18 pages

Arduino Experiment

This document outlines an experiment using the Arduino microcontroller in an ECE 110 lab setting, focusing on its capabilities as a substitute for traditional bench equipment. It covers powering the Arduino, programming it, and using it for various tasks such as voltage measurement, function generation, and circuit control. The document emphasizes the Arduino's versatility for hobbyists and its application in future projects, while also providing guidance on safe usage and programming practices.

Uploaded by

Ajay Carandan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views18 pages

Arduino Experiment

This document outlines an experiment using the Arduino microcontroller in an ECE 110 lab setting, focusing on its capabilities as a substitute for traditional bench equipment. It covers powering the Arduino, programming it, and using it for various tasks such as voltage measurement, function generation, and circuit control. The document emphasizes the Arduino's versatility for hobbyists and its application in future projects, while also providing guidance on safe usage and programming practices.

Uploaded by

Ajay Carandan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Experiment 4: Using the Arduino

Laboratory Outline
We have learned to take measurements and power our circuits using the bench equipment found the in the ECE 110 lab. While
the high accuracy of this equipment is well suited for conducting lab experiments in a university or industry, the size and cost
make these devices impractical for most hobbyists. This week we’ll learn to use a small, inexpensive microcontroller (made
famous under the brand name Arduino) that can serve many of the same purposes as the DMM, power supply, function
generator and, if you’re clever, the oscilloscope. In addition, we’ll see how the Arduino can be used to automatically react to its
measurements while your circuit is operating!

Using the Arduino as Bench Equipment:


As stated above, the Arduino can perform many of the same tasks as your bench equipment. As we progress through the lab,
you’ll learn to use the Arduino in this manner. Once you understand how to power a circuit and take measurements with the
Arduino, you’ll be able to conduct small experiments at home. Although our formal lab experiments will still require your
attendance in lab, you’ll find this capability very useful when working on extra lab modules, your final design project, and any
future projects you might take on outside of ECE 110.

Using the Arduino as a Circuit:


The power of the Arduino is enhanced by its ability to react to measurements. When employed correctly, the Arduino can
replace large parts of a circuit. Since the Arduino is programmable, this means that a person can quickly change its behavior
without rewiring anything! Today we’ll learn the basics of using the Arduino to read a sensor voltage and react to it. It is
important to note that ECE110 teaches a minimal amount of programming. The use of the Arduino this semester in ECE110
should be limited to basic tasks for which you are provided the core code. Looking ahead, the final project will outline goals that
do not depend heavily on your ability to program the Arduino.
Notes:

Getting Started with the Arduino


Before we can begin using the Arduino microcontroller (actually, we use the RedBoard clone from SparkFun Electronics), we
need to learn how to safely power it and program it. Fortunately for us, the microcontroller’s design includes a very good
voltage-regulation circuit that allows it to be powered through several interfaces using a range of voltages.

Powering the Arduino


USB is how you program the RedBoard. The USB is also the most direct and the safest method of powering your RedBoard. You
can safely power your RedBoard by connecting it to a computer (or even a phone charger) via USB. This is the first method we’ll
use to power the RedBoard today. Unfortunately, while the power that can be drawn through the USB is enough to power the
microcontroller, it quickly behaves as a non-ideal DC voltage source when it is used to power other devices such as motors and
sensors. Since the USB can provide only limited power and its cable tethers your device to a computer, the use of battery power
in most applications is essential!

The DC power jack is the “barrel jack” on the RedBoard and can be powered using an external voltage no less than 7 V and no
more than 12 V. The voltage regulator on the RedBoard is designed to handle voltages within this range comfortably and you
can easily power the board by connecting a battery to this jack and there is no chance of accidentally reversing the battery’s
polarity. We will use a 7.2-V rechargeable NiMH battery with a barrel connector. The barrel jack input also has the benefit of
having protection circuits to keep you from destroying your board – this doesn’t mean it’s impossible to kill your board this way,
just more difficult.
Notes:

(a)

(b)

Figure 1: Typical power connections for the RedBoard in ECE110 (a) with exploded view in (b). Images adapted from
those provided by SparkFun Electronics, CC BY-NC-SA 3.0.
Notes:
When powering the RedBoard with the battery through the power jack, the Vin pin will allows us to access the un-regulated
7.2-V source to power motors and other higher-voltage, higher-current devices. The term un-regulated means that the voltage
and current available from the battery are present at the Vin/GND terminals unaltered by the presence of the board.

The Vin pin may also be used “in the other direction” in order to provide a voltage to the board. This pin is connected to the
RedBoard’s voltage regulation circuit like the barrel jack described above – except it does not have the same protection circuits.
While this method allows you to power your board without the need for a barrel connector, it can easily destroy the circuitry if
you accidentally supply voltage in reverse polarity.

Never power the RedBoard by connecting your voltage source to 5V pin or 3.3V pin or you risk burning up the components on
your board and rendering it useless. These ports were not designed for this purpose.

If you’d like to learn about other ways to destroy your board, visit the Rugged Circuits page listed below.

[Link]

Programming the Redboard


 In order to program to RedBoard, we’ll need to make use the Arduino Programming software. On the computers in the
ECE 110 Lab, you should be able find a shortcut on the desktop or by searching for “Arduino” in the start menu.
Alternatively you can install the Arduino software on your own computer so long as you have an internet connection.
The instructions for doing so can be found in your SIK Guide.

 Build the Circuit #1 found in the SIK Guide and program the RedBoard following the instructions in the guide. If the
Sparkfun code is loaded in your Arduino IDE you can simply follow the instructions in your SIK Guide. Alternatively you
can use the example code that comes with the Arduino IDE found using the instructions below. Figure 2 shows the

circuit. The symbol represents a “plug and jack” connection. For us, the jack is a wire that feeds into a pin
(jack) on the Arduino board.
Notes:

Figure 2: Blink circuit.


 Program your RedBoard with the Blink example code.

o Open the Blink example code in the Arduino IDE ( File > Examples > Basics > Blink )

o Select the “Save as…” option under the file menu and save the sketch to your desktop under a name of your
choosing.

 This allows you to make changes to the code.

o Ensure that the correct port is selected under Tools > Serial Port

 (Hint: COM1 is not the correct port)

o Upload the code to the RedBoard

If you run into problems, the SIK Guide has some wonderful debugging help. You should read it.
Notes:
Navigate to the Arduino site – [Link]. Using the help section, indicate purpose of the setup and
loop portions of the code (yes, it was actually explained in the comments but navigate to the Arduino site to see
how useful and informative it is).

Explain what is happening to the voltage at pin 13 on your RedBoard. (Hint: measure with your
oscilloscope.)

What do the two parameters of the digitalWrite function mean? (If you don’t know, you can find the
answer in the SIK Guide or the Arduino website.)
Notes:
Change the parameter being passed to the delay functions to a small value (like 50 rather than
1000). What is the LED doing now? What SI time unit does this number correspond to?

What error message appears if you don’t select the correct serial port before you upload your code?

What happens if your RedBoard is not connected when you attempt to upload?

Arduino as Bench Equipment


The Arduino and clones such as the RedBoard are capable of performing many tasks that are similar to the equipment you can
find on your bench. The fact that the Arduino can be reconfigured for a task very quickly adds to its value as a bench-top device.

Arduino as Power Supply


When you hook up the board to your computer via the USB port, the computer provides power to the board. The board can also
be powered via an external power source (battery or wall-wart within in the recommended range 7-12V). Once the board is
powered, a regulated 5V is supplied to the pin labeled 5V and a regulated 3.3V is supplied to pin labeled 3.3V – clever labeling.
The term regulated means that the voltage is controlled to within a certain tolerance of variation.

 Use a 7.2 volt battery to power your RedBoard.


Notes:
Measure the voltage at the 5V for various resistive loads and fill in the following table. Generate a
plot using MATLAB and attach it the end of your lab.

Resistive Load (𝛀) Reading at 5V pin (V) Comments

Arduino as Function Generator


Open a new sketch in the Arduino programming IDE and type in the following code.
void setup() {
pinMode(9, OUTPUT);
}
void loop() {
analogWrite(9, 64);
}
Notes:
This program will use the LED circuit you built in a different way. Upload the program to the board. This will erase
the current program that is blinking the LED so it should stop blinking. The first parameter of the analog write
function is the pin number it is controlling. To get this program to work you must make a very simple modification to
the circuit. You will know it is working because the LED will go back on.

Draw your modified circuit diagram below.

Again describe the function of each line of code. How does the LED behave now?

Play with the second parameter of the analogWrite function. What happens to the voltage at pin 9
when you increase and decrease the value? (Hint: Use the scope.)
Notes:
What does the analogWrite function really do? (Hint: Look at Circuit #3 in the SIK Guide.)

What happens to the waveform produced when you use a number greater than 255 or less than 0 as
the input to analogWrite?

Compare and contrast the analogWrite function to the operation of the oscillator circuit constructed in
the previous laboratory meeting.
Notes:
Arduino as a DMM
In addition to generating signals, the Arduino can also measure voltages using the analogRead() function. In addition, the
Arduino has a set of functions built into it that allow us to send data back to the computer to be viewed on the serial monitor.
Below is the bare minimum code for reading a voltage and printing it to the serial monitor.

void setup() {
int sensorValue; // initialize an integer variable
pinMode(A0, INPUT); // set pin A0 as input
[Link](9600); // initialize serial port
}
void loop() {
sensorValue = analogRead(A0, 64); // read from pin A0
[Link](sensorValue); // print value to serial monitor
}
The function [Link]() sends the function argument to the serial monitor in your Arduino IDE. Once you have loaded this
code to the RedBoard, open the Serial Monitor to see it in action (the icon that looks like a magnifying glass located at the top
right any open sketch).

 Connect the DC power supply to pin A0 as shown in the wiring diagram below
Notes:
Figure 3: Test-circuit schematic for using the microcontroller as a DMM.

Vary the supplied voltage from 0V to 5V and measure the voltage at pin A0 using the DMM and record
this measured voltage along with the value printed to the Serial Monitor by the RedBoard. Be sure to use the full
range of 0V to 5V.

Supplied Voltage Arduino Value

What does the analogRead function do? What are the range of voltages that it can accurately read?
What range of outputs does this voltage range correspond to?
Notes:
Write down a mathematical expression for converting the numbers returned by analogRead into
voltages.

Using this expression, you can use the RedBoard as a simple digital voltmeter.
Modify your code so that the serial monitor outputs voltage. Write the line of code that does the
computation here.

Since the Arduino can only measure voltages, how could it be used to measure current? Include a
circuit schematic in your explanation.

How do would you measure resistance? If you aren’t sure, move on to the next portion of this
experiment and then come back to this question.
Notes:
If you take time to familiar with the components in your kit, you can even add a LCD screen to your RedBoard and
use it a multimeter without needing to a computer connection.

Arduino as a Circuit
 Build Circuit #2 from your SIK Guide and load the corresponding code onto your RedBoard. Play around with the
potentiometer and verify that the LED changes brightness corresponding to the position of the potentiometer.

What is causing the LED to change brightness? Be specific.

So far in this lab we have learned about resistive sensors. As you saw earlier in this experiment, the Arduino can only read
voltages through the I/O pins. In order to make use of resistive sensors, we must employ a circuit we saw in Experiment 2: the
voltage divider circuit.

 Modify Circuit #2 as to include the flex sensor as shown in the circuit diagram below.
Notes:

Figure 4: Circuit schematic showing modifications to Circuit #2 of the SIK Guide.

Does the LED get as bright as it could with the potentiometer attached? Does it get as dark?

As you should recall, the range of voltages measured across the flex sensor will not reach the full range of 0-5V.

Record the minimum and maximum values read in by the Arduino here (i.e. the value corresponding to
the sensor un-flexed and flexed to 90 degrees).
Notes:
 Initialize a new variable to represent the value we will write to the LED pin using the following line of code.
Insert this line just after sensorValue is initialized:

int ledValue;

 Now replace the line containing analogWrite function in your code with the following lines. Replace MIN with
the minimum value read by the Arduino (use the code from the Arduino as DMM portion of this lab).

ledValue = int((sensorValue - MIN) * 250 / (MAX - MIN));


if (ledValue < 0)
{
ledValue = 0;
}
if (ledValue > 255)
{
ledValue = 255;
}
analogWrite(13, ledValue);

The first of these lines calculates the new output value converts it to an integer (rather than a floating point variable). For this to
work, you must first replace MIN and MAX with values recorded earlier. The IF-statements you inserted ensure that we do not
try to enter invalid values to analogWrite.

Explain in your own words what the code does now.


Notes:

Conclusion
Explain the different ways in which the microprocessor might be used in the laboratory?

What makes the microprocessor more useful than ordinary bench-top test-and-measurement devices?
What makes it less useful?

Arduino is not the end-all be-all but it’s a very powerful tool, especially for hobby projects. Throughout the rest of the semester,
we will examine and design circuits that perform tasks that can also be done using the Arduino. Take time to explore the Arduino
further by playing with the circuits described in SIK Guide. You may find it very useful in future experiments as well as the final
design challenge at the end of the semester.

What You Learned


You should now be able to use the RedBoard as a voltmeter, ammeter, and ohmmeter. You should understand some of the
basics of programming and some of the limitations of the RedBoard device.

Learn More!
At the end of each regular lab procedure, as time permits, you will be provided with materials to continue to improve your
mastery of the materials. The suggested modules for this lab will be provided by the TA. You are to work on these as long as time
permits. The modules will be submitted to your TA when finished and a number of them will count in your final grade.
Notes:

Lab Report Rubric


The following rubric will be provided at the end of each lab procedure. As a final step in preparing your lab report, you will use
this rubric to analyze your own performance. While your analysis is not used in the grading process, extra points may be
awarded after lab 8 based on your ability to properly discern and implement good lab-writing strategies as demonstrated here.

Section Ques. Total Criterion Comments:


points
Experimental Setup Circuit Schematics are drawn neatly, accurately,
and/or and properly labeled. All important decisions
Design Description regarding experimental setup or project design are
clearly explained.
Measurements Tables include units and proper precision. Any new
device introduced should be characterized using
measurements!
Computations Computations performed on raw data are explicitly
described and follow rules for significant figures.

Analysis Graphs have title, labels, units, scale, legend; Lines


for curve-fitting appear in the graph when needed
and parameters like the intercepts and slope are
labeled.
Modeling A mathematical model for the curve-fit graph
allows for more abstract references to the device’s
behavior. The expected behavior is explained in the
context of the graph.
Conclusion Conclusions are drawn from your experimental
results to support the reason(s) for completing the
experiment. Closes the loop on the Introduction.
General Formatting Answers to questions clearly labeled. The overall
appearance of the report is professional.

You might also like